Search in sources :

Example 26 with SourceResponse

use of ddf.catalog.operation.SourceResponse 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 27 with SourceResponse

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

the class RegistryStoreImpl method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    //This is a registry store so only allow registry requests through
    if (!filterAdapter.adapt(request.getQuery(), new TagsFilterDelegate(ImmutableSet.of(RegistryConstants.REGISTRY_TAG, RegistryConstants.REGISTRY_TAG_INTERNAL), true))) {
        return new SourceResponseImpl(request, Collections.emptyList());
    }
    SourceResponse registryQueryResponse = super.query(request);
    for (Result singleResult : registryQueryResponse.getResults()) {
        if (registryId.equals(RegistryUtility.getRegistryId(singleResult.getMetacard()))) {
            String metacardTitle = singleResult.getMetacard().getTitle();
            if (metacardTitle != null && getId() != null && !getId().equals(getFullRegistryName(metacardTitle))) {
                setId(metacardTitle);
                updateConfiguration(metacardTitle);
            }
            break;
        }
    }
    return registryQueryResponse;
}
Also used : TagsFilterDelegate(ddf.catalog.filter.delegate.TagsFilterDelegate) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) Result(ddf.catalog.data.Result)

Example 28 with SourceResponse

use of ddf.catalog.operation.SourceResponse 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 29 with SourceResponse

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

the class TestWfsSource method testPagingStartIndexOne.

/**
     * Given 10 features (and metacards) exist that match search criteria, since page size=4 and
     * startIndex=1, should get 4 results back - metacards 1 thru 4.
     *
     * @throws WfsException
     * @throws SecurityServiceException
     * @throws TransformerConfigurationException
     * @throws UnsupportedQueryException
     */
@Test
public void testPagingStartIndexOne() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    int pageSize = 4;
    int startIndex = 1;
    setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, MAX_FEATURES, null);
    SourceResponse response = executeQuery(startIndex, pageSize);
    List<Result> results = response.getResults();
    assertThat(results.size(), is(pageSize));
    assertThat(response.getHits(), equalTo(new Long(MAX_FEATURES)));
    // Verify that metacards 1 thru 4 were returned since pageSize=4
    assertCorrectMetacardsReturned(results, startIndex, pageSize);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 30 with SourceResponse

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

the class TestWfsSource method testPagingPageSizeExceedsFeatureCountStartIndexOne.

/**
     * Given 10 features (and metacards) exist that match search criteria, since page size=20 (which
     * is larger than number of features) and startIndex=1, should get 10 results back - metacards 1
     * thru 10.
     *
     * @throws WfsException,                     SecurityServiceException
     * @throws TransformerConfigurationException
     * @throws UnsupportedQueryException
     */
@Test
public void testPagingPageSizeExceedsFeatureCountStartIndexOne() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    int pageSize = 20;
    int startIndex = 1;
    setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, MAX_FEATURES, null);
    SourceResponse response = executeQuery(startIndex, pageSize);
    List<Result> results = response.getResults();
    assertThat(results.size(), is(MAX_FEATURES));
    assertThat(response.getHits(), equalTo(new Long(MAX_FEATURES)));
    // Verify that metacards 1 thru 10 were returned
    assertCorrectMetacardsReturned(results, startIndex, MAX_FEATURES);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

SourceResponse (ddf.catalog.operation.SourceResponse)199 Test (org.junit.Test)146 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)99 QueryImpl (ddf.catalog.operation.impl.QueryImpl)95 Result (ddf.catalog.data.Result)79 Metacard (ddf.catalog.data.Metacard)73 Filter (org.opengis.filter.Filter)58 QueryRequest (ddf.catalog.operation.QueryRequest)52 BinaryContent (ddf.catalog.data.BinaryContent)40 ResultImpl (ddf.catalog.data.impl.ResultImpl)29 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)25 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)24 Matchers.containsString (org.hamcrest.Matchers.containsString)24 Matchers.anyString (org.mockito.Matchers.anyString)21 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 Serializable (java.io.Serializable)20 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)19 SortByImpl (ddf.catalog.filter.impl.SortByImpl)18 Map (java.util.Map)16