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);
}
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;
});
}
Aggregations