Search in sources :

Example 1 with HitCountRequest

use of org.codice.alliance.nsili.common.GIAS.HitCountRequest in project alliance by codice.

the class SampleNsiliClient method getHitCount.

public int getHitCount() throws Exception {
    if (catalogMgr != null) {
        LOGGER.info("Getting Hit Count From Query...");
        HitCountRequest hitCountRequest = catalogMgr.hit_count(QUERY, new NameValue[0]);
        IntHolder intHolder = new IntHolder();
        hitCountRequest.complete(intHolder);
        LOGGER.info("Server responded with {} hit(s). ", intHolder.value);
        return intHolder.value;
    } else {
        LOGGER.warn("CatalogMgr was not initialized, unable to find hit count");
        return -1;
    }
}
Also used : IntHolder(org.omg.CORBA.IntHolder) HitCountRequest(org.codice.alliance.nsili.common.GIAS.HitCountRequest)

Example 2 with HitCountRequest

use of org.codice.alliance.nsili.common.GIAS.HitCountRequest in project alliance by codice.

the class CatalogMgrImpl method hit_count.

@Override
public HitCountRequest hit_count(Query aQuery, NameValue[] properties) throws ProcessingFault, InvalidInputParameter, SystemFault {
    HitCountRequestImpl hitCountRequest = new HitCountRequestImpl();
    try {
        poa_.activate_object_with_id("hit_count".getBytes(Charset.forName(ENCODING)), hitCountRequest);
    } catch (ServantAlreadyActive | ObjectAlreadyActive | WrongPolicy e) {
        LOGGER.warn("hit_count : Unable to activate hitCountRequest object.", e);
    }
    org.omg.CORBA.Object obj = poa_.create_reference_with_id("hit_count".getBytes(Charset.forName(ENCODING)), HitCountRequestHelper.id());
    HitCountRequest queryRequest = HitCountRequestHelper.narrow(obj);
    return queryRequest;
}
Also used : WrongPolicy(org.omg.PortableServer.POAPackage.WrongPolicy) ObjectAlreadyActive(org.omg.PortableServer.POAPackage.ObjectAlreadyActive) HitCountRequestImpl(org.codice.alliance.nsili.mockserver.impl.requests.HitCountRequestImpl) ServantAlreadyActive(org.omg.PortableServer.POAPackage.ServantAlreadyActive) HitCountRequest(org.codice.alliance.nsili.common.GIAS.HitCountRequest)

Example 3 with HitCountRequest

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

use of org.codice.alliance.nsili.common.GIAS.HitCountRequest in project alliance by codice.

the class CatalogMgrImplTest method testHitCountWithTimeoutSet.

@Test
public void testHitCountWithTimeoutSet() throws InvalidInputParameter, SystemFault, ProcessingFault {
    catalogMgr.set_default_timeout(30);
    HitCountRequest hitCountRequest = catalogMgr.hit_count(testQuery, null);
    IntHolder hitHolder = new IntHolder();
    assertThat(hitCountRequest, notNullValue());
    hitCountRequest.complete(hitHolder);
    assertThat(hitHolder.value, greaterThan(0));
}
Also used : IntHolder(org.omg.CORBA.IntHolder) HitCountRequest(org.codice.alliance.nsili.common.GIAS.HitCountRequest) Test(org.junit.Test)

Example 5 with HitCountRequest

use of org.codice.alliance.nsili.common.GIAS.HitCountRequest in project alliance by codice.

the class CatalogMgrImpl method hit_count.

@Override
public HitCountRequest hit_count(Query aQuery, NameValue[] properties) throws ProcessingFault, InvalidInputParameter, SystemFault {
    // Force this to be an int per the NSILI API
    int numResults = (int) getResultCount(aQuery);
    HitCountRequestImpl hitCountRequest = new HitCountRequestImpl(numResults);
    String id = UUID.randomUUID().toString();
    try {
        poa.activate_object_with_id(id.getBytes(Charset.forName(NsiliEndpoint.ENCODING)), hitCountRequest);
    } catch (ServantAlreadyActive | ObjectAlreadyActive | WrongPolicy e) {
        LOGGER.debug("hit_count : Unable to activate hitCountRequest object: {}", id, e);
    }
    org.omg.CORBA.Object obj = poa.create_reference_with_id(id.getBytes(Charset.forName(NsiliEndpoint.ENCODING)), HitCountRequestHelper.id());
    HitCountRequest queryRequest = HitCountRequestHelper.narrow(obj);
    return queryRequest;
}
Also used : WrongPolicy(org.omg.PortableServer.POAPackage.WrongPolicy) ObjectAlreadyActive(org.omg.PortableServer.POAPackage.ObjectAlreadyActive) HitCountRequestImpl(org.codice.alliance.nsili.endpoint.requests.HitCountRequestImpl) ServantAlreadyActive(org.omg.PortableServer.POAPackage.ServantAlreadyActive) NsiliEndpoint(org.codice.alliance.nsili.endpoint.NsiliEndpoint) HitCountRequest(org.codice.alliance.nsili.common.GIAS.HitCountRequest)

Aggregations

HitCountRequest (org.codice.alliance.nsili.common.GIAS.HitCountRequest)8 IntHolder (org.omg.CORBA.IntHolder)6 SubmitQueryRequest (org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest)2 DAGListHolder (org.codice.alliance.nsili.common.UCO.DAGListHolder)2 InvalidInputParameter (org.codice.alliance.nsili.common.UCO.InvalidInputParameter)2 ProcessingFault (org.codice.alliance.nsili.common.UCO.ProcessingFault)2 SystemFault (org.codice.alliance.nsili.common.UCO.SystemFault)2 Test (org.junit.Test)2 ObjectAlreadyActive (org.omg.PortableServer.POAPackage.ObjectAlreadyActive)2 ServantAlreadyActive (org.omg.PortableServer.POAPackage.ServantAlreadyActive)2 WrongPolicy (org.omg.PortableServer.POAPackage.WrongPolicy)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 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 Query (org.codice.alliance.nsili.common.GIAS.Query)1