Search in sources :

Example 1 with ProcessingFault

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;
}
Also used : SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ProcessingFault(org.codice.alliance.nsili.common.UCO.ProcessingFault) Result(ddf.catalog.data.Result) SubmitQueryRequest(org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest) SystemFault(org.codice.alliance.nsili.common.UCO.SystemFault) IntHolder(org.omg.CORBA.IntHolder) InvalidInputParameter(org.codice.alliance.nsili.common.UCO.InvalidInputParameter) ExecutionException(java.util.concurrent.ExecutionException) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) DAG(org.codice.alliance.nsili.common.UCO.DAG) DAGListHolder(org.codice.alliance.nsili.common.UCO.DAGListHolder) HitCountRequest(org.codice.alliance.nsili.common.GIAS.HitCountRequest) DAGConverter(org.codice.alliance.nsili.transformer.DAGConverter) NameValue(org.codice.alliance.nsili.common.UCO.NameValue) Metacard(ddf.catalog.data.Metacard) ScheduledFuture(java.util.concurrent.ScheduledFuture) Future(java.util.concurrent.Future)

Example 2 with ProcessingFault

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;
}
Also used : AttributeInformation(org.codice.alliance.nsili.common.GIAS.AttributeInformation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessingFault(org.codice.alliance.nsili.common.UCO.ProcessingFault) SystemFault(org.codice.alliance.nsili.common.UCO.SystemFault) List(java.util.List) ArrayList(java.util.ArrayList) InvalidInputParameter(org.codice.alliance.nsili.common.UCO.InvalidInputParameter)

Example 3 with ProcessingFault

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());
    }
}
Also used : SystemFault(org.codice.alliance.nsili.common.UCO.SystemFault) LibraryManager(org.codice.alliance.nsili.common.GIAS.LibraryManager) AccessCriteria(org.codice.alliance.nsili.common.GIAS.AccessCriteria) InvalidInputParameter(org.codice.alliance.nsili.common.UCO.InvalidInputParameter) ProcessingFault(org.codice.alliance.nsili.common.UCO.ProcessingFault)

Example 4 with ProcessingFault

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;
}
Also used : SystemFault(org.codice.alliance.nsili.common.UCO.SystemFault) IntHolder(org.omg.CORBA.IntHolder) InvalidInputParameter(org.codice.alliance.nsili.common.UCO.InvalidInputParameter) ProcessingFault(org.codice.alliance.nsili.common.UCO.ProcessingFault) HitCountRequest(org.codice.alliance.nsili.common.GIAS.HitCountRequest)

Example 5 with ProcessingFault

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;
}
Also used : LibraryDescription(org.codice.alliance.nsili.common.GIAS.LibraryDescription) SystemFault(org.codice.alliance.nsili.common.UCO.SystemFault) ProcessingFault(org.codice.alliance.nsili.common.UCO.ProcessingFault)

Aggregations

ProcessingFault (org.codice.alliance.nsili.common.UCO.ProcessingFault)5 SystemFault (org.codice.alliance.nsili.common.UCO.SystemFault)5 InvalidInputParameter (org.codice.alliance.nsili.common.UCO.InvalidInputParameter)4 ArrayList (java.util.ArrayList)2 HitCountRequest (org.codice.alliance.nsili.common.GIAS.HitCountRequest)2 IntHolder (org.omg.CORBA.IntHolder)2 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 AccessCriteria (org.codice.alliance.nsili.common.GIAS.AccessCriteria)1 AttributeInformation (org.codice.alliance.nsili.common.GIAS.AttributeInformation)1 LibraryDescription (org.codice.alliance.nsili.common.GIAS.LibraryDescription)1 LibraryManager (org.codice.alliance.nsili.common.GIAS.LibraryManager)1 SortAttribute (org.codice.alliance.nsili.common.GIAS.SortAttribute)1