Skip to content
David Moebius edited this page Apr 12, 2014 · 7 revisions

The StringQueryBuilder is made to help you to build some string based queries. (All examples will be done with a query searching for Users. A search Query for Groups will be equivalent.)

A Query to be used with the OSIAM Server has be to UTF-8 encoded and also has to follow some rules. The StringQueryBuilder helps you to follow these rules and also will encode the given query strings.

The StringQueryBuilder follows the builder pattern used on many places at the connector and the scim schema, except that he will return a String after calling the build() method.

 String myQuery = new StringQueryBuilder()
                  // ...
                 .build();

With the StringQueryBuilder you are able to set all possible parameters of an query:

String myQuery = new StringQueryBuilder()
                  .setFilter("userName sw \"ma\"")
                  .setAttributes("userName, nickName, emails, address")
                  .setCount(50)
                  .setSortBy("userName")
                  .setSortOrder(SortOrder.ASCENDING)
                  .setStartIndex(2)
                  .build();

The result of this query will be:

 &filter=userName+sw+%22ma%22&attributes=userName%2C+nickName%2C+emails%2C+address&sortBy=userName&sortOrder=ascending&count=50&startIndex=2

This String now can be put into the search method of the connector:

osiamConnector.searchUsers(myQuery, <accessToken>);

##filter

The filter will be the main part of an query. It can be written in an equal way like an sql query, except for some point:

  • The filter options are not equal with an sql query:

The following filter options are supported:

  • eq = equals
  • co = contains
  • sw = starts with
  • pr = present
  • gt = greater than
  • ge = greater equals
  • lt = less than
  • le = less equals

Not all filter options are supported with all fields. For example emails.type can't be combined with le since it makes no sense.

  • all filter parameters have to be surrounded by ". Also boolean parameters or numbers

Some examples are:

userName eq "marissa"
emails.primary eq "true"
extension.age ge "18"
  • negation

To negate an expression you can use the NOT operator

example:

meta.created gt "2010-01-22T00:00:00.000" and NOT (userName eq "Marissa" or userName eq "Miller")

An easy way to transform an DateTime into an scim conform string is the following method:

String date = QueryHelper.getScimConformFormatedDateTime(new DateTime());
Clone this wiki locally