use of common.advanced.PersonInfo 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();
}
use of common.advanced.PersonInfo in project tesb-rt-se by Talend.
the class PersonInfoStorage method getTypedQueryTuple.
public List<PersonInfo> getTypedQueryTuple(SearchContext context, String expression) {
// Get search condition encapsulating the query expression
SearchCondition<Person> filter = getSearchCondition(context, expression);
// Initialise JPA2 visitor which can convert the captured search expression
// into JPA2 TypedQuery
JPACriteriaQueryVisitor<Person, Tuple> jpa = new JPACriteriaQueryVisitor<Person, Tuple>(em, Person.class, Tuple.class);
// Convert
filter.accept(jpa);
// Shape the response data with selections and Tuple
List<SingularAttribute<Person, ?>> selections = new ArrayList<SingularAttribute<Person, ?>>();
selections.add(Person_.id);
jpa.selectTuple(selections);
// Get CriteriaQuery and create TypedQuery
CriteriaQuery<Tuple> cquery = jpa.getQuery();
TypedQuery<Tuple> typedQuery = em.createQuery(cquery);
// Run the query
List<Tuple> tuples = typedQuery.getResultList();
// Return the results
List<PersonInfo> infos = new ArrayList<PersonInfo>(tuples.size());
for (Tuple tuple : tuples) {
infos.add(new PersonInfo(tuple.get(Person_.id.getName(), Long.class)));
}
return infos;
}
Aggregations