Search in sources :

Example 1 with SearchConditionBuilder

use of org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder in project tesb-rt-se by Talend.

the class RESTClient method useSearchService.

/**
 * SearchService is a service which shares the information about Persons with the PersonService.
 * It lets users search for individual people using simple or complex search expressions.
 * The interaction with this service also verifies that the JAX-RS server is capable of supporting multiple
 * root resource classes
 */
private void useSearchService() throws Exception {
    System.out.println("Searching...");
    WebClient wc = WebClient.create("http://localhost:" + port + "/services/personservice/search");
    WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
    wc.accept(MediaType.APPLICATION_XML);
    // Moves to "/services/personservice/search"
    wc.path("person");
    SearchConditionBuilder builder = SearchConditionBuilder.instance();
    System.out.println("Find people with the name Fred or Lorraine:");
    String query = builder.is("name").equalTo("Fred").or().is("name").equalTo("Lorraine").query();
    findPersons(wc, query);
    System.out.println("Find all people who are no more than 30 years old");
    query = builder.is("age").lessOrEqualTo(30).query();
    findPersons(wc, query);
    System.out.println("Find all people who are older than 28 and whose father name is John");
    query = builder.is("age").greaterThan(28).and("fatherName").equalTo("John").query();
    findPersons(wc, query);
    System.out.println("Find all people who have children with name Fred");
    query = builder.is("childName").equalTo("Fred").query();
    findPersons(wc, query);
    // Moves to "/services/personservice/personinfo"
    wc.reset().accept(MediaType.APPLICATION_XML);
    wc.path("personinfo");
    System.out.println("Find all people younger than 40 using JPA2 Tuples");
    query = builder.is("age").lessThan(40).query();
    // Use URI path component to capture the query expression
    wc.path(query);
    Collection<? extends PersonInfo> personInfos = wc.getCollection(PersonInfo.class);
    for (PersonInfo pi : personInfos) {
        System.out.println("ID : " + pi.getId());
    }
    wc.close();
}
Also used : PersonInfo(common.advanced.PersonInfo) WebClient(org.apache.cxf.jaxrs.client.WebClient) SearchConditionBuilder(org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder)

Example 2 with SearchConditionBuilder

use of org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder in project cxf by apache.

the class SearchContextImpl method convertPlainQueriesToFiqlExp.

private String convertPlainQueriesToFiqlExp(MultivaluedMap<String, String> params) {
    SearchConditionBuilder builder = SearchConditionBuilder.instance();
    List<CompleteCondition> list = new ArrayList<>(params.size());
    for (Map.Entry<String, List<String>> entry : params.entrySet()) {
        list.add(getOrCondition(builder, entry));
    }
    return builder.and(list).query();
}
Also used : ArrayList(java.util.ArrayList) CompleteCondition(org.apache.cxf.jaxrs.ext.search.client.CompleteCondition) ArrayList(java.util.ArrayList) List(java.util.List) SearchConditionBuilder(org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder) LinkedHashMap(java.util.LinkedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Map(java.util.Map)

Aggregations

SearchConditionBuilder (org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder)2 PersonInfo (common.advanced.PersonInfo)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 CompleteCondition (org.apache.cxf.jaxrs.ext.search.client.CompleteCondition)1