Search in sources :

Example 11 with Result

use of ddf.catalog.data.Result in project ddf by codice.

the class TestAtomTransformer method basicSetup.

protected SourceResponse basicSetup(AtomTransformer transformer) throws IOException, CatalogTransformerException {
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response = mock(SourceResponse.class);
    when(response.getRequest()).thenReturn(getStubRequest());
    ResultImpl result = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    metacard.setSourceId(SAMPLE_SOURCE_ID);
    result.setMetacard(metacard);
    when(response.getResults()).thenReturn(Arrays.asList((Result) result));
    return response;
}
Also used : MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) ResultImpl(ddf.catalog.data.impl.ResultImpl) Result(ddf.catalog.data.Result)

Example 12 with Result

use of ddf.catalog.data.Result in project ddf by codice.

the class TestAtomTransformer method testTotalResultsNegative.

@Test
public void testTotalResultsNegative() throws IOException, CatalogTransformerException, XpathException, SAXException {
    // given
    AtomTransformer transformer = new AtomTransformer();
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response = mock(SourceResponse.class);
    when(response.getHits()).thenReturn(new Long(-1));
    QueryImpl query = new QueryImpl(FILTER_BUILDER.attribute(Metacard.METADATA).text("you"));
    query.setPageSize(1);
    query.setStartIndex(2);
    query.setRequestsTotalResultsCount(true);
    QueryRequestImpl queryRequestImpl = new QueryRequestImpl(query);
    when(response.getRequest()).thenReturn(queryRequestImpl);
    ResultImpl result1 = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    result1.setMetacard(metacard);
    when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
    byte[] bytes = binaryContent.getByteArray();
    String output = new String(bytes);
    assertFeedCompliant(output);
    assertEntryCompliant(output);
    validateAgainstAtomSchema(bytes);
    assertXpathNotExists("/atom:feed/os:totalResults", output);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 13 with Result

use of ddf.catalog.data.Result 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 14 with Result

use of ddf.catalog.data.Result 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 15 with Result

use of ddf.catalog.data.Result 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)

Aggregations

Result (ddf.catalog.data.Result)361 Test (org.junit.Test)205 Metacard (ddf.catalog.data.Metacard)159 SourceResponse (ddf.catalog.operation.SourceResponse)153 ArrayList (java.util.ArrayList)137 ResultImpl (ddf.catalog.data.impl.ResultImpl)120 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)119 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)102 QueryImpl (ddf.catalog.operation.impl.QueryImpl)91 Filter (org.opengis.filter.Filter)91 QueryResponse (ddf.catalog.operation.QueryResponse)87 QueryRequest (ddf.catalog.operation.QueryRequest)84 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)50 Serializable (java.io.Serializable)50 BinaryContent (ddf.catalog.data.BinaryContent)48 HashMap (java.util.HashMap)45 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)43 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)39 Map (java.util.Map)36 DateTime (org.joda.time.DateTime)33