Search in sources :

Example 1 with QueryRequest

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

the class CswEndpoint method updateRecords.

private int updateRecords(UpdateAction updateAction) throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    if (updateAction.getMetacard() != null) {
        Metacard newRecord = updateAction.getMetacard();
        if (newRecord.getId() != null) {
            UpdateRequest updateRequest = new UpdateRequestImpl(newRecord.getId(), newRecord);
            LOGGER.debug("Attempting to update {} ", newRecord.getId());
            UpdateResponse updateResponse = framework.update(updateRequest);
            return updateResponse.getUpdatedMetacards().size();
        } else {
            throw new CswException("Unable to update record.  No ID was specified in the request.", CswConstants.MISSING_PARAMETER_VALUE, updateAction.getHandle());
        }
    } else if (updateAction.getConstraint() != null) {
        QueryConstraintType constraint = updateAction.getConstraint();
        QueryRequest queryRequest = queryFactory.getQuery(constraint);
        queryRequest = queryFactory.updateQueryRequestTags(queryRequest, schemaTransformerManager.getTransformerSchemaForId(updateAction.getTypeName()));
        QueryResponse response = framework.query(queryRequest);
        if (response.getHits() > 0) {
            Map<String, Serializable> recordProperties = updateAction.getRecordProperties();
            List<String> updatedMetacardIdsList = new ArrayList<>();
            List<Metacard> updatedMetacards = new ArrayList<>();
            for (Result result : response.getResults()) {
                Metacard metacard = result.getMetacard();
                if (metacard != null) {
                    for (Entry<String, Serializable> recordProperty : recordProperties.entrySet()) {
                        Attribute attribute = new AttributeImpl(recordProperty.getKey(), recordProperty.getValue());
                        metacard.setAttribute(attribute);
                    }
                    updatedMetacardIdsList.add(metacard.getId());
                    updatedMetacards.add(metacard);
                }
            }
            if (updatedMetacardIdsList.size() > 0) {
                String[] updatedMetacardIds = updatedMetacardIdsList.toArray(new String[updatedMetacardIdsList.size()]);
                UpdateRequest updateRequest = new UpdateRequestImpl(updatedMetacardIds, updatedMetacards);
                LOGGER.debug("Attempting to update {} metacards.", updatedMetacardIdsList.size());
                UpdateResponse updateResponse = framework.update(updateRequest);
                return updateResponse.getUpdatedMetacards().size();
            }
        }
    }
    return 0;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) Attribute(ddf.catalog.data.Attribute) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Result(ddf.catalog.data.Result) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) Entry(java.util.Map.Entry) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with QueryRequest

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

the class TestRegistryStore method testNonRegistryQuery.

@Test
public void testNonRegistryQuery() throws Exception {
    Filter filter = filterBuilder.attribute(RegistryObjectMetacardType.REGISTRY_ID).is().like().text("registryId");
    QueryRequest testRequest = new QueryRequestImpl(new QueryImpl(filter));
    queryResults.add(new ResultImpl(getDefaultMetacard()));
    SourceResponse answer = registryStore.query(testRequest);
    List<Result> testResults = answer.getResults();
    assertThat(testResults.size(), is(0));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 3 with QueryRequest

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

the class TestRegistryStore method testInit.

@Test
public void testInit() throws Exception {
    RegistryStoreImpl registryStore = spy(new RegistryStoreImpl(context, cswSourceConfiguration, provider, factory, encryptionService) {

        @Override
        protected void validateOperation() {
        }

        @Override
        public boolean isAvailable() {
            return availability;
        }

        @Override
        protected SourceResponse query(QueryRequest queryRequest, ElementSetType elementSetName, List<QName> elementNames, Csw csw) throws UnsupportedQueryException {
            if (queryResults == null) {
                throw new UnsupportedQueryException("Test - Bad Query");
            }
            return new SourceResponseImpl(queryRequest, queryResults);
        }

        @Override
        public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
            return new SourceResponseImpl(request, Collections.singletonList(new Result() {

                @Override
                public Metacard getMetacard() {
                    MetacardImpl metacard = new MetacardImpl();
                    metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "registryId");
                    metacard.setAttribute(Metacard.TITLE, "title");
                    return metacard;
                }

                @Override
                public Double getRelevanceScore() {
                    return null;
                }

                @Override
                public Double getDistanceInMeters() {
                    return null;
                }
            }));
        }

        @Override
        protected CapabilitiesType getCapabilities() {
            return mock(CapabilitiesType.class);
        }

        @Override
        public void configureCswSource() {
        }

        ;

        @Override
        protected Subject getSystemSubject() {
            return subject;
        }

        @Override
        BundleContext getBundleContext() {
            return context;
        }
    });
    registryStore.setFilterBuilder(filterBuilder);
    registryStore.setFilterAdapter(filterAdapter);
    registryStore.setConfigAdmin(configAdmin);
    registryStore.setMetacardMarshaller(new MetacardMarshaller(parser));
    registryStore.setSchemaTransformerManager(transformer);
    registryStore.setAutoPush(true);
    registryStore.setRegistryUrl("http://test.url:0101/example");
    properties = new Hashtable<>();
    properties.put(RegistryStoreImpl.ID, "registryId");
    registryStore.setMetacardMarshaller(marshaller);
    Csw csw = mock(Csw.class);
    when(factory.getClientForSubject(any())).thenReturn(csw);
    cswSourceConfiguration.setCswUrl("https://localhost");
    cswSourceConfiguration.setPollIntervalMinutes(1);
    queryResults.add(new ResultImpl(getDefaultMetacard()));
    registryStore.init();
    assertThat(registryStore.getRegistryId(), is("registryId"));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) QName(javax.xml.namespace.QName) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Subject(ddf.security.Subject) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 4 with QueryRequest

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

the class TestRegistryStore method testRegistryQuery.

@Test
public void testRegistryQuery() throws Exception {
    Filter filter = filterBuilder.attribute(Metacard.TAGS).is().like().text(RegistryConstants.REGISTRY_TAG);
    queryResults.add(new ResultImpl(getDefaultMetacard()));
    QueryRequest testRequest = new QueryRequestImpl(new QueryImpl(filter));
    SourceResponse answer = registryStore.query(testRequest);
    List<Result> testResults = answer.getResults();
    assertThat(testResults.size(), is(1));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 5 with QueryRequest

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

the class TestWfsSource method executeQuery.

private SourceResponse executeQuery(int startIndex, int pageSize) throws UnsupportedQueryException {
    Filter filter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL);
    Query query = new QueryImpl(filter, startIndex, pageSize, null, false, 0);
    QueryRequest request = new QueryRequestImpl(query);
    SourceResponse response = source.query(request);
    return response;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Aggregations

QueryRequest (ddf.catalog.operation.QueryRequest)275 Test (org.junit.Test)185 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)145 QueryImpl (ddf.catalog.operation.impl.QueryImpl)117 QueryResponse (ddf.catalog.operation.QueryResponse)75 SourceResponse (ddf.catalog.operation.SourceResponse)70 Query (ddf.catalog.operation.Query)67 ArrayList (java.util.ArrayList)64 Filter (org.opengis.filter.Filter)60 Result (ddf.catalog.data.Result)52 Metacard (ddf.catalog.data.Metacard)44 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)44 Source (ddf.catalog.source.Source)37 HashMap (java.util.HashMap)30 FederationException (ddf.catalog.federation.FederationException)29 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)28 SortBy (org.opengis.filter.sort.SortBy)28 Serializable (java.io.Serializable)26 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)25 Map (java.util.Map)25