use of org.folio.rest.jaxrs.model.ResultInfo in project raml-module-builder by folio-org.
the class PostgresClientIT method streamGetWithFacetsAndFilter.
@Test
public void streamGetWithFacetsAndFilter(TestContext context) {
AtomicInteger objectCount = new AtomicInteger();
Async async = context.async();
List<FacetField> facets = new ArrayList<FacetField>();
facets.add(new FacetField("jsonb->>'edition'"));
facets.add(new FacetField("jsonb->>'title'"));
createTableWithPoLines(context);
postgresClient.streamGet(MOCK_POLINES_TABLE, Poline.class, "jsonb", firstEdition(), true, null, facets, QUERY_TIMEOUT, context.asyncAssertSuccess(sr -> {
ResultInfo resultInfo = sr.resultInfo();
context.assertEquals(3, resultInfo.getTotalRecords());
context.assertEquals(2, resultInfo.getFacets().size());
context.assertEquals("edition", resultInfo.getFacets().get(0).getType());
context.assertEquals(1, resultInfo.getFacets().get(0).getFacetValues().size());
context.assertEquals("First edition", resultInfo.getFacets().get(0).getFacetValues().get(0).getValue());
context.assertEquals(3, resultInfo.getFacets().get(0).getFacetValues().get(0).getCount());
context.assertEquals("title", resultInfo.getFacets().get(1).getType());
context.assertEquals(3, resultInfo.getFacets().get(1).getFacetValues().size());
context.assertEquals(1, resultInfo.getFacets().get(1).getFacetValues().get(0).getCount());
context.assertEquals(1, resultInfo.getFacets().get(1).getFacetValues().get(1).getCount());
context.assertEquals(1, resultInfo.getFacets().get(1).getFacetValues().get(2).getCount());
sr.handler(streamHandler -> objectCount.incrementAndGet());
sr.endHandler(x -> {
context.assertEquals(3, objectCount.get());
async.complete();
});
}));
async.awaitSuccess();
}
use of org.folio.rest.jaxrs.model.ResultInfo in project raml-module-builder by folio-org.
the class PostgresClientIT method getDistinctOnWithFacets.
@Test
public void getDistinctOnWithFacets(TestContext context) {
final String tableDefiniton = "id UUID PRIMARY KEY , jsonb JSONB NOT NULL, distinct_test_field TEXT";
createTableWithPoLines(context, MOCK_POLINES_TABLE, tableDefiniton);
List<FacetField> facets = List.of(new FacetField("jsonb->>'edition'"));
String distinctOn = "jsonb->>'order_format'";
// with facets and return count
Async async1 = context.async();
CQLWrapper wrapper = new CQLWrapper();
postgresClient.get(MOCK_POLINES_TABLE, Poline.class, new String[] { "*" }, wrapper, true, false, facets, distinctOn, handler -> {
ResultInfo resultInfo = handler.result().getResultInfo();
context.assertEquals(4, resultInfo.getTotalRecords());
List<Facet> retFacets = resultInfo.getFacets();
context.assertEquals(1, retFacets.size());
async1.complete();
});
async1.awaitSuccess();
}
use of org.folio.rest.jaxrs.model.ResultInfo in project raml-module-builder by folio-org.
the class PostgresClientIT method streamGetWithFacetsZeroHits.
@Test
public void streamGetWithFacetsZeroHits(TestContext context) throws FieldException {
AtomicInteger objectCount = new AtomicInteger();
Async async = context.async();
List<FacetField> facets = new ArrayList<FacetField>();
facets.add(new FacetField("jsonb->>'edition'"));
facets.add(new FacetField("jsonb->>'title'"));
createTableWithPoLines(context);
CQLWrapper wrapper = new CQLWrapper(new CQL2PgJSON("jsonb"), "edition=Millenium edition");
postgresClient.streamGet(MOCK_POLINES_TABLE, Object.class, "jsonb", wrapper, true, null, facets, context.asyncAssertSuccess(sr -> {
ResultInfo resultInfo = sr.resultInfo();
context.assertEquals(0, resultInfo.getTotalRecords());
context.assertEquals(0, resultInfo.getFacets().size());
sr.handler(streamHandler -> objectCount.incrementAndGet());
sr.endHandler(x -> {
context.assertEquals(0, objectCount.get());
async.complete();
});
}));
async.awaitSuccess();
}
use of org.folio.rest.jaxrs.model.ResultInfo in project raml-module-builder by folio-org.
the class PostgresClientIT method normalGetWithFacetsAndFilter.
@Test
public void normalGetWithFacetsAndFilter(TestContext context) {
List<FacetField> facets = new ArrayList<FacetField>();
facets.add(new FacetField("jsonb->>'edition'"));
facets.add(new FacetField("jsonb->>'title'"));
createTableWithPoLines(context);
postgresClient.get(MOCK_POLINES_TABLE, Poline.class, new String[] { "jsonb" }, firstEdition(), true, true, facets, context.asyncAssertSuccess(sr -> {
ResultInfo resultInfo = sr.getResultInfo();
context.assertEquals(3, resultInfo.getTotalRecords());
context.assertEquals(2, resultInfo.getFacets().size());
context.assertEquals("edition", resultInfo.getFacets().get(0).getType());
context.assertEquals(1, resultInfo.getFacets().get(0).getFacetValues().size());
context.assertEquals("First edition", resultInfo.getFacets().get(0).getFacetValues().get(0).getValue());
context.assertEquals(3, resultInfo.getFacets().get(0).getFacetValues().get(0).getCount());
context.assertEquals("title", resultInfo.getFacets().get(1).getType());
context.assertEquals(3, resultInfo.getFacets().get(1).getFacetValues().size());
context.assertEquals(1, resultInfo.getFacets().get(1).getFacetValues().get(0).getCount());
context.assertEquals(1, resultInfo.getFacets().get(1).getFacetValues().get(1).getCount());
context.assertEquals(1, resultInfo.getFacets().get(1).getFacetValues().get(2).getCount());
}));
}
use of org.folio.rest.jaxrs.model.ResultInfo in project raml-module-builder by folio-org.
the class PostgresClient method doStreamGetCount.
/**
* private for now, might be public later (and renamed)
* @param <T>
* @param connection
* @param table
* @param clazz
* @param fieldName
* @param wrapper
* @param returnIdField
* @param distinctOn
* @param facets
* @param replyHandler
*/
// Method has >7 parameters
@SuppressWarnings({ "squid:S00107" })
<T> void doStreamGetCount(PgConnection connection, boolean startTransaction, String table, Class<T> clazz, String fieldName, CQLWrapper wrapper, boolean returnIdField, String distinctOn, List<FacetField> facets, Handler<AsyncResult<PostgresClientStreamResult<T>>> replyHandler) {
try {
QueryHelper queryHelper = buildQueryHelper(table, fieldName, wrapper, returnIdField, facets, distinctOn);
Future<Integer> countQuery;
if (wrapper == null || wrapper.hasReturnCount()) {
countQuery = connection.query(queryHelper.countQuery).execute().map(result -> result.iterator().next().getInteger(0));
} else {
countQuery = Future.succeededFuture(null);
}
countQuery.onSuccess(count -> {
ResultInfo resultInfo = new ResultInfo();
resultInfo.setTotalRecords(count);
doStreamGetQuery(connection, startTransaction, queryHelper, resultInfo, clazz, replyHandler);
}).onFailure(e -> {
log.error(e.getMessage(), e);
replyHandler.handle(Future.failedFuture(e));
});
} catch (Exception e) {
log.error(e.getMessage(), e);
replyHandler.handle(Future.failedFuture(e));
}
}
Aggregations