Search in sources :

Example 6 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class NoOpSolrMetacardClient method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    LOGGER.debug("Query was not executed. SolrMetacardClient has not been initialized.");
    SourceResponseImpl sourceResponseImpl = new SourceResponseImpl(request, Collections.emptyList());
    sourceResponseImpl.setHits(0);
    return sourceResponseImpl;
}
Also used : SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl)

Example 7 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class TestGeoJsonQueryResponseTransformer method testNullMetacard.

@Test(expected = CatalogTransformerException.class)
public void testNullMetacard() throws CatalogTransformerException {
    List<Result> results = new LinkedList<Result>();
    Result result = new ResultImpl(null);
    results.add(result);
    SourceResponse sourceResponse = new SourceResponseImpl(null, results, 1L);
    new GeoJsonQueryResponseTransformer().transform(sourceResponse, null);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) LinkedList(java.util.LinkedList) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 8 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class TestGeoJsonQueryResponseTransformer method testNullResult.

@Test(expected = CatalogTransformerException.class)
public void testNullResult() throws CatalogTransformerException {
    List<Result> results = new LinkedList<Result>();
    results.add(null);
    results.add(null);
    SourceResponse sourceResponse = new SourceResponseImpl(null, results, 2L);
    new GeoJsonQueryResponseTransformer().transform(sourceResponse, null);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) LinkedList(java.util.LinkedList) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 9 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testQueryTransformWithTransformException.

@Test(expected = CatalogTransformerException.class)
public void testQueryTransformWithTransformException() throws Exception {
    BundleContext context = mock(BundleContext.class);
    QueryResponseTransformer transformer = mock(QueryResponseTransformer.class);
    ServiceReference reference = mock(ServiceReference.class);
    ServiceReference[] serviceReferences = new ServiceReference[] { reference };
    when(context.getServiceReferences(anyString(), anyString())).thenReturn(serviceReferences);
    when(context.getService(isA(ServiceReference.class))).thenReturn(transformer);
    when(transformer.transform(isA(SourceResponse.class), isA(Map.class))).thenThrow(new CatalogTransformerException("Could not transform"));
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
    SourceResponse response = new SourceResponseImpl(null, null);
    framework.transform(response, "NONE", new HashMap<String, Serializable>());
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) CatalogFramework(ddf.catalog.CatalogFramework) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 10 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class OpenSearchSource method query.

@Override
public SourceResponse query(QueryRequest queryRequest) throws UnsupportedQueryException {
    String methodName = "query";
    LOGGER.trace(methodName);
    Serializable metacardId = queryRequest.getPropertyValue(Metacard.ID);
    SourceResponseImpl response = null;
    Subject subject = null;
    WebClient restWebClient = null;
    if (queryRequest.hasProperties()) {
        Object subjectObj = queryRequest.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
        subject = (Subject) subjectObj;
    }
    restWebClient = factory.getWebClientForSubject(subject);
    Query query = queryRequest.getQuery();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Received query: " + query);
    }
    boolean canDoOpenSearch = setOpenSearchParameters(query, subject, restWebClient);
    if (canDoOpenSearch) {
        InputStream responseStream = performRequest(restWebClient);
        response = new SourceResponseImpl(queryRequest, new ArrayList<Result>());
        if (responseStream != null) {
            response = processResponse(responseStream, queryRequest);
        }
    } else {
        if (StringUtils.isEmpty((String) metacardId)) {
            OpenSearchFilterVisitor visitor = new OpenSearchFilterVisitor();
            query.accept(visitor, null);
            metacardId = visitor.getMetacardId();
        }
        restWebClient = newRestClient(query, (String) metacardId, false, subject);
        if (restWebClient != null) {
            InputStream responseStream = performRequest(restWebClient);
            Metacard metacard = null;
            List<Result> resultQueue = new ArrayList<Result>();
            try (TemporaryFileBackedOutputStream fileBackedOutputStream = new TemporaryFileBackedOutputStream()) {
                if (responseStream != null) {
                    IOUtils.copyLarge(responseStream, fileBackedOutputStream);
                    InputTransformer inputTransformer = null;
                    try (InputStream inputStream = fileBackedOutputStream.asByteSource().openStream()) {
                        inputTransformer = getInputTransformer(inputStream);
                    } catch (IOException e) {
                        LOGGER.debug("Problem with transformation.", e);
                    }
                    if (inputTransformer != null) {
                        try (InputStream inputStream = fileBackedOutputStream.asByteSource().openStream()) {
                            metacard = inputTransformer.transform(inputStream);
                        } catch (IOException e) {
                            LOGGER.debug("Problem with transformation.", e);
                        }
                    }
                }
            } catch (IOException | CatalogTransformerException e) {
                LOGGER.debug("Problem with transformation.", e);
            }
            if (metacard != null) {
                metacard.setSourceId(getId());
                ResultImpl result = new ResultImpl(metacard);
                resultQueue.add(result);
                response = new SourceResponseImpl(queryRequest, resultQueue);
                response.setHits(resultQueue.size());
            }
        }
    }
    LOGGER.trace(methodName);
    return response;
}
Also used : Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ResultImpl(ddf.catalog.data.impl.ResultImpl) IOException(java.io.IOException) InputTransformer(ddf.catalog.transform.InputTransformer) WebClient(org.apache.cxf.jaxrs.client.WebClient) Subject(ddf.security.Subject) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard)

Aggregations

SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)36 SourceResponse (ddf.catalog.operation.SourceResponse)24 ResultImpl (ddf.catalog.data.impl.ResultImpl)20 Result (ddf.catalog.data.Result)19 Test (org.junit.Test)19 Metacard (ddf.catalog.data.Metacard)17 QueryRequest (ddf.catalog.operation.QueryRequest)13 ArrayList (java.util.ArrayList)12 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)6 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)6 IOException (java.io.IOException)6 Query (ddf.catalog.operation.Query)5 BundleContext (org.osgi.framework.BundleContext)5 Matchers.anyString (org.mockito.Matchers.anyString)4 BinaryContent (ddf.catalog.data.BinaryContent)3 QueryImpl (ddf.catalog.operation.impl.QueryImpl)3 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)3 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)3 Serializable (java.io.Serializable)3