Search in sources :

Example 96 with QueryResponse

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

the class GeoNamesCatalogIndexer method removeGeoNamesMetacardsFromCatalog.

private void removeGeoNamesMetacardsFromCatalog(String resource, ProgressCallback extractionCallback) throws UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
    extractionCallback.updateProgress(0);
    Optional<CatalogProvider> catalogProviderOptional = catalogProviders.stream().findFirst();
    if (catalogProviderOptional.isPresent()) {
        CatalogProvider catalogProvider = catalogProviderOptional.get();
        if (StringUtils.isNotBlank(resource)) {
            filter = filterBuilder.allOf(filterBuilder.attribute(GeoEntryAttributes.IMPORT_LOCATION).is().equalTo().text(resource), filter);
        }
        while (true) {
            Query query = new QueryImpl(filter, 1, BATCH_SIZE, SortBy.NATURAL_ORDER, false, TimeUnit.SECONDS.toMillis(90));
            QueryRequest queryRequest = new QueryRequestImpl(query);
            LOGGER.trace("Removing existing geonames data with filter: {}", filter);
            QueryResponse response = catalogFramework.query(queryRequest);
            List<Serializable> metacardsToDelete = response.getResults().stream().map(Result::getMetacard).map(Metacard::getId).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(metacardsToDelete)) {
                break;
            }
            LOGGER.trace("Deleting {} GeoNames metacards", metacardsToDelete.size());
            removeMetacards(catalogProvider, extractionCallback, metacardsToDelete);
        }
    }
    extractionCallback.updateProgress(50);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Result(ddf.catalog.data.Result)

Example 97 with QueryResponse

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

the class CswEndpointTest method getQueryResponseBatch.

private List<QueryResponse> getQueryResponseBatch(int batchSize, int total) {
    Queue<Result> results = new ArrayDeque<>();
    for (int i = 1; i <= total; i++) {
        MetacardImpl metacard = new MetacardImpl();
        metacard.setId(i + "");
        results.add(new ResultImpl(metacard));
    }
    List<QueryResponse> queryResponses = new ArrayList<>();
    while (!results.isEmpty()) {
        List<Result> batchList = new ArrayList<>();
        for (int i = 0; i < batchSize; i++) {
            Result result = results.poll();
            if (result == null) {
                break;
            }
            batchList.add(result);
        }
        queryResponses.add(new QueryResponseImpl(null, batchList, total));
    }
    // Add one empty response list to the end
    queryResponses.add(new QueryResponseImpl(null, Collections.emptyList(), 0));
    return queryResponses;
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ArrayDeque(java.util.ArrayDeque) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

Example 98 with QueryResponse

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

the class CswEndpointTest method testDeleteBatching.

@Test
public void testDeleteBatching() throws Exception {
    // configure query responses
    queryResponseBatch = getQueryResponseBatch(500, 800);
    QueryResponse[] qrRest = queryResponseBatch.subList(1, queryResponseBatch.size()).toArray(new QueryResponse[0]);
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponseBatch.get(0), qrRest);
    // configure delete responses
    DeleteType deleteType = mock(DeleteType.class);
    doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
    doReturn("").when(deleteType).getHandle();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("title = \"foo\"");
    doReturn(queryConstraintType).when(deleteType).getConstraint();
    when(deleteResponse.getDeletedMetacards()).thenReturn(populateMetacardList(1));
    when(catalogFramework.delete(any(DeleteRequest.class))).thenAnswer((Answer<DeleteResponse>) invocation -> deleteResponse);
    DeleteAction deleteAction = new DeleteActionImpl(deleteType, DefaultCswRecordMap.getPrefixToUriMapping());
    CswTransactionRequest deleteRequest = new CswTransactionRequest();
    deleteRequest.getDeleteActions().add(deleteAction);
    TransactionResponseType response = csw.transaction(deleteRequest);
    assertThat(response.getTransactionSummary().getTotalDeleted().intValue(), equalTo(800));
    verify(catalogFramework, times(4)).query(any());
    verify(catalogFramework, times(800)).delete(any());
}
Also used : UpdateActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateActionImpl) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CreateRequest(ddf.catalog.operation.CreateRequest) Matchers.hasItems(org.hamcrest.Matchers.hasItems) MediaType(javax.ws.rs.core.MediaType) ServiceIdentification(net.opengis.ows.v_1_0_0.ServiceIdentification) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ComparisonOperatorType(net.opengis.filter.v_1_1_0.ComparisonOperatorType) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) Mockito.doReturn(org.mockito.Mockito.doReturn) ServiceReference(org.osgi.framework.ServiceReference) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Serializable(java.io.Serializable) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) ParseException(org.locationtech.jts.io.ParseException) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) Matchers.is(org.hamcrest.Matchers.is) CswConstants(org.codice.ddf.spatial.ogc.csw.catalog.common.CswConstants) UpdateResponse(ddf.catalog.operation.UpdateResponse) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) CswRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRequest) Mockito.mock(org.mockito.Mockito.mock) ResourceResponse(ddf.catalog.operation.ResourceResponse) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) Iterables(com.google.common.collect.Iterables) DescribeRecordRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.DescribeRecordRequest) DefaultCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.common.converter.DefaultCswRecordMap) CatalogFramework(ddf.catalog.CatalogFramework) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) Resource(ddf.catalog.resource.Resource) ArrayList(java.util.ArrayList) UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Answer(org.mockito.stubbing.Answer) Subject(org.apache.shiro.subject.Subject) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) QueryRequest(ddf.catalog.operation.QueryRequest) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CswActionTransformerProvider(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswActionTransformerProvider) Result(ddf.catalog.data.Result) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) IngestException(ddf.catalog.source.IngestException) StringWriter(java.io.StringWriter) JAXBElement(javax.xml.bind.JAXBElement) ServiceProvider(net.opengis.ows.v_1_0_0.ServiceProvider) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) FederationException(ddf.catalog.federation.FederationException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Query(ddf.catalog.operation.Query) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Matchers.hasItem(org.hamcrest.Matchers.hasItem) GetRecordsRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest) ArrayDeque(java.util.ArrayDeque) Mockito.reset(org.mockito.Mockito.reset) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QueryFilterTransformer(ddf.catalog.transform.QueryFilterTransformer) URL(java.net.URL) DescribeRecordResponseType(net.opengis.cat.csw.v_2_0_2.DescribeRecordResponseType) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) SectionsType(net.opengis.ows.v_1_0_0.SectionsType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) InsertActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertActionImpl) Assert.fail(org.junit.Assert.fail) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) URI(java.net.URI) DeleteActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl) Bundle(org.osgi.framework.Bundle) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Collection(java.util.Collection) GetRecordByIdType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdType) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ResultImpl(ddf.catalog.data.impl.ResultImpl) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) BundleContext(org.osgi.framework.BundleContext) DeleteRequest(ddf.catalog.operation.DeleteRequest) Objects(java.util.Objects) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Operation(net.opengis.ows.v_1_0_0.Operation) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Queue(java.util.Queue) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) DescribeRecordType(net.opengis.cat.csw.v_2_0_2.DescribeRecordType) ResultType(net.opengis.cat.csw.v_2_0_2.ResultType) Update(ddf.catalog.operation.Update) SchemaComponentType(net.opengis.cat.csw.v_2_0_2.SchemaComponentType) HashSet(java.util.HashSet) GetCapabilitiesType(net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType) SortBy(org.opengis.filter.sort.SortBy) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) OperationsMetadata(net.opengis.ows.v_1_0_0.OperationsMetadata) Metacard(ddf.catalog.data.Metacard) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) MimeType(javax.activation.MimeType) UpdateRequest(ddf.catalog.operation.UpdateRequest) GmdConstants(org.codice.ddf.spatial.ogc.csw.catalog.common.GmdConstants) LinkedList(java.util.LinkedList) DomainType(net.opengis.ows.v_1_0_0.DomainType) JAXBContext(javax.xml.bind.JAXBContext) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Matchers.empty(org.hamcrest.Matchers.empty) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) Logger(org.slf4j.Logger) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) Collectors.toList(java.util.stream.Collectors.toList) SourceResponse(ddf.catalog.operation.SourceResponse) ThreadContext(org.apache.shiro.util.ThreadContext) AcceptVersionsType(net.opengis.ows.v_1_0_0.AcceptVersionsType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Collections(java.util.Collections) DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) DeleteActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 99 with QueryResponse

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

the class CswEndpoint method queryCsw.

private CswRecordCollection queryCsw(GetRecordsType request) throws CswException {
    if (LOGGER.isDebugEnabled()) {
        try {
            Writer writer = new StringWriter();
            try {
                Marshaller marshaller = CswQueryFactory.getJaxBContext().createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                JAXBElement<GetRecordsType> jaxbElement = new ObjectFactory().createGetRecords(request);
                marshaller.marshal(jaxbElement, writer);
            } catch (JAXBException e) {
                LOGGER.debug("Unable to marshall {} to XML", GetRecordsType.class, e);
            }
            LOGGER.debug(writer.toString());
        } catch (Exception e) {
            LOGGER.debug("Unable to create debug message for getRecordsType", e);
        }
    }
    QueryType query = (QueryType) request.getAbstractQuery().getValue();
    CswRecordCollection response = new CswRecordCollection();
    response.setRequest(request);
    response.setOutputSchema(request.getOutputSchema());
    response.setMimeType(request.getOutputFormat());
    response.setElementName(query.getElementName());
    response.setElementSetType((query.getElementSetName() != null) ? query.getElementSetName().getValue() : null);
    response.setResultType((ResultType) ObjectUtils.defaultIfNull(request.getResultType(), ResultType.HITS));
    if (ResultType.HITS.equals(request.getResultType()) || ResultType.RESULTS.equals(request.getResultType())) {
        QueryRequest queryRequest = queryFactory.getQuery(request);
        try {
            queryRequest = queryFactory.updateQueryRequestTags(queryRequest, request.getOutputSchema());
            LOGGER.debug("Attempting to execute paged query: {}", queryRequest);
            AtomicLong hitCount = new AtomicLong(0);
            QueryFunction qf = qr -> {
                SourceResponse sr = framework.query(qr);
                hitCount.compareAndSet(0, sr.getHits());
                return sr;
            };
            ResultIterable results = ResultIterable.resultIterable(qf, queryRequest, request.getMaxRecords().intValue());
            List<Result> resultList = results.stream().collect(Collectors.toList());
            // The hitCount Atomic is used here instead of just defaulting
            // to the size of the resultList because the size of the resultList
            // can be limited to request.getMaxRecords().intValue() which would
            // lead to an incorrect response for hits.
            // hitCount is set within the QueryFunction and will correspond to
            // all responses.
            long totalHits = hitCount.get();
            totalHits = totalHits != 0 ? totalHits : resultList.size();
            QueryResponse queryResponse = new QueryResponseImpl(queryRequest, resultList, totalHits);
            response.setSourceResponse(queryResponse);
        } catch (UnsupportedQueryException | CatalogQueryException e) {
            LOGGER.debug("Unable to query", e);
            throw new CswException(e);
        }
    }
    return response;
}
Also used : ScalarCapabilitiesType(net.opengis.filter.v_1_1_0.ScalarCapabilitiesType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) WKTReader(org.locationtech.jts.io.WKTReader) CreateRequest(ddf.catalog.operation.CreateRequest) Produces(javax.ws.rs.Produces) XMLUtils(org.codice.ddf.platform.util.XMLUtils) SpatialOperatorsType(net.opengis.filter.v_1_1_0.SpatialOperatorsType) RequestMethodType(net.opengis.ows.v_1_0_0.RequestMethodType) Future(java.util.concurrent.Future) MediaType(javax.ws.rs.core.MediaType) ServiceIdentification(net.opengis.ows.v_1_0_0.ServiceIdentification) Document(org.w3c.dom.Document) Map(java.util.Map) HeaderParam(javax.ws.rs.HeaderParam) BigInteger(java.math.BigInteger) ComparisonOperatorType(net.opengis.filter.v_1_1_0.ComparisonOperatorType) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) ServiceReference(org.osgi.framework.ServiceReference) HTTP(net.opengis.ows.v_1_0_0.HTTP) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) CancellationException(java.util.concurrent.CancellationException) StandardThreadFactoryBuilder(org.codice.ddf.platform.util.StandardThreadFactoryBuilder) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) Set(java.util.Set) LogicalOperators(net.opengis.filter.v_1_1_0.LogicalOperators) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Serializable(java.io.Serializable) MimeTypeParseException(javax.activation.MimeTypeParseException) Stream(java.util.stream.Stream) ParseException(org.locationtech.jts.io.ParseException) SpatialCapabilitiesType(net.opengis.filter.v_1_1_0.SpatialCapabilitiesType) CswConstants(org.codice.ddf.spatial.ogc.csw.catalog.common.CswConstants) UpdateResponse(ddf.catalog.operation.UpdateResponse) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) SecurityUtils(org.apache.shiro.SecurityUtils) CswRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRequest) ResourceResponse(ddf.catalog.operation.ResourceResponse) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) Iterables(com.google.common.collect.Iterables) ResultIterable(ddf.catalog.util.impl.ResultIterable) GeometryOperandsType(net.opengis.filter.v_1_1_0.GeometryOperandsType) DescribeRecordRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.DescribeRecordRequest) GET(javax.ws.rs.GET) CatalogFramework(ddf.catalog.CatalogFramework) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ResponsiblePartySubsetType(net.opengis.ows.v_1_0_0.ResponsiblePartySubsetType) DeleteResponse(ddf.catalog.operation.DeleteResponse) Callable(java.util.concurrent.Callable) Resource(ddf.catalog.resource.Resource) ArrayList(java.util.ArrayList) IdCapabilitiesType(net.opengis.filter.v_1_1_0.IdCapabilitiesType) Subject(org.apache.shiro.subject.Subject) DCP(net.opengis.ows.v_1_0_0.DCP) EID(net.opengis.filter.v_1_1_0.EID) CodeType(net.opengis.ows.v_1_0_0.CodeType) QueryRequest(ddf.catalog.operation.QueryRequest) CswActionTransformerProvider(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswActionTransformerProvider) Result(ddf.catalog.data.Result) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) IngestException(ddf.catalog.source.IngestException) StringWriter(java.io.StringWriter) JAXBElement(javax.xml.bind.JAXBElement) ServiceProvider(net.opengis.ows.v_1_0_0.ServiceProvider) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Paths(java.nio.file.Paths) DocumentBuilder(javax.xml.parsers.DocumentBuilder) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) InsertResultType(net.opengis.cat.csw.v_2_0_2.InsertResultType) GetRecordsRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction) QueryFilterTransformer(ddf.catalog.transform.QueryFilterTransformer) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) URL(java.net.URL) DescribeRecordResponseType(net.opengis.cat.csw.v_2_0_2.DescribeRecordResponseType) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) CompletionService(java.util.concurrent.CompletionService) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) LogSanitizer(org.codice.ddf.log.sanitizer.LogSanitizer) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) Bundle(org.osgi.framework.Bundle) Splitter(com.google.common.base.Splitter) CatalogQueryException(ddf.catalog.util.impl.CatalogQueryException) Context(javax.ws.rs.core.Context) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) OnlineResourceType(net.opengis.ows.v_1_0_0.OnlineResourceType) Collection(java.util.Collection) GetRecordByIdType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdType) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) ObjectUtils(org.apache.commons.lang.ObjectUtils) BundleContext(org.osgi.framework.BundleContext) Objects(java.util.Objects) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Attribute(ddf.catalog.data.Attribute) Operation(net.opengis.ows.v_1_0_0.Operation) SAXException(org.xml.sax.SAXException) Writer(java.io.Writer) Entry(java.util.Map.Entry) Optional(java.util.Optional) Geometry(org.locationtech.jts.geom.Geometry) ComparisonOperatorsType(net.opengis.filter.v_1_1_0.ComparisonOperatorsType) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral) Marshaller(javax.xml.bind.Marshaller) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) DescribeRecordType(net.opengis.cat.csw.v_2_0_2.DescribeRecordType) ResultType(net.opengis.cat.csw.v_2_0_2.ResultType) Function(java.util.function.Function) SchemaComponentType(net.opengis.cat.csw.v_2_0_2.SchemaComponentType) HashSet(java.util.HashSet) GetCapabilitiesType(net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType) CreateResponse(ddf.catalog.operation.CreateResponse) OperationsMetadata(net.opengis.ows.v_1_0_0.OperationsMetadata) Metacard(ddf.catalog.data.Metacard) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) MimeType(javax.activation.MimeType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) LinkedList(java.util.LinkedList) SpatialOperatorNameType(net.opengis.filter.v_1_1_0.SpatialOperatorNameType) DomainType(net.opengis.ows.v_1_0_0.DomainType) BoundingBoxType(net.opengis.ows.v_1_0_0.BoundingBoxType) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) TimeUnit(java.util.concurrent.TimeUnit) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) SourceResponse(ddf.catalog.operation.SourceResponse) QueryFunction(ddf.catalog.util.impl.QueryFunction) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Collections(java.util.Collections) Envelope(org.locationtech.jts.geom.Envelope) FrameworkUtil(org.osgi.framework.FrameworkUtil) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Result(ddf.catalog.data.Result) StringWriter(java.io.StringWriter) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) Marshaller(javax.xml.bind.Marshaller) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) JAXBException(javax.xml.bind.JAXBException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ResultIterable(ddf.catalog.util.impl.ResultIterable) CancellationException(java.util.concurrent.CancellationException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) MimeTypeParseException(javax.activation.MimeTypeParseException) ParseException(org.locationtech.jts.io.ParseException) IngestException(ddf.catalog.source.IngestException) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CatalogQueryException(ddf.catalog.util.impl.CatalogQueryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryFunction(ddf.catalog.util.impl.QueryFunction) QueryResponse(ddf.catalog.operation.QueryResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) CatalogQueryException(ddf.catalog.util.impl.CatalogQueryException) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 100 with QueryResponse

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

the class CswEndpoint method queryById.

private CswRecordCollection queryById(List<String> ids, String outputSchema) throws CswException {
    QueryRequest queryRequest = queryFactory.getQueryById(ids);
    try {
        CswRecordCollection response = new CswRecordCollection();
        response.setById(true);
        queryRequest = queryFactory.updateQueryRequestTags(queryRequest, outputSchema);
        QueryResponse queryResponse = framework.query(queryRequest);
        response.setSourceResponse(queryResponse);
        List<Metacard> metacards = new LinkedList<>();
        for (Result result : queryResponse.getResults()) {
            metacards.add(result.getMetacard());
        }
        response.setCswRecords(metacards);
        return response;
    } catch (FederationException | SourceUnavailableException | UnsupportedQueryException e) {
        throw new CswException(e);
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) FederationException(ddf.catalog.federation.FederationException) LinkedList(java.util.LinkedList) 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