Search in sources :

Example 41 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestXmlResponseQueueTransformer method givenMetacardTypeName.

private SourceResponse givenMetacardTypeName(String metacardTypeName) {
    MetacardType type = getMetacardTypeStub(metacardTypeName, new HashSet<AttributeDescriptor>());
    Metacard metacard = new MetacardImpl(type);
    SourceResponse response = new SourceResponseImpl(null, Arrays.asList((Result) new ResultImpl(metacard)));
    return response;
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

Example 42 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class TestZipCompression method createSourceResponseWithURISchemes.

private SourceResponse createSourceResponseWithURISchemes(String scheme, String derivedResourceScheme) throws Exception {
    List<Result> resultList = new ArrayList<>();
    for (String string : METACARD_ID_LIST) {
        MetacardImpl metacard = new MetacardImpl();
        metacard.setId(string);
        if (scheme != null && string.equals(METACARD_ID_LIST.get(METACARD_ID_LIST.size() - 1))) {
            URI uri = new URI(scheme + metacard.getId());
            metacard.setResourceURI(uri);
            if (StringUtils.isNotBlank(derivedResourceScheme)) {
                metacard.setAttribute(Metacard.DERIVED_RESOURCE_URI, derivedResourceScheme);
            }
        }
        Result result = new ResultImpl(metacard);
        resultList.add(result);
    }
    return new SourceResponseImpl(null, resultList);
}
Also used : SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

Example 43 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl 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 44 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project alliance by codice.

the class AccessManagerImplTest method testIsAvailableWithBadURL.

@Test
public void testIsAvailableWithBadURL() throws Exception {
    MetacardImpl testMetacard = new MetacardImpl();
    testMetacard.setId(testMetacardId);
    testMetacard.setTitle("JUnit Test Card");
    testMetacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_DOWNLOAD_URL, "http://localhost:20999/not/present"));
    Result testResult = new ResultImpl(testMetacard);
    List<Result> results = new ArrayList<>();
    results.add(testResult);
    QueryResponse testResponse = new QueryResponseImpl(null, results, results.size());
    when(mockCatalogFramework.query(any(QueryRequest.class))).thenReturn(testResponse);
    DAG dag = ResultDAGConverter.convertResult(testResult, orb, rootPOA, new ArrayList<>(), new HashMap<>());
    Product product = ProductHelper.extract(dag.nodes[0].value);
    boolean avail = accessManager.is_available(product, null);
    assertThat(avail, is(false));
    avail = accessManager.is_available(null, null);
    assertThat(avail, is(false));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) Product(org.codice.alliance.nsili.common.UID.Product) ResultImpl(ddf.catalog.data.impl.ResultImpl) DAG(org.codice.alliance.nsili.common.UCO.DAG) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 45 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project alliance by codice.

the class AccessManagerImplTest method testIsAvailableNoURL.

@Test
public void testIsAvailableNoURL() throws Exception {
    MetacardImpl testMetacard = new MetacardImpl();
    testMetacard.setId(testMetacardId);
    testMetacard.setTitle("JUnit Test Card");
    Result testResult = new ResultImpl(testMetacard);
    DAG dag = ResultDAGConverter.convertResult(testResult, orb, rootPOA, new ArrayList<>(), new HashMap<>());
    Product product = ProductHelper.extract(dag.nodes[0].value);
    boolean avail = accessManager.is_available(product, null);
    assertThat(avail, is(false));
    avail = accessManager.is_available(null, null);
    assertThat(avail, is(false));
}
Also used : Product(org.codice.alliance.nsili.common.UID.Product) ResultImpl(ddf.catalog.data.impl.ResultImpl) DAG(org.codice.alliance.nsili.common.UCO.DAG) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

ResultImpl (ddf.catalog.data.impl.ResultImpl)114 Result (ddf.catalog.data.Result)74 Test (org.junit.Test)73 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)61 Metacard (ddf.catalog.data.Metacard)47 ArrayList (java.util.ArrayList)45 QueryRequest (ddf.catalog.operation.QueryRequest)33 SourceResponse (ddf.catalog.operation.SourceResponse)30 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)23 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)21 QueryResponse (ddf.catalog.operation.QueryResponse)20 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)18 DAG (org.codice.alliance.nsili.common.UCO.DAG)17 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 BinaryContent (ddf.catalog.data.BinaryContent)10 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 Product (org.codice.alliance.nsili.common.UID.Product)9 Query (ddf.catalog.operation.Query)7 PolicyResponse (ddf.catalog.plugin.PolicyResponse)7