Search in sources :

Example 61 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class SolrCacheSource method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    final QueryResponseImpl queryResponse = new QueryResponseImpl(request);
    try {
        SourceResponse result = cache.query(request);
        queryResponse.setHits(result.getHits());
        queryResponse.setProperties(result.getProperties());
        queryResponse.addResults(result.getResults(), true);
    } catch (UnsupportedQueryException e) {
        queryResponse.getProcessingDetails().add(new ProcessingDetailsImpl(getId(), e));
        queryResponse.closeResultQueue();
    }
    return queryResponse;
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) SourceResponse(ddf.catalog.operation.SourceResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl)

Example 62 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class CswEndpoint method getRecordById.

@Override
@POST
@Consumes({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
@Produces({ MediaType.TEXT_XML, MediaType.APPLICATION_XML })
public CswRecordCollection getRecordById(GetRecordByIdType request, @HeaderParam(CswConstants.RANGE_HEADER) String rangeValue) throws CswException {
    if (request == null) {
        throw new CswException("GetRecordByIdRequest request is null");
    }
    String outputFormat = request.getOutputFormat();
    String outputSchema = request.getOutputSchema();
    validator.validateOutputFormat(outputFormat, mimeTypeTransformerManager);
    validator.validateOutputSchema(outputSchema, schemaTransformerManager);
    List<String> ids = request.getId();
    if (!ids.isEmpty()) {
        String id = ids.get(0);
        // Check if the request wants to retrieve a product.
        if (isProductRetrieval(ids, outputFormat, outputSchema)) {
            LOGGER.debug("{} is attempting to retrieve product for: {}", request.getService(), id);
            try {
                return queryProductById(id, rangeValue);
            } catch (UnsupportedQueryException e) {
                throw new CswException(String.format(ERROR_ID_PRODUCT_RETRIEVAL, id), e);
            }
        }
        LOGGER.debug("{} is attempting to retrieve records: {}", request.getService(), ids);
        CswRecordCollection response = queryById(ids, outputSchema);
        response.setOutputSchema(outputSchema);
        if (request.isSetElementSetName() && request.getElementSetName().getValue() != null) {
            response.setElementSetType(request.getElementSetName().getValue());
        } else {
            response.setElementSetType(ElementSetType.SUMMARY);
        }
        LOGGER.debug("{} successfully retrieved record(s): {}", request.getService(), request.getId());
        return response;
    } else {
        throw new CswException("A GetRecordById Query must contain an ID.", CswConstants.MISSING_PARAMETER_VALUE, "id");
    }
}
Also used : UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 63 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class Query method getMetacardForId.

/**
     * @param searchPhrase The search phrase used to query for the metacard.
     * @param proxyTicket  The CAS proxy ticket that will be used by the STS to get a SAML assertion.
     * @return
     */
private String getMetacardForId(String searchPhrase, String proxyTicket) {
    Filter filter = filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase);
    LOGGER.info("Query filter: {}", filter.toString());
    String queryError = "Unable to perform query " + filter.toString() + ".";
    QueryRequest request = new QueryRequestImpl(new QueryImpl(filter), true);
    StringBuilder responseString = new StringBuilder();
    try {
        Subject subject = securityManager.getSubject(new CasAuthenticationToken(proxyTicket));
        LOGGER.info("Adding {} property with value {} to request", SecurityConstants.SECURITY_SUBJECT, subject);
        request.getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
    } catch (SecurityServiceException se) {
        LOGGER.error("Could not retrieve subject from securitymanager.", se);
        return queryError;
    }
    try {
        LOGGER.debug("About to query the catalog framework with query {}", filter.toString());
        QueryResponse queryResponse = catalogFramework.query(request, null);
        LOGGER.debug("Got query response from catalog framework for query {}", filter.toString());
        List<Result> results = queryResponse.getResults();
        if (results != null) {
            String message = "The query for " + filter.toString() + " returned " + results.size() + " results.";
            responseString.append(message);
            LOGGER.debug(message);
            for (Result curResult : results) {
                Metacard metacard = curResult.getMetacard();
                LOGGER.debug("Transforming the metacard with id [{}] to xml.", metacard.getId());
                BinaryContent content = catalogFramework.transform(metacard, "xml", null);
                StringWriter writer = new StringWriter();
                IOUtils.copy(content.getInputStream(), writer, "UTF8");
                LOGGER.debug("Formatting xml for metacard with id [{}].", metacard.getId());
                responseString.append(format(writer.toString()));
            }
        } else {
            String message = "The query for " + filter.toString() + " returned a null result.";
            responseString.append(message);
            LOGGER.warn(message);
        }
    } catch (SourceUnavailableException e) {
        LOGGER.error(queryError, e);
    } catch (UnsupportedQueryException e) {
        LOGGER.error(queryError, e);
    } catch (FederationException e) {
        LOGGER.error(queryError, e);
    } catch (CatalogTransformerException e) {
        LOGGER.error(queryError, e);
    } catch (IOException e) {
        LOGGER.error(queryError, e);
    }
    return responseString.toString();
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SecurityServiceException(ddf.security.service.SecurityServiceException) QueryRequest(ddf.catalog.operation.QueryRequest) CasAuthenticationToken(ddf.security.service.impl.cas.CasAuthenticationToken) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) BinaryContent(ddf.catalog.data.BinaryContent) FederationException(ddf.catalog.federation.FederationException) Subject(ddf.security.Subject) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) StringWriter(java.io.StringWriter) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse)

Example 64 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class MetacardsMigratableTest method exportWhenProviderQueryFails.

@Test(expected = RuntimeException.class)
public void exportWhenProviderQueryFails() throws Exception {
    when(mockFramework.query(any())).thenThrow(new UnsupportedQueryException(""));
    MetacardsMigratable migratable = new MetacardsMigratable(DESCRIBABLE_BEAN, mockFramework, mockFilterBuilder, mockFileWriter, config, mockTaskManager);
    migratable.export(EXPORT_PATH);
}
Also used : UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Test(org.junit.Test)

Example 65 with UnsupportedQueryException

use of ddf.catalog.source.UnsupportedQueryException in project ddf by codice.

the class CatalogFrameworkImplTest method createDummyCatalogFramework.

private CatalogFramework createDummyCatalogFramework(CatalogProvider provider, Map<String, CatalogStore> stores, Map<String, FederatedSource> sources, MockEventProcessor eventAdmin) {
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
    FederationStrategy federationStrategy = new FederationStrategy() {

        @Override
        public QueryResponse federate(List<Source> sources, QueryRequest query) throws FederationException {
            List<Result> results = new ArrayList<>();
            for (Source source : sources) {
                try {
                    SourceResponse response = source.query(query);
                    results.addAll(response.getResults());
                } catch (UnsupportedQueryException e) {
                }
            }
            return new QueryResponseImpl(query, results, results.size());
        }
    };
    ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<>();
    postIngestPlugins.add(eventAdmin);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setCatalogStoresMap(stores);
    frameworkProperties.setSourcePoller(mockPoller);
    frameworkProperties.setPreIngest(new ArrayList<>());
    frameworkProperties.setPostIngest(postIngestPlugins);
    frameworkProperties.setPreQuery(new ArrayList<>());
    frameworkProperties.setPostQuery(new ArrayList<>());
    frameworkProperties.setPolicyPlugins(new ArrayList<>());
    frameworkProperties.setAccessPlugins(new ArrayList<>());
    frameworkProperties.setFederatedSources(sources);
    frameworkProperties.setConnectedSources(new ArrayList<>());
    frameworkProperties.setFederationStrategy(federationStrategy);
    frameworkProperties.setQueryResponsePostProcessor(new QueryResponsePostProcessor(null, null));
    frameworkProperties.setFilterBuilder(new GeotoolsFilterBuilder());
    frameworkProperties.setValidationQueryFactory(new ValidationQueryFactory(new GeotoolsFilterAdapterImpl(), new GeotoolsFilterBuilder()));
    frameworkProperties.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
    return createFramework(frameworkProperties);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) FederationStrategy(ddf.catalog.federation.FederationStrategy) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) ValidationQueryFactory(ddf.catalog.cache.solr.impl.ValidationQueryFactory) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) SourcePoller(ddf.catalog.util.impl.SourcePoller) Result(ddf.catalog.data.Result) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)

Aggregations

UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)85 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)34 FederationException (ddf.catalog.federation.FederationException)31 QueryRequest (ddf.catalog.operation.QueryRequest)31 Metacard (ddf.catalog.data.Metacard)28 QueryImpl (ddf.catalog.operation.impl.QueryImpl)27 Filter (org.opengis.filter.Filter)27 ArrayList (java.util.ArrayList)26 Result (ddf.catalog.data.Result)25 QueryResponse (ddf.catalog.operation.QueryResponse)25 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)25 Test (org.junit.Test)21 SourceResponse (ddf.catalog.operation.SourceResponse)16 IngestException (ddf.catalog.source.IngestException)15 IOException (java.io.IOException)15 Query (ddf.catalog.operation.Query)12 CreateResponse (ddf.catalog.operation.CreateResponse)10 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)9 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)9 Subject (ddf.security.Subject)9