Search in sources :

Example 1 with DAGListHolder

use of org.codice.alliance.nsili.common.UCO.DAGListHolder 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;
    }
}
Also used : SubmitQueryRequest(org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) DAGListHolder(org.codice.alliance.nsili.common.UCO.DAGListHolder)

Example 2 with DAGListHolder

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

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

the class NsiliSourceTest method getMockCatalogMgr.

private CatalogMgr getMockCatalogMgr() throws Exception {
    SubmitQueryRequest submitQueryRequest = mock(SubmitQueryRequest.class);
    HitCountRequest hitCountRequest = mock(HitCountRequest.class);
    doReturn(State.COMPLETED).when(hitCountRequest).complete(any(IntHolder.class));
    Status status = new Status();
    status.completion_state = State.COMPLETED;
    doReturn(status).when(hitCountRequest).get_status();
    when(hitCountRequest.complete(any(IntHolder.class))).thenAnswer((InvocationOnMock invocationOnMock) -> {
        IntHolder intHolder = (IntHolder) invocationOnMock.getArguments()[0];
        intHolder.value = 12;
        return State.COMPLETED;
    });
    when(submitQueryRequest.complete_DAG_results(any(DAGListHolder.class))).thenAnswer((InvocationOnMock invocationOnMock) -> {
        DAGListHolder dagListHolder = (DAGListHolder) invocationOnMock.getArguments()[0];
        dagListHolder.value = getMockDAGArray();
        return State.COMPLETED;
    });
    doReturn(submitQueryRequest).when(catalogMgr).submit_query(any(Query.class), any(String[].class), any(SortAttribute[].class), any(NameValue[].class));
    doReturn(hitCountRequest).when(catalogMgr).hit_count(any(Query.class), any(NameValue[].class));
    return catalogMgr;
}
Also used : Status(org.codice.alliance.nsili.common.UCO.Status) SubmitQueryRequest(org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest) Query(org.codice.alliance.nsili.common.GIAS.Query) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IntHolder(org.omg.CORBA.IntHolder) HitCountRequest(org.codice.alliance.nsili.common.GIAS.HitCountRequest) DAGListHolder(org.codice.alliance.nsili.common.UCO.DAGListHolder)

Example 4 with DAGListHolder

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

the class CatalogMgrImplTest method testQuery.

@Test
public void testQuery() throws InvalidInputParameter, SystemFault, ProcessingFault {
    String[] resultAttributes = null;
    SortAttribute[] sortAttributes = null;
    catalogMgr.setMaxNumResults(999);
    catalogMgr.set_default_timeout(AccessManagerImpl.DEFAULT_TIMEOUT);
    SubmitQueryRequest submitQueryRequest = catalogMgr.submit_query(testQuery, resultAttributes, sortAttributes, null);
    assertThat(submitQueryRequest, notNullValue());
    DAGListHolder dagListHolder = new DAGListHolder();
    submitQueryRequest.complete_DAG_results(dagListHolder);
    assertThat(dagListHolder.value, notNullValue());
    assertThat(dagListHolder.value.length, is(2));
}
Also used : SubmitQueryRequest(org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest) SortAttribute(org.codice.alliance.nsili.common.GIAS.SortAttribute) DAGListHolder(org.codice.alliance.nsili.common.UCO.DAGListHolder) Test(org.junit.Test)

Example 5 with DAGListHolder

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

the class SubmitStandingQueryRequestImplTest method testComplete.

@Test
public void testComplete() throws SystemFault, ProcessingFault, UnsupportedQueryException, SourceUnavailableException, FederationException {
    DAGListHolder results = new DAGListHolder();
    standingQueryRequest.complete_DAG_results(results);
    assertThat(results, notNullValue());
    DAG[] dagResults = results.value;
    assertThat(dagResults.length, is(2));
}
Also used : DAG(org.codice.alliance.nsili.common.UCO.DAG) StringDAGListHolder(org.codice.alliance.nsili.common.UCO.StringDAGListHolder) DAGListHolder(org.codice.alliance.nsili.common.UCO.DAGListHolder) Test(org.junit.Test)

Aggregations

DAGListHolder (org.codice.alliance.nsili.common.UCO.DAGListHolder)5 SubmitQueryRequest (org.codice.alliance.nsili.common.GIAS.SubmitQueryRequest)4 SortAttribute (org.codice.alliance.nsili.common.GIAS.SortAttribute)3 HitCountRequest (org.codice.alliance.nsili.common.GIAS.HitCountRequest)2 DAG (org.codice.alliance.nsili.common.UCO.DAG)2 Test (org.junit.Test)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 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 InvalidInputParameter (org.codice.alliance.nsili.common.UCO.InvalidInputParameter)1 NameValue (org.codice.alliance.nsili.common.UCO.NameValue)1 ProcessingFault (org.codice.alliance.nsili.common.UCO.ProcessingFault)1 Status (org.codice.alliance.nsili.common.UCO.Status)1