Search in sources :

Example 1 with UpdateStorageResponseImpl

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;
}
Also used : Path(java.nio.file.Path) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) UpdateStorageResponseImpl(ddf.catalog.content.operation.impl.UpdateStorageResponseImpl) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem)

Aggregations

StorageException (ddf.catalog.content.StorageException)1 ContentItem (ddf.catalog.content.data.ContentItem)1 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)1 UpdateStorageResponseImpl (ddf.catalog.content.operation.impl.UpdateStorageResponseImpl)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1