Search in sources :

Example 26 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class SortedQueryMonitor method executePostFederationQueryPluginsWithSourceError.

private void executePostFederationQueryPluginsWithSourceError(QueryRequest queryRequest, String sourceId, Exception e, Set<ProcessingDetails> processingDetails) {
    ProcessingDetails processingDetail = new ProcessingDetailsImpl(sourceId, e);
    SourceResponse sourceResponse = new SourceResponseImpl(queryRequest, new ArrayList<>());
    sourceResponse.getProcessingErrors().add(processingDetail);
    processingDetails.add(processingDetail);
    executePostFederationQueryPlugins(sourceResponse, queryRequest);
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl)

Example 27 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class TestCswQueryResponseTransformer method createSourceResponse.

private SourceResponse createSourceResponse(GetRecordsType request, int resultCount) {
    int first = 1;
    int last = 2;
    int max = 0;
    if (request != null) {
        first = request.getStartPosition().intValue();
        max = request.getMaxRecords().intValue();
        int next = request.getMaxRecords().intValue() + first;
        last = next - 1;
        if (last >= resultCount) {
            last = resultCount;
        }
    }
    QueryImpl query = new QueryImpl(filter, first, max, null, true, 0);
    SourceResponseImpl sourceResponse = new SourceResponseImpl(new QueryRequestImpl(query), createResults(first, last));
    sourceResponse.setHits(resultCount);
    return sourceResponse;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Example 28 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testPostQueryStopExecution.

@Test(expected = FederationException.class)
public void testPostQueryStopExecution() throws UnsupportedQueryException, FederationException, SourceUnavailableException {
    SourcePoller poller = mock(SourcePoller.class);
    when(poller.getCachedSource(isA(Source.class))).thenReturn(null);
    BundleContext context = null;
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "goodyear", "*", "?", "/", false);
    QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
    SourceResponseImpl sourceResponse = new SourceResponseImpl(request, new ArrayList<Result>());
    QueryResponseImpl queryResponse = new QueryResponseImpl(sourceResponse, "anyId");
    CatalogProvider provider = mock(CatalogProvider.class);
    when(provider.query(isA(QueryRequest.class))).thenReturn(sourceResponse);
    FederationStrategy federationStrategy = mock(FederationStrategy.class);
    when(federationStrategy.federate(isA(List.class), isA(QueryRequest.class))).thenReturn(queryResponse);
    PostQueryPlugin stopQueryPlugin = new PostQueryPlugin() {

        @Override
        public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
            throw new StopProcessingException("Testing that the framework will stop the query.");
        }
    };
    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
    props.setBundleContext(context);
    props.setPostQuery(Arrays.asList(stopQueryPlugin));
    props.setFederationStrategy(federationStrategy);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setSourcePoller(poller);
    props.setFilterBuilder(new GeotoolsFilterBuilder());
    CatalogFrameworkImpl framework = createFramework(props);
    framework.query(request);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) FederationStrategy(ddf.catalog.federation.FederationStrategy) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) FilterFactory(org.opengis.filter.FilterFactory) SourcePoller(ddf.catalog.util.impl.SourcePoller) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Filter(org.opengis.filter.Filter) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) PostQueryPlugin(ddf.catalog.plugin.PostQueryPlugin) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 29 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class RefreshRegistryEntriesTest method testNoUpdatesOnOlder.

@Test
public void testNoUpdatesOnOlder() throws Exception {
    MetacardImpl localMcard = getPopulatedTestRegistryMetacard(TEST_METACARD_ID, RegistryObjectMetacardType.REGISTRY_ID, 0, true);
    Metacard remoteMcard = getPopulatedTestRegistryMetacard("remoteMcardId", RegistryObjectMetacardType.REGISTRY_ID, -5000L);
    when(federationAdminService.getInternalRegistryMetacards()).thenReturn(Collections.singletonList(localMcard));
    SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(remoteMcard)));
    when(registryStore.query(any(QueryRequest.class))).thenReturn(response);
    refreshRegistryEntries.setRegistryStores(Collections.singletonList(registryStore));
    when(registryStore.isPullAllowed()).thenReturn(true);
    when(registryStore.isAvailable()).thenReturn(true);
    refreshRegistryEntries.refreshRegistryEntries();
    verify(federationAdminService, never()).updateRegistryEntry(any(Metacard.class));
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 30 with SourceResponseImpl

use of ddf.catalog.operation.impl.SourceResponseImpl in project ddf by codice.

the class RefreshRegistryEntriesTest method testWriteRemoteUpdates.

@Test
public void testWriteRemoteUpdates() throws Exception {
    Metacard localMcard = getPopulatedTestRegistryMetacard(TEST_METACARD_ID, RegistryObjectMetacardType.REGISTRY_ID, 0, true);
    Metacard remoteMcard = getPopulatedTestRegistryMetacard("remoteMcardId", RegistryObjectMetacardType.REGISTRY_ID, 1000L);
    when(federationAdminService.getInternalRegistryMetacards()).thenReturn(Collections.singletonList(localMcard));
    SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(remoteMcard)));
    when(registryStore.query(any(QueryRequest.class))).thenReturn(response);
    refreshRegistryEntries.setRegistryStores(Collections.singletonList(registryStore));
    when(registryStore.isPullAllowed()).thenReturn(true);
    when(registryStore.isAvailable()).thenReturn(true);
    refreshRegistryEntries.refreshRegistryEntries();
    verify(federationAdminService).updateRegistryEntry(remoteMcard);
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Aggregations

SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)36 SourceResponse (ddf.catalog.operation.SourceResponse)24 ResultImpl (ddf.catalog.data.impl.ResultImpl)20 Result (ddf.catalog.data.Result)19 Test (org.junit.Test)19 Metacard (ddf.catalog.data.Metacard)17 QueryRequest (ddf.catalog.operation.QueryRequest)13 ArrayList (java.util.ArrayList)12 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)6 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)6 IOException (java.io.IOException)6 Query (ddf.catalog.operation.Query)5 BundleContext (org.osgi.framework.BundleContext)5 Matchers.anyString (org.mockito.Matchers.anyString)4 BinaryContent (ddf.catalog.data.BinaryContent)3 QueryImpl (ddf.catalog.operation.impl.QueryImpl)3 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)3 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)3 Serializable (java.io.Serializable)3