use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testUpdateStorageResponse.
@Test
public void testUpdateStorageResponse() throws UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException, StorageException {
// The metacard and updated metacard
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
storeMetacard(metacards.get(0));
// send a request to update the metacard
updateMetacard(storageRequest, storageResponse, metacards.get(1));
storageProvider.update(storageRequest);
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
// Verify that the metacard updated
Metacard update = readMetacard();
assertThat(update, equalTo(metacards.get(1)));
assertThat(storageResponse.getUpdatedContentItems().get(0).getUri(), not(equalTo(RESOURCE_URI)));
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testTryCommitStorageException.
@Test(expected = IngestException.class)
public void testTryCommitStorageException() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
List<Metacard> metacards = getMetacardUpdatePair();
// Mock out a bad storage provider
StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
doThrow(StorageException.class).when(exceptionStorageProvider).commit(any());
ContentItem item = mock(ContentItem.class);
when(item.getId()).thenReturn(METACARD_ID);
when(item.getUri()).thenReturn(RESOURCE_URI);
when(item.getMetacard()).thenReturn(metacards.get(0));
ReadStorageResponse readStorageResponse = mock(ReadStorageResponse.class);
when(readStorageResponse.getContentItem()).thenReturn(item);
when(exceptionStorageProvider.read(any())).thenReturn(readStorageResponse);
when(exceptionStorageProvider.create(any())).thenReturn(mock(CreateStorageResponse.class));
historian.setStorageProviders(Collections.singletonList(exceptionStorageProvider));
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
// send a request to update the metacard
updateMetacard(storageRequest, storageResponse, metacards.get(1));
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
verify(exceptionStorageProvider).rollback(any(StorageRequest.class));
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testUpdateStorageResponseNoContentItems.
@Test
public void testUpdateStorageResponseNoContentItems() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
// The metacard and updated metacard
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
// send a request to update the metacard
updateMetacard(storageRequest, storageResponse, metacards.get(1));
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
assertThat(storageProvider.storageMap.size(), equalTo(0));
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class UpdateOperations method update.
public UpdateResponse update(UpdateStorageRequest streamUpdateRequest) throws IngestException, SourceUnavailableException {
Map<String, Metacard> metacardMap = new HashMap<>();
List<ContentItem> contentItems = new ArrayList<>(streamUpdateRequest.getContentItems().size());
HashMap<String, Map<String, Path>> tmpContentPaths = new HashMap<>();
UpdateResponse updateResponse = null;
UpdateStorageRequest updateStorageRequest = null;
UpdateStorageResponse updateStorageResponse = null;
streamUpdateRequest = opsStorageSupport.prepareStorageRequest(streamUpdateRequest, streamUpdateRequest::getContentItems);
// Operation populates the metacardMap, contentItems, and tmpContentPaths
opsMetacardSupport.generateMetacardAndContentItems(streamUpdateRequest.getContentItems(), metacardMap, contentItems, tmpContentPaths);
streamUpdateRequest.getProperties().put(CONTENT_PATHS, tmpContentPaths);
streamUpdateRequest = applyAttributeOverrides(streamUpdateRequest, metacardMap);
try {
if (!contentItems.isEmpty()) {
updateStorageRequest = new UpdateStorageRequestImpl(contentItems, streamUpdateRequest.getId(), streamUpdateRequest.getProperties());
updateStorageRequest = processPreUpdateStoragePlugins(updateStorageRequest);
try {
updateStorageResponse = sourceOperations.getStorage().update(updateStorageRequest);
updateStorageResponse.getProperties().put(CONTENT_PATHS, tmpContentPaths);
} catch (StorageException e) {
throw new IngestException("Could not store content items. Removed created metacards.", e);
}
updateStorageResponse = processPostUpdateStoragePlugins(updateStorageResponse);
for (ContentItem contentItem : updateStorageResponse.getUpdatedContentItems()) {
if (StringUtils.isBlank(contentItem.getQualifier())) {
Metacard metacard = metacardMap.get(contentItem.getId());
Metacard overrideMetacard = contentItem.getMetacard();
Metacard updatedMetacard = OverrideAttributesSupport.overrideMetacard(metacard, overrideMetacard, true, true);
updatedMetacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_SIZE, String.valueOf(contentItem.getSize())));
metacardMap.put(contentItem.getId(), updatedMetacard);
}
}
}
UpdateRequestImpl updateRequest = new UpdateRequestImpl(Iterables.toArray(metacardMap.values().stream().map(Metacard::getId).collect(Collectors.toList()), String.class), new ArrayList<>(metacardMap.values()));
updateRequest.setProperties(streamUpdateRequest.getProperties());
historian.setSkipFlag(updateRequest);
updateResponse = doUpdate(updateRequest);
historian.version(streamUpdateRequest, updateStorageResponse, updateResponse);
} catch (Exception e) {
if (updateStorageRequest != null) {
try {
sourceOperations.getStorage().rollback(updateStorageRequest);
} catch (StorageException e1) {
LOGGER.info("Unable to remove temporary content for id: {}", updateStorageRequest.getId(), e1);
}
}
throw new IngestException("Unable to store products for request: " + streamUpdateRequest.getId(), e);
} finally {
opsStorageSupport.commitAndCleanup(updateStorageRequest, tmpContentPaths);
}
updateResponse = doPostIngest(updateResponse);
return updateResponse;
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class TestVideoThumbnailPlugin method testUpdatedItemNotVideoFile.
@Test
public void testUpdatedItemNotVideoFile() throws Exception {
mockContentItem = mock(ContentItem.class);
doReturn(new MimeType("application/pdf")).when(mockContentItem).getMimeType();
Metacard mockMetacard = new MetacardImpl();
doReturn(mockMetacard).when(mockContentItem).getMetacard();
final UpdateStorageResponse mockUpdateResponse = mock(UpdateStorageResponse.class);
doReturn(Collections.singletonList(mockContentItem)).when(mockUpdateResponse).getUpdatedContentItems();
final UpdateStorageResponse processedUpdateResponse = videoThumbnailPlugin.process(mockUpdateResponse);
assertThat(processedUpdateResponse.getUpdatedContentItems().get(0).getMetacard().getAttribute(Metacard.THUMBNAIL), CoreMatchers.is(nullValue()));
}
Aggregations