Announcement

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

    RequestTransformer corrupts combined AdvancedCriteria

    I'm using a RequestTransformer to add HTTP params to my DSRequests for a grid, which works fine unless the criteria of the request is the result of combining two AdvancedCriteria objects. In this case, the RequestTransformer discards the "_constructor" marker of one of the original AdvancedCriteria objects - which results in a garbage criteria when combined again. I've posted a test case below that reproduces the issue. The first request looks fine - but the 2nd (and later ) request(s) have a garbage criteria.

    Code:
    VLayout layout = new VLayout();
                                    layout.setWidth("100%");
     
                                    final Criteria crit1 = new AdvancedCriteria(OperatorId.AND, new Criterion[] { new Criterion("field1", OperatorId.EQUALS, "value1"), new Criterion("field2", OperatorId.EQUALS, "value2") });
                                    Criteria crit2 = new AdvancedCriteria(OperatorId.AND, new Criterion[] { new Criterion("field3", OperatorId.EQUALS, "value3"), new Criterion("field4", OperatorId.EQUALS, "value4") });
                                    Criteria crit3 = new AdvancedCriteria(OperatorId.AND, new Criterion[] { new Criterion("field5", OperatorId.EQUALS, "value5"),
                                                                    new Criterion("field6", OperatorId.IN_SET, new String[] { "value4", "value8", "value9" }) });
                                    final DataSource ds = DataSource.get("loadData");
                                    final DynamicForm form = new DynamicForm();
                                    SpinnerItem spinner1 = new SpinnerItem("fieldN");
                                    SpinnerItem spinner2 = new SpinnerItem("fieldM");
                                    SelectItem si = new SelectItem("fieldZ");
                                    si.setValueMap("v1", "v2", "v3", "v4", "v5");
                                    si.setMultiple(true);
                                    form.setFields(spinner1, spinner2, si);
                                    spinner1.setValue(0);
                                    spinner2.setValue(0);
                                    final Label label1 = new Label();
                                    label1.setContents("Adjust form to combine criteria...");
                                    final ListGrid test = new ListGrid();
                                    test.setDataSource(DataSource.get("loadData", new RequestTransformer() {
     
                                                    @Override
                                                    protected Object transformRequest(DSRequest dsRequest) {
                                                                    // TODO Auto-generated method stub
                                                                    Map params = new HashMap();
                                                                    params.put("test", "test_param");
                                                                    dsRequest.setParams(params);
                                                                    return dsRequest.getCriteria().getJsObj();
                                                    }
                                    }, null));
     
                                    form.addItemChangedHandler(new ItemChangedHandler() {
     
                                                    @Override
                                                    public void onItemChanged(ItemChangedEvent event) {
                                                                    AdvancedCriteria tmp = new AdvancedCriteria(OperatorId.AND, new Criterion[] { crit1.asAdvancedCriteria(), form.getValuesAsAdvancedCriteria() });
                                                                    label1.setContents(JSON.encode(tmp.getJsObj()));
                                                                    test.fetchData(tmp);
                                                    }
                                    });
     
                                    layout.setMembers(form, test, label1);
                                    layout.draw();
    I've tried replacing the:
    return dsRequest.getCriteria().getJsObj();
    line with:
    return getDefaultTransformRequest(dsRequest);
    - the result is the same.

    I'm using the 09/15 nightly build: SmartClient Version: SNAPSHOT_v9.1d_2013-09-15/PowerEdition Deployment (built 2013-09-15) - behavior seems to be browser independent, though I've confirmed with FF17 and Chrome.

    thanks,
    dan

    #2
    This is assigned to a developer for investigation. We'll let you know as soon as we have more information.

    Regards
    Isomorphic Software

    Comment


      #3
      We need to confirm some things. Could you send us two examples of these criterias that you are obtaining?. One related to the first request, which seems to be correct, and one or two criterias with this issue.

      Comment


        #4
        Using the test case above - the first rpc request gives:

        Code:
            data:{
                operator:"and", 
                criteria:[
                    {
                        operator:"and", 
                        criteria:[
                            {
                                fieldName:"field1", 
                                operator:"equals", 
                                value:"value1"
                            }, 
                            {
                                fieldName:"field2", 
                                operator:"equals", 
                                value:"value2"
                            }
                        ]
                    }, 
                    {
                        operator:"and", 
                        criteria:[
                            {
                                fieldName:"fieldN", 
                                operator:"iContains", 
                                value:1
                            }, 
                            {
                                fieldName:"fieldM", 
                                operator:"iContains", 
                                value:0
                            }
                        ]
                    }
                ]
            },
        and the 2nd request gives:
        Code:
            data:{
                operator:"and", 
                criteria:[
                    {
                        fieldName:"operator", 
                        operator:"iContains", 
                        value:"and"
                    }, 
                    {
                        operator:"or", 
                        criteria:[
                            {
                                fieldName:"criteria", 
                                operator:"iContains", 
                                value:{
                                    fieldName:"field1", 
                                    operator:"equals", 
                                    value:"value1"
                                }
                            }, 
                            {
                                fieldName:"criteria", 
                                operator:"iContains", 
                                value:{
                                    fieldName:"field2", 
                                    operator:"equals", 
                                    value:"value2"
                                }
                            }
                        ]
                    }, 
                    {
                        fieldName:"fieldN", 
                        operator:"iContains", 
                        value:2
                    }, 
                    {
                        fieldName:"fieldM", 
                        operator:"iContains", 
                        value:0
                    }
                ]
            },

        Comment


          #5
          One thing that is incorrect in your usage is this:

          Code:
          AdvancedCriteria tmp = new AdvancedCriteria(
              OperatorId.AND, 
              new Criterion[] { 
                  crit1.asAdvancedCriteria(),
                  form.getValuesAsAdvancedCriteria() 
              }
          );
          The "crit1" param here is already an AdvancedCriteria. You should not call "asAdvancedCriteria()" on it. You need to modify the declaration so it is available as such:

          Code:
              final Criteria crit1 = new AdvancedCriteria(...);
          should be

          Code:
              final AdvancedCriteria crit1 = new AdvancedCriteria(...);
          and then you can pass crit1 into the new A-C constructor without calling 'asAdvancedCriteria()'

          Code:
          AdvancedCriteria tmp = new AdvancedCriteria(
              OperatorId.AND, 
              new Criterion[] { 
                  crit1,
                  form.getValuesAsAdvancedCriteria() 
              }
          );
          Fixing this bug will resolve some problems with your serialization and may resolve this issue for you entirely.

          Having said that we have not been able to reproduce exactly the problem you describe where the "_constructor" is getting mysteriously stripped off in some cases.
          If changing the above doesn't totally fix your usage, please let us know. The best way to proceed would be to show us a new, complete entry point class which references a DataSource we have (either include the DataSource in the entry point class, or make use of "supplyItem" form the built-in ds sample or similar), so we can run your code, unaltered, on our end.

          Regards
          Isomorphic Software

          Comment

          Working...
          X