Search in sources :

Example 11 with PluginExecutionException

use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.

the class Checksum method runChecksum.

private void runChecksum(List<ContentItem> contentItems) throws PluginExecutionException {
    for (ContentItem contentItem : contentItems) {
        try (InputStream inputStream = contentItem.getInputStream()) {
            //calculate checksum so that it can be added as an attribute on metacard
            String checksumAlgorithm = checksumProvider.getChecksumAlgorithm();
            String checksumValue;
            try {
                checksumValue = checksumProvider.calculateChecksum(inputStream);
            } catch (IOException e) {
                throw new PluginExecutionException("Error calculating checksum", e);
            } catch (NoSuchAlgorithmException e) {
                throw new PluginExecutionException("Unsupported algorithm", e);
            }
            addChecksumAttributes(contentItem.getMetacard(), checksumAlgorithm, checksumValue);
        } catch (IOException e) {
            throw new PluginExecutionException("Unable to retrieve input stream for content item", e);
        }
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ContentItem(ddf.catalog.content.data.ContentItem) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 12 with PluginExecutionException

use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.

the class ExceptionsTest method testPluginExecutionException.

@Test
public void testPluginExecutionException() {
    PluginExecutionException pee = new PluginExecutionException();
    assertNotNull(pee);
    pee = new PluginExecutionException(msg);
    assertEquals(pee.getMessage(), msg);
    pee = new PluginExecutionException(testCause);
    assertEquals(pee.getCause(), testCause);
    pee = new PluginExecutionException(msg, testCause);
    assertEquals(pee.getMessage(), msg);
    assertEquals(pee.getCause(), testCause);
}
Also used : PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) Test(org.junit.Test)

Example 13 with PluginExecutionException

use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.

the class CachingFederationStrategyTest method testCatchPluginExecutionException.

@Test
public void testCatchPluginExecutionException() throws Exception {
    PreFederatedQueryPlugin mockPlug = mock(PreFederatedQueryPlugin.class);
    PreFederatedQueryPlugin mockPlug2 = mock(PreFederatedQueryPlugin.class);
    when(mockPlug.process(any(Source.class), any(QueryRequest.class))).thenThrow(new PluginExecutionException());
    strategy = new CachingFederationStrategy(queryExecutor, Arrays.asList(mockPlug, mockPlug2), new ArrayList<>(), cache, cacheExecutor, mock(ValidationQueryFactory.class), new CacheQueryFactory(new GeotoolsFilterBuilder()));
    QueryRequest fedQueryRequest = new QueryRequestImpl(mockQuery, properties);
    strategy.federate(Arrays.asList(mock(Source.class)), fedQueryRequest);
    verify(mockPlug).process(any(Source.class), any(QueryRequest.class));
    verify(mockPlug2).process(any(Source.class), any(QueryRequest.class));
}
Also used : PreFederatedQueryPlugin(ddf.catalog.plugin.PreFederatedQueryPlugin) QueryRequest(ddf.catalog.operation.QueryRequest) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ArrayList(java.util.ArrayList) Source(ddf.catalog.source.Source) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) Test(org.junit.Test)

Example 14 with PluginExecutionException

use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.

the class DummyPreQueryPlugin method process.

@Override
public QueryRequest process(QueryRequest input) throws PluginExecutionException, StopProcessingException {
    String methodName = "process";
    LOGGER.trace(ENTERING, methodName);
    QueryRequest newQueryRequest = input;
    if (input != null) {
        Query query = input.getQuery();
        if (query != null) {
            FilterDelegate<Filter> delegate = new CopyFilterDelegate(filterBuilder);
            try {
                // Make a defensive copy of the original filter (just in case anyone else
                // expects
                // it to remain unmodified)
                Filter copiedFilter = filterAdapter.adapt(query, delegate);
                // Define the extra query clause(s) to add to the copied filter
                // This will create a filter with a search phrase of:
                // ((("schematypesearch") and ("test" and ("ISAF" or "CAN"))))
                Filter contextualFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("test");
                Filter releasableToFilter1 = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("ISAF");
                Filter releasableToFilter2 = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("CAN");
                Filter orFilter = filterBuilder.anyOf(releasableToFilter1, releasableToFilter2);
                Filter extraFilter = filterBuilder.allOf(contextualFilter, orFilter);
                // AND this PreQueryPlugin's extra query clause(s) to the copied filter
                Filter modifiedFilter = filterBuilder.allOf(copiedFilter, extraFilter);
                // Create a new QueryRequest using the modified filter and the attributes from
                // the original query
                QueryImpl newQuery = new QueryImpl(modifiedFilter, query.getStartIndex(), query.getPageSize(), query.getSortBy(), query.requestsTotalResultsCount(), query.getTimeoutMillis());
                newQueryRequest = new QueryRequestImpl(newQuery, input.isEnterprise(), input.getSourceIds(), input.getProperties());
            } catch (UnsupportedQueryException e) {
                throw new PluginExecutionException(e);
            }
        }
    }
    LOGGER.trace(EXITING, methodName);
    return newQueryRequest;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query) Filter(org.opengis.filter.Filter) CopyFilterDelegate(ddf.catalog.filter.delegate.CopyFilterDelegate) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 15 with PluginExecutionException

use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.

the class DummyPreSubscriptionPlugin method process.

public Subscription process(Subscription input) throws PluginExecutionException {
    String methodName = "process";
    LOGGER.trace(ENTERING, methodName);
    Subscription newSubscription = input;
    if (input != null) {
        FilterDelegate<Filter> delegate = new CopyFilterDelegate(filterBuilder);
        try {
            // Make a defensive copy of the original filter (just in case anyone else expects
            // it to remain unmodified)
            Filter copiedFilter = filterAdapter.adapt(input, delegate);
            // Define the extra query clause(s) to add to the copied filter
            Filter extraFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text("CAN");
            // AND the extra query clause(s) to the copied filter
            Filter modifiedFilter = filterBuilder.allOf(copiedFilter, extraFilter);
            // Create a new subscription with the modified filter
            newSubscription = new SubscriptionImpl(modifiedFilter, input.getDeliveryMethod(), input.getSourceIds(), input.isEnterprise());
        } catch (UnsupportedQueryException e) {
            throw new PluginExecutionException(e);
        }
    }
    LOGGER.trace(EXITING, methodName);
    return newSubscription;
}
Also used : Filter(org.opengis.filter.Filter) CopyFilterDelegate(ddf.catalog.filter.delegate.CopyFilterDelegate) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Subscription(ddf.catalog.event.Subscription) SubscriptionImpl(ddf.catalog.event.impl.SubscriptionImpl) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Aggregations

PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)18 Metacard (ddf.catalog.data.Metacard)7 QueryRequest (ddf.catalog.operation.QueryRequest)5 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)5 StopProcessingException (ddf.catalog.plugin.StopProcessingException)4 IOException (java.io.IOException)4 Query (ddf.catalog.operation.Query)3 QueryResponse (ddf.catalog.operation.QueryResponse)3 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)3 Source (ddf.catalog.source.Source)3 HashMap (java.util.HashMap)3 BinaryContent (ddf.catalog.data.BinaryContent)2 Result (ddf.catalog.data.Result)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)2 CopyFilterDelegate (ddf.catalog.filter.delegate.CopyFilterDelegate)2 SourceResponse (ddf.catalog.operation.SourceResponse)2 Update (ddf.catalog.operation.Update)2 UpdateRequest (ddf.catalog.operation.UpdateRequest)2 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)2