Search in sources :

Example 81 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class AbstractCatalogService method getHeaders.

@Override
public BinaryContent getHeaders(String sourceid, String id, URI absolutePath, MultivaluedMap<String, String> queryParameters) throws CatalogServiceException {
    QueryResponse queryResponse;
    Metacard card = null;
    LOGGER.trace("getHeaders");
    if (id != null) {
        LOGGER.debug("Got id: {}", LogSanitizer.sanitize(id));
        LOGGER.debug("Map of query parameters: \n{}", LogSanitizer.sanitize(queryParameters));
        Map<String, Serializable> convertedMap = convert(queryParameters);
        convertedMap.put("url", absolutePath.toString());
        LOGGER.debug("Map converted, retrieving product.");
        // default to xml if no transformer specified
        try {
            String transformer = DEFAULT_METACARD_TRANSFORMER;
            Filter filter = getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id);
            Collection<String> sources = null;
            if (sourceid != null) {
                sources = new ArrayList<>();
                sources.add(sourceid);
            }
            QueryRequestImpl request = new QueryRequestImpl(new QueryImpl(filter), sources);
            request.setProperties(convertedMap);
            queryResponse = catalogFramework.query(request, null);
            // pull the metacard out of the blocking queue
            List<Result> results = queryResponse.getResults();
            // return null if timeout elapsed)
            if (results != null && !results.isEmpty()) {
                card = results.get(0).getMetacard();
            }
            if (card == null) {
                return null;
            }
            LOGGER.debug("Calling transform.");
            final BinaryContent content = catalogFramework.transform(card, transformer, convertedMap);
            LOGGER.debug("Read and transform complete, preparing response.");
            return content;
        } catch (FederationException e) {
            String exceptionMessage = "READ failed due to unexpected exception: ";
            LOGGER.info(exceptionMessage, e);
            throw new InternalServerErrorException(exceptionMessage);
        } catch (CatalogTransformerException e) {
            String exceptionMessage = "Unable to transform Metacard.  Try different transformer: ";
            LOGGER.info(exceptionMessage, e);
            throw new InternalServerErrorException(exceptionMessage);
        } catch (SourceUnavailableException e) {
            String exceptionMessage = "Cannot obtain query results because source is unavailable: ";
            LOGGER.info(exceptionMessage, e);
            throw new InternalServerErrorException(exceptionMessage);
        } catch (UnsupportedQueryException e) {
            String errorMessage = "Specified query is unsupported.  Change query and resubmit: ";
            LOGGER.info(errorMessage, e);
            throw new CatalogServiceException(errorMessage);
        // The catalog framework will throw this if any of the transformers blow up. We need to
        // catch this exception
        // here or else execution will return to CXF and we'll lose this message and end up with
        // a huge stack trace
        // in a GUI or whatever else is connected to this endpoint
        } catch (IllegalArgumentException e) {
            throw new CatalogServiceException(e.getMessage());
        }
    } else {
        throw new CatalogServiceException("No ID specified.");
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Serializable(java.io.Serializable) CatalogServiceException(org.codice.ddf.rest.api.CatalogServiceException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) BinaryContent(ddf.catalog.data.BinaryContent) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) InternalServerErrorException(javax.ws.rs.InternalServerErrorException)

Example 82 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class MetacardIngestNetworkPluginTest method testPassthroughMethods.

@Test
public void testPassthroughMethods() throws Exception {
    ThreadContext.put(CLIENT_INFO_KEY, INFO_MAP);
    UpdateRequest updateRequest = mock(UpdateRequest.class);
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    QueryRequest queryRequest = mock(QueryRequest.class);
    ResourceRequest resourceRequest = mock(ResourceRequest.class);
    DeleteResponse deleteResponse = mock(DeleteResponse.class);
    QueryResponse queryResponse = mock(QueryResponse.class);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    assertThat(plugin.processPreUpdate(updateRequest, mock(Map.class)), is(updateRequest));
    assertThat(plugin.processPreDelete(deleteRequest), is(deleteRequest));
    assertThat(plugin.processPreQuery(queryRequest), is(queryRequest));
    assertThat(plugin.processPreResource(resourceRequest), is(resourceRequest));
    assertThat(plugin.processPostDelete(deleteResponse), is(deleteResponse));
    assertThat(plugin.processPostQuery(queryResponse), is(queryResponse));
    assertThat(plugin.processPostResource(resourceResponse, mock(Metacard.class)), is(resourceResponse));
    verifyZeroInteractions(mockMetacardCondition, mockMetacardServices, updateRequest, deleteRequest, queryRequest, resourceRequest, deleteResponse, queryResponse, resourceResponse);
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) ResourceResponse(ddf.catalog.operation.ResourceResponse) UpdateRequest(ddf.catalog.operation.UpdateRequest) QueryResponse(ddf.catalog.operation.QueryResponse) ResourceRequest(ddf.catalog.operation.ResourceRequest) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 83 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class SendEvent method sendEvent.

private void sendEvent(String operation, Metacard... metacards) {
    if (subject == null) {
        return;
    }
    try {
        List<Result> results = Arrays.asList(metacards).stream().map(ResultImpl::new).collect(Collectors.toList());
        QueryResponse queryResponse = new QueryResponseImpl(query, results, true, metacards.length);
        CswRecordCollection recordCollection = new CswRecordCollection();
        recordCollection.setElementName(elementName);
        recordCollection.setElementSetType(elementSetType);
        recordCollection.setById(false);
        recordCollection.setRequest(request);
        recordCollection.setResultType(resultType);
        recordCollection.setDoWriteNamespaces(false);
        recordCollection.setMimeType(mimeType);
        recordCollection.setOutputSchema(outputSchema);
        queryResponse.getRequest().getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
        for (AccessPlugin plugin : getAccessPlugins()) {
            queryResponse = plugin.processPostQuery(queryResponse);
        }
        if (queryResponse.getResults().isEmpty()) {
            return;
        }
        recordCollection.setSourceResponse(queryResponse);
        send(operation, recordCollection);
    } catch (StopProcessingException | InvalidSyntaxException e) {
        LOGGER.debug("Unable to send event error running AccessPlugin processPostQuery. ", e);
    }
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) AccessPlugin(ddf.catalog.plugin.AccessPlugin) QueryResponse(ddf.catalog.operation.QueryResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Result(ddf.catalog.data.Result)

Example 84 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class GeoNamesCatalogIndexerTest method setUp.

@Before
public void setUp() throws Exception {
    geoEntryCreator = mock(GeoEntryCreator.class);
    when(geoEntryCreator.createGeoEntry(anyString(), anyString())).thenReturn(GEO_ENTRY);
    geoEntryExtractor = new GeoNamesFileExtractor();
    geoEntryExtractor.setGeoEntryCreator(geoEntryCreator);
    catalogFramework = mock(CatalogFramework.class);
    uuidGenerator = mock(UuidGenerator.class);
    createResponse = mock(CreateResponse.class);
    when(createResponse.getCreatedMetacards()).thenReturn(Collections.singletonList(METACARD));
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    catalogProvider = mock(CatalogProvider.class);
    DeleteResponse deleteResponse = mock(DeleteResponse.class);
    when(deleteResponse.getDeletedMetacards()).thenReturn(Collections.singletonList(METACARD));
    when(catalogProvider.delete(any(DeleteRequest.class))).thenReturn(deleteResponse);
    queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(Collections.singletonList(new ResultImpl(new MetacardImpl())));
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse);
    progressCallback = progress -> {
    };
    geoNamesCatalogIndexer = new GeoNamesCatalogIndexer(catalogFramework, uuidGenerator, new GeoEntryAttributes(), new GeotoolsFilterBuilder(), Collections.singletonList(catalogProvider));
}
Also used : UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) QueryRequest(ddf.catalog.operation.QueryRequest) GeoEntryAttributes(org.codice.ddf.spatial.geocoding.GeoEntryAttributes) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) ResultImpl(ddf.catalog.data.impl.ResultImpl) GeoEntryCreator(org.codice.ddf.spatial.geocoding.GeoEntryCreator) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeoNamesFileExtractor(org.codice.ddf.spatial.geocoding.extract.GeoNamesFileExtractor) CatalogFramework(ddf.catalog.CatalogFramework) DeleteRequest(ddf.catalog.operation.DeleteRequest) Before(org.junit.Before)

Example 85 with QueryResponse

use of ddf.catalog.operation.QueryResponse in project ddf by codice.

the class GazetteerQueryCatalog method queryById.

@Override
public GeoEntry queryById(String id) throws GeoEntryQueryException {
    if (StringUtils.isBlank(id)) {
        throw new IllegalArgumentException("id cannot be blank or null");
    }
    Filter idFilter = filterBuilder.attribute(Core.ID).is().text(id);
    Filter queryFilter = filterBuilder.allOf(tagFilter, idFilter);
    QueryResponse queryResponse;
    try {
        queryResponse = catalogFramework.query(new QueryRequestImpl(new QueryImpl(queryFilter)));
    } catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
        throw new GeoEntryQueryException(ERROR_MESSAGE, e);
    }
    if (!queryResponse.getResults().isEmpty()) {
        Result result = queryResponse.getResults().get(0);
        return transformMetacardToGeoEntry(result.getMetacard());
    }
    return null;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) GeoEntryQueryException(org.codice.ddf.spatial.geocoding.GeoEntryQueryException) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Result(ddf.catalog.data.Result)

Aggregations

QueryResponse (ddf.catalog.operation.QueryResponse)187 QueryRequest (ddf.catalog.operation.QueryRequest)130 Test (org.junit.Test)113 Metacard (ddf.catalog.data.Metacard)91 Result (ddf.catalog.data.Result)85 ArrayList (java.util.ArrayList)73 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)70 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)55 QueryImpl (ddf.catalog.operation.impl.QueryImpl)48 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)43 FederationException (ddf.catalog.federation.FederationException)40 ResultImpl (ddf.catalog.data.impl.ResultImpl)39 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)39 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)33 Filter (org.opengis.filter.Filter)33 HashMap (java.util.HashMap)31 Serializable (java.io.Serializable)30 Source (ddf.catalog.source.Source)28 HashSet (java.util.HashSet)28 CatalogFramework (ddf.catalog.CatalogFramework)26