Skip to content
tkrille edited this page Aug 22, 2013 · 6 revisions

If you want to search for Users or Groups you can do this by a string or by a Query Object.

The Query.Builder will help you to build the needed query to get any search result you need. The Query object also gives you the possibility to move to the next or the prevision page.

Chapters:

Creating a Query Object

A Query Object can be created by

Query query = new Query.Builder(User.class).....build();

or

Query query = new Query.Builder(Group.class).....build();

With query.toString() is it possible to get a complete query with all given Parameters to write it, for example, in log statements.

If you have more Users or Groups than one page will hold (standard 100) you can get with

Query newQuery = query.nextPage();

a new query which will gives you the results of the next page.

In the same way you can get the previous page with

Query newQuery = query.previousPage();

If you try to get the page with the "number" -1 you will get an IllegalStateException.

Query.Builder

The Query.Builder gives you a easy possibility to build any easy or complex Querys you need.

(All Examples will be done with a User Query. A Group query is equivalent)

To get a Query.Builder please call

Query.Builder queryBuilder = new Query.Builder(User.class);

creating the filter (where) statement

To build a query please call the methods of the Query.Builder starting with filter in the way you would build a query.

Query.Builder queryBuilder = new Query.Builder(User.class);
queryBuilder.filter("userName").equalTo("marissa")
            .and("emails.value").equalTo("marissa@example.de")
            .or("emails.value").equalTo("marissa@example.de");

(braches)

If you need to put some statements into some braces you can do this with a subQueryBuilder

Query.Builder queryBuilder = new Query.Builder(User.class);
Query.Builder innerQueryBuilder = new Query.Builder(User.class);
     innerQueryBuilder.filter("userName").equalTo("marissa")
                     .or("userName").equalTo("bjensen");

queryBuilder.filter("meta.created").greaterEquals("2013-05-23T13:12:45.672").and(innerQueryBuilder);

The result will be

meta.created ge "2013-05-23T13:12:45.672" and (userName eq "marissa" and userName eq "bjensen")

sortBy

OSIAM gives you the opportunity to sort your result by one field. To sort by one field call

queryBuilder.sortBy("userName");

sortOrder

You can tell OSIAM to sort your result ascending or descending by calling

queryBuilder.withSortOrder(SortOrder.ASCENDING);

or

ueryBuilder.withSortOrder(SortOrder.DESCENDING);

results per page

with

queryBuilder.countPerPage(20);

you can define how many Users/Groups you want to get for the actual request.

start index

with

queryBuilder.startIndex(10);

you can define the 1-based index of the first search result.

NOTE: At the time of writing the osiam server uses a 0-based index for paging and so does the connector for java.

Clone this wiki locally