Announcement

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

    Iterate AdvancedCriteria on Server Side

    SNAPSHOT_v12.1d_2020-02-21/PowerEdition Deployment (built 2020-02-21)

    For too many reasons to enumerate, but basically the age and complexity of our code set I need to look into an AdvancedCriteria in a fetch on the server side and extract the field names and the criterion values for each field. And I don't see a way of extracting an array of Criterion from the AdvancedCriteria method on the server.

    If I look into values in:

    request.getAdvancedCriteria() or request.getCriteria() I get a data structure (which you're familiar with) of:

    {_constructor=AdvancedCriteria, criteria=[{fieldName=Path_GroupType, operator=notEqual, value=0}, {fieldName=idSTARun, operator=equals, value=8686483}, {fieldName=PK_STA_Rundir, operator=equals, value=3903212} etc etc ]

    I was thinking of using the static Evalutor class, but I don't always know the field names of the AC.

    I was thinking of trying something like:

    Criterion [] cc = (Criterion [])request.getAdvancedCriteria().get("crtieria");

    but that seems problematic.

    Thanks

    #2
    Maybe something like this might work?

    com.google.gson.Gson gsonDecoder = new com.google.gson.Gson();
    List<Criterion> cc = gsonDecoder.fromJson((String) additionalCrits.getCriteriaAsMap().get("criteria"), ArrayList.class);

    Comment


      #3
      That didn't work. But this seems to do the job. What's your opinion on if this will break in the future?

      Map waiverCritMap = new HashMap();
      additionalCrits = request.getAdvancedCriteria();
      List<Map> cc = (List<Map>)additionalCrits.getCriteriaAsMap().get("criteria");
      for (Map c : cc ) {

      Criterion n = com.isomorphic.criteria.Evaluator.parseCriterion(c);

      if ( n.getFieldName() != null && n.getValue() != null ) {
      waiverCritMap.put(n.getFieldName(), n.getValue());
      }

      I end up with a map of the field names of the criteria and the field values.

      Comment


        #4
        Correct traversal would be:
        AdvancedCriteria.asCriterion()
        getOperatorId() - if it's "and"/"or"/"not" you know you can cast to LogicalCriterion and then you have LogicalOperator.getCriteria() returning List of Criterion
        Otherwise you have a Criterion that is not a LogicalOperator and hence has no subcriteria.
        Do this recursively to discover all nested logical structures.

        Keep in mind that the entire AdvancedCriteria can be just a simple (non-logical) Criterion, like someField greaterThan someValue. The top-level operator isn't necessarily a logical operator.

        That's also why we didn't provide an API like AdvancedCriteria.getFieldNames() - could be more than one Criterion on the same field.

        Comment


          #5
          Thanks.

          I got your suggestion to work. As you pointed out an AdvancedCriteria can have multiple logical operators. So the routine I developed is recursive and steps down the the entire structure of the AD crit.

          Comment

          Working...
          X