Uploaded image for project: 'Hippo Site Toolkit 2'
  1. Hippo Site Toolkit 2
  2. HSTTWO-3617

Filter.addGreaterThan(prop, number) throws exception

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 3.2.0
    • Fix Version/s: 4.1.0
    • Component/s: None
    • Similar issues:

      Description

      Found during training:

      In HST query execution code, if you do like the following:

      Filter filter = hstQuery.createFilter();
      filter.addGreaterThan("myhippoproject:availability", 0); // in order to query only available products
      hstQuery.setFilter(filter);
      HstQueryResult result = hstQuery.execut();
      

      Then, it throws an exception because it cannot make a query statement from the number argument, "0".
      If I change it to (long) 0, it works.

      I see the following in FilterImpl.java:

          public String getStringValue(Object value) throws FilterException{
              if(value instanceof String || value instanceof Boolean) {
                  return "'" + value.toString() + "'";
              } else if(value instanceof Long || value instanceof Double) {
                  return value.toString();
              } else if(value instanceof Calendar){
                  return DateTools.createXPathConstraint(session, (Calendar)value);
              } else if(value instanceof Date){
                  Calendar cal = new GregorianCalendar();
                  cal.setTime((Date)value);
                  return DateTools.createXPathConstraint(session, cal);
              }
              throw new FilterException("Unsupported Object type '"+value.getClass().getName()+"' to query on.");
          }
      

      I guess it's better to use value instanceof Number instead. Then you can allow any number in making xpath query for developer's convenience.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              wko Woonsan Ko
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: