use of ddf.catalog.content.operation.UpdateStorageResponse 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;
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class FileSystemStorageProviderTest method testCreateWithQualifierAndOneInvalidItem.
@Test
public void testCreateWithQualifierAndOneInvalidItem() throws Exception {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream("This data is my data, this data is your data.");
}
};
ContentItem contentItem = new ContentItemImpl(uuid, null, byteSource, "application/text", "datadatadata", byteSource.size(), mock(Metacard.class));
String invalidUuid = "wow-this-isn't-a-valid-uuid-right?!@#%";
ContentItem badContentItem = new ContentItemImpl(invalidUuid, null, byteSource, "application/text", "datadatadata", byteSource.size(), mock(Metacard.class));
CreateStorageRequest createRequest = new CreateStorageRequestImpl(Lists.newArrayList(contentItem, badContentItem), null);
CreateStorageResponse createResponse = provider.create(createRequest);
assertThat(createResponse.getCreatedContentItems().size(), is(1));
assertThat(createResponse.getCreatedContentItems().get(0).getId(), is(uuid));
ContentItem updateContentItem = new ContentItemImpl(invalidUuid, null, byteSource, "application/text", "datadatadata", byteSource.size(), mock(Metacard.class));
UpdateStorageRequest updateRequest = new UpdateStorageRequestImpl(Lists.newArrayList(updateContentItem), null);
UpdateStorageResponse updateResponse = provider.update(updateRequest);
assertThat(updateResponse.getUpdatedContentItems().size(), is(0));
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testUpdateStorageResponseSkipProperty.
@Test
public void testUpdateStorageResponseSkipProperty() throws SourceUnavailableException, IngestException, UnsupportedQueryException {
Map<String, Serializable> properties = new HashMap<>();
properties.put(MetacardVersion.SKIP_VERSIONING, true);
UpdateStorageResponse updateStorageResponse = mock(UpdateStorageResponse.class);
when(updateStorageResponse.getProperties()).thenReturn(properties);
historian.version(mock(UpdateStorageRequest.class), updateStorageResponse, mock(UpdateResponse.class));
verifyZeroInteractions(catalogProvider);
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class Historian method version.
/**
* Versions updated {@link Metacard}s and {@link ContentItem}s.
*
* @param streamUpdateRequest Needed to pass {@link ddf.catalog.core.versioning.MetacardVersion#SKIP_VERSIONING}
* flag into downstream update
* @param updateStorageResponse Versions this response's updated items
* @return the update response originally passed in
* @throws UnsupportedQueryException
* @throws SourceUnavailableException
* @throws IngestException
*/
public UpdateStorageResponse version(UpdateStorageRequest streamUpdateRequest, UpdateStorageResponse updateStorageResponse, UpdateResponse updateResponse) throws UnsupportedQueryException, SourceUnavailableException, IngestException {
if (doSkip(updateStorageResponse)) {
return updateStorageResponse;
}
setSkipFlag(streamUpdateRequest);
setSkipFlag(updateStorageResponse);
List<Metacard> updatedMetacards = updateStorageResponse.getUpdatedContentItems().stream().filter(ci -> StringUtils.isBlank(ci.getQualifier())).map(ContentItem::getMetacard).filter(Objects::nonNull).filter(isNotVersionNorDeleted).collect(Collectors.toList());
Map<String, Metacard> originalMetacards = query(forIds(updatedMetacards.stream().map(Metacard::getId).collect(Collectors.toList())));
Collection<ReadStorageRequest> ids = getReadStorageRequests(updatedMetacards);
Map<String, List<ContentItem>> content = getContent(ids);
Function<String, Action> getAction = (id) -> content.containsKey(id) ? Action.VERSIONED_CONTENT : Action.VERSIONED;
Map<String, Metacard> versionMetacards = getVersionMetacards(originalMetacards.values(), getAction, (Subject) updateResponse.getProperties().get(SecurityConstants.SECURITY_SUBJECT));
CreateStorageResponse createStorageResponse = versionContentItems(content, versionMetacards);
if (createStorageResponse == null) {
LOGGER.debug("Could not version content items.");
return updateStorageResponse;
}
setResourceUriForContent(/*mutable*/
versionMetacards, createStorageResponse);
storeVersionMetacards(versionMetacards);
return updateStorageResponse;
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testReadStorageException.
@Test
public void testReadStorageException() throws StorageException, SourceUnavailableException, IngestException, UnsupportedQueryException, URISyntaxException {
StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
when(exceptionStorageProvider.read(any())).thenThrow(StorageException.class);
historian.setStorageProviders(Collections.singletonList(exceptionStorageProvider));
Metacard metacard = getMetacardUpdatePair().get(0);
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
// create the update request
updateMetacard(storageRequest, storageResponse, metacard);
mockQuery(metacard);
historian.version(storageRequest, storageResponse, updateResponse);
// Verify that it wasn't updated
verify(catalogProvider, times(0)).create(anyObject());
}
Aggregations