Search in sources :

Example 1 with ProcessResource

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

the class InMemoryProcessingFramework method storeProcessRequest.

private <T extends ProcessResourceItem> void storeProcessRequest(ProcessRequest<T> processRequest) {
    LOGGER.trace("Storing update request post processing change(s)");
    Map<String, ContentItem> contentItemsToUpdate = new HashMap<>();
    Map<String, Metacard> metacardsToUpdate = new HashMap<>();
    List<TemporaryFileBackedOutputStream> tfbosToCleanUp = new ArrayList<>();
    for (T item : processRequest.getProcessItems()) {
        if (item.getProcessResource() == null && item.isMetacardModified()) {
            metacardsToUpdate.put(item.getMetacard().getId(), item.getMetacard());
        }
        final ProcessResource processResource = item.getProcessResource();
        TemporaryFileBackedOutputStream tfbos = null;
        if (processResource != null && processResource.isModified() && !contentItemsToUpdate.containsKey(getContentItemKey(item.getMetacard(), processResource))) {
            try {
                tfbos = new TemporaryFileBackedOutputStream();
                long numberOfBytes = IOUtils.copyLarge(processResource.getInputStream(), tfbos);
                LOGGER.debug("Copied {} bytes to TemporaryFileBackedOutputStream.", numberOfBytes);
                ByteSource byteSource = tfbos.asByteSource();
                ContentItem contentItem = new ContentItemImpl(item.getMetacard().getId(), processResource.getQualifier(), byteSource, processResource.getMimeType(), processResource.getName(), processResource.getSize(), item.getMetacard());
                contentItemsToUpdate.put(getContentItemKey(item.getMetacard(), processResource), contentItem);
                tfbosToCleanUp.add(tfbos);
            } catch (IOException | RuntimeException e) {
                LOGGER.debug("Unable to store process request", e);
                if (tfbos != null) {
                    close(tfbos);
                }
            }
        }
    }
    storeContentItemUpdates(contentItemsToUpdate, processRequest.getProperties());
    storeMetacardUpdates(metacardsToUpdate, processRequest.getProperties());
    closeTfbos(tfbosToCleanUp);
}
Also used : TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessResource(org.codice.ddf.catalog.async.data.api.internal.ProcessResource) IOException(java.io.IOException) Metacard(ddf.catalog.data.Metacard) ByteSource(com.google.common.io.ByteSource) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Example 2 with ProcessResource

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

the class ProcessingPostIngestPlugin method getProcessResource.

private ProcessResource getProcessResource(Metacard metacard, Subject subject) {
    LOGGER.trace("Attempting to retrieve process resource metacard with id \"{}\" and sourceId \"{}\".", metacard.getId(), metacard.getSourceId());
    ResourceRequest request = new ResourceRequestById(metacard.getId());
    if (subject == null) {
        LOGGER.debug("No available subject to fetch metacard resource. Returning null");
        return null;
    }
    return subject.execute(() -> {
        try {
            ResourceResponse response = catalogFramework.getResource(request, metacard.getSourceId());
            Resource resource = response.getResource();
            ProcessResource processResource = new ProcessResourceImpl(metacard.getId(), resource.getInputStream(), resource.getMimeTypeValue(), resource.getName(), resource.getSize(), false);
            return processResource;
        } catch (IOException | ResourceNotFoundException | ResourceNotSupportedException | RuntimeException e) {
            LOGGER.debug("Unable to get resource id:{}, sourceId:{}. Returning null", metacard.getId(), metacard.getSourceId(), e);
        }
        return null;
    });
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) Resource(ddf.catalog.resource.Resource) ProcessResource(org.codice.ddf.catalog.async.data.api.internal.ProcessResource) ProcessResource(org.codice.ddf.catalog.async.data.api.internal.ProcessResource) ResourceRequest(ddf.catalog.operation.ResourceRequest) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) ProcessResourceImpl(org.codice.ddf.catalog.async.data.impl.ProcessResourceImpl)

Aggregations

IOException (java.io.IOException)2 ProcessResource (org.codice.ddf.catalog.async.data.api.internal.ProcessResource)2 ByteSource (com.google.common.io.ByteSource)1 ContentItem (ddf.catalog.content.data.ContentItem)1 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)1 Metacard (ddf.catalog.data.Metacard)1 ResourceRequest (ddf.catalog.operation.ResourceRequest)1 ResourceResponse (ddf.catalog.operation.ResourceResponse)1 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)1 Resource (ddf.catalog.resource.Resource)1 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)1 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ProcessResourceImpl (org.codice.ddf.catalog.async.data.impl.ProcessResourceImpl)1 TemporaryFileBackedOutputStream (org.codice.ddf.platform.util.TemporaryFileBackedOutputStream)1