Search in sources :

Example 1 with ProcessResourceItem

use of org.codice.ddf.catalog.async.data.api.internal.ProcessResourceItem 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 2 with ProcessResourceItem

use of org.codice.ddf.catalog.async.data.api.internal.ProcessResourceItem in project ddf by codice.

the class MetacardBackupPluginTest method generateProcessRequest.

private ProcessRequest generateProcessRequest(Class<? extends ProcessResourceItem> clazz, boolean validCard) {
    List<ProcessResourceItem> processCreateItems = new ArrayList<>();
    for (String id : METACARD_IDS) {
        Metacard metacard = new MetacardImpl();
        metacard.setAttribute(new AttributeImpl(Core.ID, id));
        metacard.setAttribute(new AttributeImpl(Core.METADATA, XML_METADATA));
        if (!validCard) {
            metacard.setAttribute(new AttributeImpl(Core.METACARD_TAGS, "INVALID"));
        }
        ProcessResourceItem processResourceItem;
        if (clazz.getName().contains("ProcessCreateItem")) {
            processResourceItem = mock(ProcessCreateItem.class);
        } else {
            processResourceItem = mock(ProcessUpdateItem.class);
        }
        when(processResourceItem.getMetacard()).thenReturn(metacard);
        processCreateItems.add(processResourceItem);
    }
    ProcessRequest localCreateRequest = mock(ProcessRequest.class);
    when(localCreateRequest.getProcessItems()).thenReturn(processCreateItems);
    return localCreateRequest;
}
Also used : ProcessResourceItem(org.codice.ddf.catalog.async.data.api.internal.ProcessResourceItem) Metacard(ddf.catalog.data.Metacard) ProcessRequest(org.codice.ddf.catalog.async.data.api.internal.ProcessRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) ProcessCreateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessCreateItem) ProcessUpdateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessUpdateItem) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Aggregations

Metacard (ddf.catalog.data.Metacard)2 ProcessResourceItem (org.codice.ddf.catalog.async.data.api.internal.ProcessResourceItem)2 BinaryContent (ddf.catalog.data.BinaryContent)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 ArrayList (java.util.ArrayList)1 ProcessCreateItem (org.codice.ddf.catalog.async.data.api.internal.ProcessCreateItem)1 ProcessRequest (org.codice.ddf.catalog.async.data.api.internal.ProcessRequest)1 ProcessUpdateItem (org.codice.ddf.catalog.async.data.api.internal.ProcessUpdateItem)1