use of org.folio.rest.persist.cql.CQLWrapper in project raml-module-builder by folio-org.
the class CQLWrapperTest method invalidCQLvalidation.
@Test
public void invalidCQLvalidation() throws FieldException {
CQLWrapper wrapper = new CQLWrapper().setField(new CQL2PgJSON("field")).setQuery("or name=miller");
try {
wrapper.toString();
fail("exception expected");
} catch (CQLQueryValidationException e) {
assertThat(e.getMessage(), allOf(containsString("ParseException"), containsString("unexpected relation")));
}
}
use of org.folio.rest.persist.cql.CQLWrapper in project raml-module-builder by folio-org.
the class CQLWrapperTest method sortBy.
@Test
public void sortBy() throws FieldException {
CQL2PgJSON cql2pgJson = new CQL2PgJSON("field");
CQLWrapper wrapper = new CQLWrapper().setField(cql2pgJson).setQuery("cql.allRecords=1 sortBy name");
assertThat(wrapper.toString(), stringContainsInOrder(" WHERE true ORDER BY ", "name"));
}
use of org.folio.rest.persist.cql.CQLWrapper in project raml-module-builder by folio-org.
the class FacetManager method main.
public static void main(String[] args) throws Exception {
FacetManager fm = new FacetManager("myuniversity_new1_mod_users.users");
List<FacetField> facets = new ArrayList<>();
facets.add(new FacetField("jsonb->>'lastUpdateDate'", 5));
facets.add(new FacetField("jsonb->'personal'->>'phone'", 5));
facets.add(new FacetField("jsonb->>'username'", 5));
fm.setSupportFacets(facets);
fm.setWhere(new CQLWrapper(new CQL2PgJSON("jsonb"), "username=jha* OR username=szeev*").toString());
fm.setMainQuery("SELECT jsonb FROM myuniversity_new1_mod_users.users where jsonb->>'username' like 'jha%' OR jsonb->>'username' like 'szeev%'");
System.out.println(fm.generateFacetQuery());
}
use of org.folio.rest.persist.cql.CQLWrapper in project mod-inventory-storage by folio-org.
the class LocationUnitAPI method getLocationUnitsCampuses.
@Override
public void getLocationUnitsCampuses(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
String tenantId = getTenant(okapiHeaders);
CQLWrapper cql;
try {
cql = getCQL(query, limit, offset, CAMPUS_TABLE);
} catch (Exception e) {
String message = logAndSaveError(e);
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesResponse.withPlainInternalServerError(message)));
return;
}
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(CAMPUS_TABLE, Loccamp.class, new String[] { "*" }, cql, true, true, reply -> {
if (reply.failed()) {
String message = logAndSaveError(reply.cause());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesResponse.withPlainBadRequest(message)));
} else {
Loccamps camps = new Loccamps();
List<Loccamp> items = (List<Loccamp>) reply.result().getResults();
camps.setLoccamps(items);
camps.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(Future.succeededFuture(LocationUnitsResource.GetLocationUnitsCampusesResponse.withJsonOK(camps)));
}
});
}
use of org.folio.rest.persist.cql.CQLWrapper in project mod-inventory-storage by folio-org.
the class PlatformAPI method getPlatforms.
@Validate
@Override
public void getPlatforms(String query, int offset, int limit, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
/**
* http://host:port/platforms
*/
vertxContext.runOnContext(v -> {
try {
String tenantId = TenantTool.tenantId(okapiHeaders);
CQLWrapper cql = getCQL(query, limit, offset);
PostgresClient.getInstance(vertxContext.owner(), tenantId).get(PLATFORM_TABLE, Platform.class, new String[] { "*" }, cql, true, true, reply -> {
try {
if (reply.succeeded()) {
Platforms instanceTypes = new Platforms();
@SuppressWarnings("unchecked") List<Platform> instanceType = (List<Platform>) reply.result().getResults();
instanceTypes.setPlatforms(instanceType);
instanceTypes.setTotalRecords(reply.result().getResultInfo().getTotalRecords());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PlatformsResource.GetPlatformsResponse.withJsonOK(instanceTypes)));
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PlatformsResource.GetPlatformsResponse.withPlainBadRequest(reply.cause().getMessage())));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PlatformsResource.GetPlatformsResponse.withPlainInternalServerError(messages.getMessage(lang, MessageConsts.InternalServerError))));
}
});
} catch (Exception e) {
log.error(e.getMessage(), e);
String message = messages.getMessage(lang, MessageConsts.InternalServerError);
if (e.getCause() instanceof CQLParseException) {
message = " CQL parse error " + e.getLocalizedMessage();
}
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PlatformsResource.GetPlatformsResponse.withPlainInternalServerError(message)));
}
});
}
Aggregations