use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.
the class SampleNsiliClient method submitQuery.
public DAG[] submitQuery() throws Exception {
if (catalogMgr != null) {
LOGGER.info("Submitting Query To Server...");
DAGListHolder dagListHolder = new DAGListHolder();
SortAttribute[] sortAttributes = getSortableAttributes();
String[] resultAttributes = getResultAttributes();
SubmitQueryRequest submitQueryRequest = catalogMgr.submit_query(QUERY, resultAttributes, sortAttributes, new NameValue[0]);
submitQueryRequest.set_user_info("AllianceQuerySubmit");
submitQueryRequest.set_number_of_hits(200);
submitQueryRequest.complete_DAG_results(dagListHolder);
LOGGER.info("Server Responded with {} result(s).", dagListHolder.value.length);
return dagListHolder.value;
} else {
LOGGER.info("CatalogMgr is not initialized, unable to submit queries");
return null;
}
}
use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.
the class NsiliSource method submitQuery.
/**
* Submits and completes a BQS Query to the STANAG 4559 server and returns the response.
*
* @param queryRequest - the query request generated from the search
* @param query - a BQS query
* @param resultAttributes - a list of desired result attributes
* @param sortAttributes - a list of attributes to sort by
* @param properties - a list of properties for the query
* @return - the server's response
*/
private SourceResponse submitQuery(QueryRequest queryRequest, org.codice.alliance.nsili.common.GIAS.Query query, String[] resultAttributes, SortAttribute[] sortAttributes, NameValue[] properties) {
DAGListHolder dagListHolder = new DAGListHolder();
SourceResponseImpl sourceResponse = null;
long numHits = 0;
try {
synchronized (queryLockObj) {
LOGGER.debug("{} : Submit query: {}", sourceId, query.bqs_query);
LOGGER.debug("{} : Requesting result attributes: {}", sourceId, resultAttributes);
LOGGER.debug("{} : Sort Attributes: {}", sourceId, sortAttributes);
LOGGER.debug("{} : Properties: {}", sourceId, properties);
HitCountRequest hitCountRequest = catalogMgr.hit_count(query, properties);
IntHolder hitHolder = new IntHolder();
hitCountRequest.complete(hitHolder);
numHits = hitHolder.value;
SubmitQueryRequest submitQueryRequest;
if (hitHolder.value > 1) {
submitQueryRequest = catalogMgr.submit_query(query, resultAttributes, sortAttributes, properties);
} else {
submitQueryRequest = catalogMgr.submit_query(query, resultAttributes, new SortAttribute[0], new NameValue[0]);
}
submitQueryRequest.set_user_info(ddfOrgName);
submitQueryRequest.set_number_of_hits(maxHitCount);
submitQueryRequest.complete_DAG_results(dagListHolder);
}
} catch (ProcessingFault | SystemFault | InvalidInputParameter e) {
LOGGER.debug("{} : Unable to query source. {}", sourceId, NsilCorbaExceptionUtil.getExceptionDetails(e), e);
}
if (dagListHolder.value != null) {
List<Result> results = new ArrayList<>();
String id = getId();
List<Future> futures = new ArrayList<>(dagListHolder.value.length);
for (DAG dag : dagListHolder.value) {
Callable<Result> convertRunner = () -> {
DAGConverter dagConverter = new DAGConverter(resourceReader);
dagConverter.setNsiliMetacardType(nsiliMetacardType);
Metacard card = dagConverter.convertDAG(dag, swapCoordinates, id);
if (card != null) {
if (LOGGER.isTraceEnabled()) {
DAGConverter.logMetacard(card, getId());
}
return new ResultImpl(card);
} else {
LOGGER.debug("{} : Unable to convert DAG to metacard, returned card is null", getId());
}
return null;
};
futures.add(completionService.submit(convertRunner));
}
Future<Result> completedFuture;
while (!futures.isEmpty()) {
try {
completedFuture = completionService.take();
futures.remove(completedFuture);
results.add(completedFuture.get());
} catch (ExecutionException e) {
LOGGER.debug("Unable to create result.", e);
} catch (InterruptedException ignore) {
// ignore
}
}
sourceResponse = new SourceResponseImpl(queryRequest, results, numHits);
} else {
LOGGER.debug("{} : Source returned empty DAG list", getId());
}
return sourceResponse;
}
use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.
the class NsiliSourceTest method testQuerySupportedAscendingSorting.
@Test
public void testQuerySupportedAscendingSorting() throws Exception {
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(GMTI));
SortBy sortBy = new SortByImpl(Metacard.MODIFIED, SortOrder.ASCENDING);
propertyIsLikeQuery.setSortBy(sortBy);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
ArgumentCaptor<SortAttribute[]> argumentCaptor = ArgumentCaptor.forClass(SortAttribute[].class);
verify(catalogMgr).submit_query(any(Query.class), any(String[].class), argumentCaptor.capture(), any(NameValue[].class));
String sortAttr = NsiliConstants.NSIL_CARD + "." + NsiliConstants.DATE_TIME_MODIFIED;
assertThat(argumentCaptor.getValue()[0].attribute_name, is(sortAttr));
assertThat(argumentCaptor.getValue()[0].sort_polarity, is(Polarity.ASCENDING));
}
use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.
the class NsiliSourceTest method testQuerySortingNullSortableAttributes.
@Test
public void testQuerySortingNullSortableAttributes() throws Exception {
source.setSortableAttributes(null);
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(GMTI));
SortBy sortBy = new SortByImpl(RELEVANCE, SortOrder.DESCENDING);
propertyIsLikeQuery.setSortBy(sortBy);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
ArgumentCaptor<SortAttribute[]> argumentCaptor = ArgumentCaptor.forClass(SortAttribute[].class);
verify(catalogMgr).submit_query(any(Query.class), any(String[].class), argumentCaptor.capture(), any(NameValue[].class));
// Length is 1, as we force a sort attribute if a valid one is not provided.
assertThat(argumentCaptor.getValue().length, is(1));
}
use of org.codice.alliance.nsili.common.GIAS.SortAttribute in project alliance by codice.
the class NsiliSourceTest method testQueryUnsupportedSorting.
@Test
public void testQueryUnsupportedSorting() throws Exception {
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(GMTI));
SortBy sortBy = new SortByImpl(RELEVANCE, SortOrder.DESCENDING);
propertyIsLikeQuery.setSortBy(sortBy);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
ArgumentCaptor<SortAttribute[]> argumentCaptor = ArgumentCaptor.forClass(SortAttribute[].class);
verify(catalogMgr).submit_query(any(Query.class), any(String[].class), argumentCaptor.capture(), any(NameValue[].class));
assertThat(argumentCaptor.getValue().length, is(0));
}
Aggregations