Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    #16
    Hi Isomorphic,

    thanks for the hint on this correct way to get the dsName. I adjusted my code accordingly.

    Also again thanks for implementing this feature - as it turns out this is also useful to add default values that are not present in the CSV file to the data returned to the client.
    Like you already write:
    There are scenarios when mentioned earlier pre- and post-processing approach is not enough. For example if uploaded data needs to be transformed in a certain way before initial validation.
    For anyone finding this thread via search:
    • My usecase is that I have required fields that are not necessarily included in the CSV data.
    • Normally, an user would then have to edit every row and enter/select a value. Very time consuming for CSVs with many rows.
    • Using myBatchUploader.setUploadFormFields() it is possible to have a FormItem on top, select a value there, which then is sent to the server as well. On the server one can add this as default value to the data that later is returned to the client. This way an requiredField-error that would have to be removed manually in every row can be mitigated by including the selected value as default value.
    • (If you are using this lookup feature you'll most likely also use a SelectItem or ComboBoxItem as editor in the upload grid - in this case you need to include another HiddenItem in setUploadFormFields() for the displayValue in the grid data. Store the displayValue in the HiddenItem with an onChange Handler in the SelectItem and set the data for both fields during server processing.)
    Hope this helps.

    Best regards
    Blama

    Comment


      #17
      Hi Isomorphic,

      is this approach still correct (current 6.1p)? After some time (long ago), this changed and DSResponse response = batchUpload.parseUploadData(dsRequest) does directly convert to Boolean.
      I have the feeling that the only way for me to get the original values is, us to use the incoming dsRequest. But this is against the recommendation and I think I don't even have documented get*-APIs here, so that this is not possible at all. From the changes to my BatchUploadDMI.java-DMI class, the change must have happened before 2018-02-21. Not sure ho much before, though.

      This is my conversion code, which never reaches the String->Boolean switch:
      Code:
          private Boolean toBoolean(Object o) {
              if (o == null)
                  return null;
              else if (o instanceof Boolean)
                  return (Boolean) o;
      [B]// Seems not to be hit anymore, as values are already transmitted as Boolean[/B]
              else
                  switch (o.toString().toLowerCase()) {
                  case "x":
                  case "true":
                  case "ja":
                  case "yes":
                  case "y":
                      return true;
                  default:
                      return false;
                  }
          }
      This is the recommendation:
      Originally posted by Isomorphic View Post
      We've made some changes to address your use case. There is a possibility now to manipulate upload data before it is validated.

      Configure the builtin batchUpload.ds.xml DataSource to use custom DMI, which should parse uploaded data using new BatchUpload.parseUploadData(dsRequest) API, perform data manipulations and then validate data using another new BatchUpload.validateUploadData(dsResponse) API. Your DMI may look like this:
      Code:
      public DSResponse batchUpload(DSRequest dsRequest) throws Exception {
      BatchUpload batchUpload = new BatchUpload();
      
      // parse data and get the result Map
      [B]DSResponse response = batchUpload.parseUploadData(dsRequest); // Boolean fields contain boolean values after this line - not possible to access the old, CSV-supplied value[/B]
      Map respData = response.getDataMap();
      
      // do not proceed to validation if parsing failed
      if (respData.containsKey("errorMessage")) return response;
      
      // get upload data
      List<Map> uploadData = (List<Map>) respData.get("gridRows");
      
      // perform data manipulations
      for (Map row: uploadData) {
      if (row.containsKey("inStock")) {
      row.put("inStock", toBoolean(row.get("inStock")));
      }
      }
      
      // validate data and return
      return batchUpload.validateUploadData(response);
      }
      Best regards
      Blama

      Comment


        #18
        We added and documented some heuristics that will "do the right thing" for common boolean formats. We don't really think there are cases where you'd need to override this, but if you did, you could access the dsRequest before calling parseUploadData.

        Comment


          #19
          Hi Isomorphic,

          the reason I noticed this is that you interpret "Nein" (German "No") as true. Before I could control this.
          How would I access the dsRequest before? There is no documented API that gives me access to the CSV Upload data in the incoming DSRequest. I can only see it *after* parseUploadData(), which will use some internal APIs I assume.

          Best regards
          Blama

          Comment


            #20
            Check out new BatchUploader.autoInterpretBooleans flag, which is true by default, but setting it to false would cause BatchUpload.parseUploadData() to skip interpreting values for boolean fields, so you are able to control them manually.

            This will be available for download in nightly builds since June 6 (today).

            Comment


              #21
              Hi Isomorphic,

              thank you, this seems to be working again with current 6.1p.

              Best regards
              Blama

              Comment

              Working...
              X