use of org.codice.alliance.nsili.common.UCO.ProcessingFault 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.UCO.ProcessingFault in project alliance by codice.
the class NsiliSource method initSortableAndResultAttributes.
/**
* Obtains all possible attributes for all possible views that the Federated Source can provide,
* and populates a sortableAttributes map, as well as resultAttributes map that will be used for
* querying the server. According to ANNEX D, TABLE D-6, the passed parameter in get_view_names is
* an empty list(not used).
*
* @return a map of each view and the attributes provided by the source for that view
*/
private void initSortableAndResultAttributes() {
if (views == null || views.length == 0) {
return;
}
HashMap<String, String[]> resultAttributesMap = new HashMap<>();
HashMap<String, List<String>> sortableAttributesMap = new HashMap<>();
try {
for (int i = 0; i < views.length; i++) {
List<String> sortableAttributesList = new ArrayList<>();
AttributeInformation[] attributeInformationArray = dataModelMgr.get_attributes(views[i].view_name, new NameValue[0]);
String[] resultAttributes = new String[attributeInformationArray.length];
LOGGER.debug("Attributes for view: {}", views[i].view_name);
for (int c = 0; c < attributeInformationArray.length; c++) {
AttributeInformation attributeInformation = attributeInformationArray[c];
resultAttributes[c] = attributeInformation.attribute_name;
if (LOGGER.isDebugEnabled()) {
getModeStr(attributeInformation);
}
if (attributeInformation.sortable) {
sortableAttributesList.add(attributeInformation.attribute_name);
}
}
sortableAttributesMap.put(views[i].view_name, sortableAttributesList);
resultAttributesMap.put(views[i].view_name, resultAttributes);
}
} catch (ProcessingFault | SystemFault | InvalidInputParameter e) {
LOGGER.debug("{} : Unable to retrieve queryable attributes.", sourceId, e);
}
if (resultAttributesMap.size() == 0) {
LOGGER.debug("{} : Received empty attributes list from STANAG source.", getId());
}
this.sortableAttributes = sortableAttributesMap;
this.resultAttributes = resultAttributesMap;
}
use of org.codice.alliance.nsili.common.UCO.ProcessingFault in project alliance by codice.
the class NsiliSource method initMandatoryManagers.
/**
* Initializes all STANAG 4559 mandatory managers: CatalogMgr OrderMgr DataModelMgr ProductMgr
*/
private void initMandatoryManagers() {
try {
accessCriteria = new AccessCriteria(accessUserId, accessPassword, accessLicenseKey);
LibraryManager libraryManager = library.get_manager(CATALOG_MGR, accessCriteria);
setCatalogMgr(CatalogMgrHelper.narrow(libraryManager));
libraryManager = library.get_manager(ORDER_MGR, accessCriteria);
setOrderMgr(OrderMgrHelper.narrow(libraryManager));
libraryManager = library.get_manager(PRODUCT_MGR, accessCriteria);
setProductMgr(ProductMgrHelper.narrow(libraryManager));
libraryManager = library.get_manager(DATA_MODEL_MGR, accessCriteria);
setDataModelMgr(DataModelMgrHelper.narrow(libraryManager));
} catch (ProcessingFault | SystemFault | InvalidInputParameter e) {
LOGGER.debug("{} : Unable to retrieve mandatory managers.", sourceId, e);
}
if (catalogMgr != null && orderMgr != null && productMgr != null && dataModelMgr != null) {
LOGGER.debug("{} : Initialized STANAG mandatory managers.", getId());
} else {
LOGGER.debug("{} : Unable to initialize mandatory mangers.", getId());
}
}
use of org.codice.alliance.nsili.common.UCO.ProcessingFault in project alliance by codice.
the class NsiliSource method getHitCount.
/**
* Obtains the number of hits that the given query has received from the server.
*
* @param query - a BQS query
* @param properties - a list of properties for the query
* @return - the hit count
*/
private int getHitCount(org.codice.alliance.nsili.common.GIAS.Query query, NameValue[] properties) {
IntHolder intHolder = new IntHolder();
try {
synchronized (queryLockObj) {
HitCountRequest hitCountRequest = catalogMgr.hit_count(query, properties);
hitCountRequest.complete(intHolder);
}
} catch (ProcessingFault | SystemFault | InvalidInputParameter e) {
LOGGER.debug("{} : Unable to get hit count for query. : {}", getId(), NsilCorbaExceptionUtil.getExceptionDetails(e), e);
}
LOGGER.debug("{} : Received {} hit(s) from query.", getId(), intHolder.value);
return intHolder.value;
}
use of org.codice.alliance.nsili.common.UCO.ProcessingFault in project alliance by codice.
the class NsiliSource method setSourceDescription.
/**
* Obtains the sourceDescription of the source from the Library interface.
*
* @return a sourceDescription of the source
*/
private void setSourceDescription() {
StringBuilder stringBuilder = new StringBuilder();
try {
LibraryDescription libraryDescription = library.get_library_description();
stringBuilder.append(libraryDescription.library_name + " : ");
stringBuilder.append(libraryDescription.library_description);
} catch (ProcessingFault | SystemFault e) {
LOGGER.debug("{} : Unable to retrieve source sourceDescription.", sourceId, e);
}
String description = stringBuilder.toString();
if (StringUtils.isBlank(description)) {
LOGGER.debug("{} : Unable to retrieve source sourceDescription.", getId());
}
this.sourceDescription = description;
}
Aggregations