use of ddf.catalog.content.operation.impl.UpdateStorageResponseImpl in project ddf by codice.
the class FileSystemStorageProvider method update.
@Override
public UpdateStorageResponse update(UpdateStorageRequest updateRequest) throws StorageException {
LOGGER.trace("ENTERING: update");
List<ContentItem> contentItems = updateRequest.getContentItems();
List<ContentItem> updatedItems = new ArrayList<>(updateRequest.getContentItems().size());
for (ContentItem contentItem : contentItems) {
try {
if (!ContentItemValidator.validate(contentItem)) {
LOGGER.warn("Item is not valid: {}", contentItem);
continue;
}
ContentItem updateItem = contentItem;
if (StringUtils.isBlank(contentItem.getFilename()) || StringUtils.equals(contentItem.getFilename(), ContentItem.DEFAULT_FILE_NAME)) {
ContentItem existingItem = readContent(new URI(contentItem.getUri()));
updateItem = new ContentItemDecorator(contentItem, existingItem);
}
Path contentIdDir = getTempContentItemDir(updateRequest.getId(), new URI(updateItem.getUri()));
updatedItems.add(generateContentFile(updateItem, contentIdDir, (String) updateRequest.getPropertyValue(Constants.STORE_REFERENCE_KEY)));
} catch (IOException | URISyntaxException | IllegalArgumentException e) {
throw new StorageException(e);
}
}
for (ContentItem contentItem : updatedItems) {
if (contentItem.getMetacard().getResourceURI() == null && StringUtils.isBlank(contentItem.getQualifier())) {
contentItem.getMetacard().setAttribute(new AttributeImpl(Metacard.RESOURCE_URI, contentItem.getUri()));
try {
contentItem.getMetacard().setAttribute(new AttributeImpl(Metacard.RESOURCE_SIZE, contentItem.getSize()));
} catch (IOException e) {
LOGGER.info("Could not set size of content item [{}] on metacard [{}]", contentItem.getId(), contentItem.getMetacard().getId(), e);
}
}
}
UpdateStorageResponse response = new UpdateStorageResponseImpl(updateRequest, updatedItems);
updateMap.put(updateRequest.getId(), updatedItems.stream().map(ContentItem::getUri).collect(Collectors.toSet()));
LOGGER.trace("EXITING: update");
return response;
}
Aggregations