Search in sources :

Example 6 with PluginExecutionException

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

the class RestReplicatorPlugin method transform.

private String transform(Metacard m, WebClient client) throws PluginExecutionException {
    BinaryContent binaryContent;
    try {
        binaryContent = transformer.transform(m, new HashMap<>());
        client.type(getValidMimeType(binaryContent.getMimeTypeValue()));
        return new String(binaryContent.getByteArray(), StandardCharsets.UTF_8);
    } catch (IOException e) {
        LOGGER.debug("Could not understand metacard.", e);
        throw new PluginExecutionException("Could not send metacard.");
    } catch (CatalogTransformerException e) {
        LOGGER.debug("Could not transform metacard.", e);
        throw new PluginExecutionException("Could not send metacard.");
    }
}
Also used : HashMap(java.util.HashMap) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) BinaryContent(ddf.catalog.data.BinaryContent) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 7 with PluginExecutionException

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

the class MetacardBackupPlugin method processRequest.

private void processRequest(ProcessRequest<? extends ProcessResourceItem> processRequest) throws PluginExecutionException {
    if (CollectionUtils.isEmpty(storageBackupPlugins)) {
        throw new PluginExecutionException("Unable to backup ingested metacard; no metacard backup storage provider configured.");
    }
    if (metacardTransformer == null) {
        throw new PluginExecutionException("Unable to backup ingested metacard; no Metacard Transformer found.");
    }
    List<? extends ProcessResourceItem> processResourceItems = processRequest.getProcessItems();
    for (ProcessResourceItem processResourceItem : processResourceItems) {
        Metacard metacard = processResourceItem.getMetacard();
        if (shouldBackupMetacard(metacard)) {
            try {
                LOGGER.trace("Backing up metacard : {}", metacard.getId());
                BinaryContent binaryContent = metacardTransformer.transform(metacard, Collections.emptyMap());
                backupData(binaryContent, metacard.getId());
            } catch (CatalogTransformerException e) {
                LOGGER.debug("Unable to transform metacard with id {}.", metacard.getId(), e);
                throw new PluginExecutionException(String.format("Unable to transform metacard with id %s.", metacard.getId()));
            }
        }
    }
}
Also used : ProcessResourceItem(org.codice.ddf.catalog.async.data.api.internal.ProcessResourceItem) Metacard(ddf.catalog.data.Metacard) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) BinaryContent(ddf.catalog.data.BinaryContent) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 8 with PluginExecutionException

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

the class ExpirationDatePlugin method process.

/**
     * Modify metacard expiration dates (pre-ingest).
     */
@Override
public CreateRequest process(CreateRequest createRequest) throws PluginExecutionException, StopProcessingException {
    LOGGER.debug("START Pre-Ingest Plugin: {}.process(CreateRequest createRequest)", this.getClass().getName());
    if (createRequest == null || createRequest.getMetacards() == null || createRequest.getMetacards().isEmpty()) {
        throw new PluginExecutionException("No metacards to validate or CreateRequest is null");
    }
    List<Metacard> metacards = createRequest.getMetacards();
    for (Metacard metacard : metacards) {
        updateExpirationDate(metacard);
    }
    LOGGER.debug("END Pre-Ingest Plugin: {}.process(CreateRequest createRequest)", this.getClass().getName());
    return createRequest;
}
Also used : Metacard(ddf.catalog.data.Metacard) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 9 with PluginExecutionException

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

the class RegistryIdPostIngestPlugin method init.

/**
     * Init method initializes the id sets from the catalog. If the catalog is not available it
     * will retry later.
     */
public void init() {
    try {
        List<Metacard> registryMetacards;
        Filter registryFilter = filterBuilder.anyOf(filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG), filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL));
        QueryImpl query = new QueryImpl(registryFilter);
        query.setPageSize(PAGE_SIZE);
        QueryRequest request = new QueryRequestImpl(query);
        QueryResponse response = security.runAsAdminWithException(() -> security.runWithSubjectOrElevate(() -> catalogFramework.query(request)));
        if (response == null) {
            throw new PluginExecutionException("Failed to initialize RegistryIdPostIngestPlugin. Query for registry metacards came back null");
        }
        registryMetacards = response.getResults().stream().map(Result::getMetacard).collect(Collectors.toList());
        addIdsFromMetacards(registryMetacards);
    } catch (PrivilegedActionException | PluginExecutionException e) {
        LOGGER.debug("Error getting registry metacards. Will try again later");
        executorService.schedule(this::init, RETRY_INTERVAL, TimeUnit.SECONDS);
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) PrivilegedActionException(java.security.PrivilegedActionException) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) Result(ddf.catalog.data.Result)

Example 10 with PluginExecutionException

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

the class VideoThumbnailPlugin method createThumbnail.

private void createThumbnail(final ContentItem contentItem, final Path contentPath) throws PluginExecutionException {
    LOGGER.debug("About to create video thumbnail.");
    try {
        limitFFmpegProcessesSemaphore.acquire();
        try {
            final byte[] thumbnailBytes = createThumbnail(contentPath.toAbsolutePath().toString());
            addThumbnailAttribute(contentItem, thumbnailBytes);
            LOGGER.debug("Successfully created video thumbnail.");
        } finally {
            limitFFmpegProcessesSemaphore.release();
        }
    } catch (IOException | InterruptedException e) {
        throw new PluginExecutionException(e);
    } finally {
        deleteImageFiles();
    }
}
Also used : IOException(java.io.IOException) 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