Search in sources :

Example 1 with InvalidInputParameter

use of org.codice.alliance.nsili.common.UCO.InvalidInputParameter in project alliance by codice.

the class LibraryImpl method get_manager.

@Override
public LibraryManager get_manager(String manager_type, AccessCriteria access_criteria) throws ProcessingFault, InvalidInputParameter, SystemFault {
    org.omg.CORBA.Object obj;
    switch(manager_type) {
        case "CatalogMgr":
            CatalogMgrImpl catalogMgr = new CatalogMgrImpl(poa_);
            try {
                poa_.activate_object_with_id(manager_type.getBytes(Charset.forName(ENCODING)), catalogMgr);
            } catch (Exception e) {
            // Ignore
            }
            obj = poa_.create_reference_with_id(manager_type.getBytes(Charset.forName(ENCODING)), CatalogMgrHelper.id());
            break;
        case "OrderMgr":
            OrderMgrImpl orderMgr = new OrderMgrImpl();
            try {
                poa_.activate_object_with_id(manager_type.getBytes(Charset.forName(ENCODING)), orderMgr);
            } catch (Exception e) {
            // Ignore
            }
            obj = poa_.create_reference_with_id(manager_type.getBytes(Charset.forName(ENCODING)), OrderMgrHelper.id());
            break;
        case "ProductMgr":
            ProductMgrImpl productMgr = new ProductMgrImpl();
            try {
                poa_.activate_object_with_id(manager_type.getBytes(Charset.forName(ENCODING)), productMgr);
            } catch (Exception e) {
            // Ignore
            }
            obj = poa_.create_reference_with_id(manager_type.getBytes(Charset.forName(ENCODING)), ProductMgrHelper.id());
            break;
        case "DataModelMgr":
            DataModelMgrImpl dataModelMgr = new DataModelMgrImpl();
            try {
                poa_.activate_object_with_id(manager_type.getBytes(Charset.forName(ENCODING)), dataModelMgr);
            } catch (Exception e) {
            // Ignore
            }
            obj = poa_.create_reference_with_id(manager_type.getBytes(Charset.forName(ENCODING)), DataModelMgrHelper.id());
            break;
        default:
            String[] bad_params = { manager_type };
            throw new InvalidInputParameter("UnknownMangerType", new exception_details("UnknownMangerType", true, manager_type), bad_params);
    }
    LibraryManager libraryManager = LibraryManagerHelper.narrow(obj);
    return libraryManager;
}
Also used : OrderMgrImpl(org.codice.alliance.nsili.mockserver.impl.managers.OrderMgrImpl) DataModelMgrImpl(org.codice.alliance.nsili.mockserver.impl.managers.DataModelMgrImpl) ProductMgrImpl(org.codice.alliance.nsili.mockserver.impl.managers.ProductMgrImpl) UCO.exception_details(org.codice.alliance.nsili.common.UCO.exception_details) LibraryManager(org.codice.alliance.nsili.common.GIAS.LibraryManager) CatalogMgrImpl(org.codice.alliance.nsili.mockserver.impl.managers.CatalogMgrImpl) InvalidInputParameter(org.codice.alliance.nsili.common.UCO.InvalidInputParameter)

Example 2 with InvalidInputParameter

use of org.codice.alliance.nsili.common.UCO.InvalidInputParameter 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 3 with InvalidInputParameter

use of org.codice.alliance.nsili.common.UCO.InvalidInputParameter 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 4 with InvalidInputParameter

use of org.codice.alliance.nsili.common.UCO.InvalidInputParameter 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 5 with InvalidInputParameter

use of org.codice.alliance.nsili.common.UCO.InvalidInputParameter in project alliance by codice.

the class StandingQueryMgrImpl method submit_standing_query.

@Override
public SubmitStandingQueryRequest submit_standing_query(Query aQuery, String[] result_attributes, SortAttribute[] sort_attributes, QueryLifeSpan lifespan, NameValue[] properties) throws InvalidInputParameter, ProcessingFault, SystemFault {
    if (aQuery == null) {
        InvalidInputParameter except = new InvalidInputParameter();
        exception_details details = new exception_details();
        details.exception_name = "No Query Specified";
        details.exception_desc = "Query must be specified for standing query request";
        except.details = details;
        throw except;
    }
    LOGGER.debug("Registering Standing Query View: {}, BQS: {}", aQuery.view, aQuery.bqs_query);
    SubmitStandingQueryRequestImpl standingQueryRequest = new SubmitStandingQueryRequestImpl(aQuery, result_attributes, sort_attributes, lifespan, properties, catalogFramework, filterBuilder, defaultUpdateFrequencyMsec, querySources, maxPendingResults, removeSourceLibrary, outgoingValidationEnabled, maxWaitToStartTimeMsecs);
    String id = UUID.randomUUID().toString();
    try {
        _poa().activate_object_with_id(id.getBytes(Charset.forName(NsiliEndpoint.ENCODING)), standingQueryRequest);
    } catch (ServantAlreadyActive | ObjectAlreadyActive | WrongPolicy e) {
        LOGGER.debug("submit_standing_query : Unable to activate submitStandingQueryRequest object.", e);
    }
    org.omg.CORBA.Object obj = _poa().create_reference_with_id(id.getBytes(Charset.forName(NsiliEndpoint.ENCODING)), SubmitStandingQueryRequestHelper.id());
    SubmitStandingQueryRequest submitStandingQueryRequest = SubmitStandingQueryRequestHelper.narrow(obj);
    return submitStandingQueryRequest;
}
Also used : SubmitStandingQueryRequest(org.codice.alliance.nsili.common.GIAS.SubmitStandingQueryRequest) WrongPolicy(org.omg.PortableServer.POAPackage.WrongPolicy) UCO.exception_details(org.codice.alliance.nsili.common.UCO.exception_details) ObjectAlreadyActive(org.omg.PortableServer.POAPackage.ObjectAlreadyActive) InvalidInputParameter(org.codice.alliance.nsili.common.UCO.InvalidInputParameter) SubmitStandingQueryRequestImpl(org.codice.alliance.nsili.endpoint.requests.SubmitStandingQueryRequestImpl) ServantAlreadyActive(org.omg.PortableServer.POAPackage.ServantAlreadyActive)

Aggregations

InvalidInputParameter (org.codice.alliance.nsili.common.UCO.InvalidInputParameter)7 ProcessingFault (org.codice.alliance.nsili.common.UCO.ProcessingFault)4 SystemFault (org.codice.alliance.nsili.common.UCO.SystemFault)4 LibraryManager (org.codice.alliance.nsili.common.GIAS.LibraryManager)3 UCO.exception_details (org.codice.alliance.nsili.common.UCO.exception_details)3 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 SortAttribute (org.codice.alliance.nsili.common.GIAS.SortAttribute)1