Uploaded image for project: 'Olingo'
  1. Olingo
  2. OLINGO-1145

How to create a valid URI with a date(time) literal using the FilterArgFactory?

    XMLWordPrintableJSON

Details

    • Question
    • Status: Open
    • Major
    • Resolution: Unresolved
    • (Java) V4 4.3.0
    • None
    • odata4-client
    • None

    Description

      Hi,

      We use the Olingo client library to call an OData service (which also uses the Olingo library). We are implementing filtering using the FilterFactory and FilterArgFactory. We want to filter on a property that is of type Edm.Date (and also Edm.DateTimeOffset), for instance for a date that equals 2017-07-04, e.g.

      $filter=date eq 2017-07-04
      

      Note that we do not use the date() function, is this is not implemented in the OData service that we call. That being said, the date() function also needs a FilterArg, so it has the same problem.

      The problem is that we cannot find how to use the FilterArgFactory to create such a valid date literal. If we use the literal() method, the date value is surrounded with quotes, leading the OData service to interpret the value as a String which is inconsistent with our model, so it fails. We need to create a FilterArg with the date literal as a String value, without quotes. The only way to achieve this is to "disguise" it as a property, like the code below. That works, but it is clearly not the way it should be in the end.

      FilterFactory filterFactory = new FilterFactoryImpl();
      Date dateValue = <a valid date>;
      String dateString = EdmDate.getInstance().valueToString(dateValue, null, null, null, null, null);
      return filterFactory.getArgFactory().property(dateString);
      

      Can you show an example how this should be done?

      Attachments

        Activity

          People

            Unassigned Unassigned
            g.graat Geert Graat
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: