use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.
the class FileSystemStorageProviderTest method testDeleteIdWithMultpleContent.
@Test
public void testDeleteIdWithMultpleContent() throws Exception {
CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
createResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, createResponse.getCreatedContentItems().get(0).getId(), QUALIFIER);
String id = createResponse.getCreatedContentItems().get(0).getId();
DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(createResponse.getCreatedContentItems().stream().map(ContentItem::getMetacard).collect(Collectors.toList()), null);
when(deleteRequest.getMetacards().get(0).getId()).thenReturn(id);
DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
provider.commit(deleteRequest);
List<ContentItem> items = deleteResponse.getDeletedContentItems();
assertThat(items, hasSize(2));
for (ContentItem item : items) {
LOGGER.debug("Item retrieved: {}", item);
assertThat(item.getId(), is(id));
assertThat(item.getFilename(), isEmptyString());
}
}
use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.
the class FileSystemStorageProviderTest method testDeleteReference.
@Test
public void testDeleteReference() throws Exception {
String path = baseTmpDir + File.separator + TEST_INPUT_FILENAME;
FileUtils.writeStringToFile(new File(path), TEST_INPUT_CONTENTS);
Map<String, Serializable> properties = new HashMap<>();
properties.put(Constants.STORE_REFERENCE_KEY, path);
CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, properties);
String id = createResponse.getCreatedContentItems().get(0).getId();
DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(createResponse.getCreatedContentItems().stream().map(ContentItem::getMetacard).collect(Collectors.toList()), null);
when(deleteRequest.getMetacards().get(0).getId()).thenReturn(id);
DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
List<ContentItem> items = deleteResponse.getDeletedContentItems();
ContentItem item = items.get(0);
LOGGER.debug("Item retrieved: {}", item);
assertEquals(id, item.getId());
assertThat(item.getFilename(), isEmptyString());
assertTrue(new File(path).exists());
}
use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.
the class CreateOperations method create.
public CreateResponse create(CreateStorageRequest streamCreateRequest, List<String> fanoutTagBlacklist) throws IngestException, SourceUnavailableException {
Map<String, Metacard> metacardMap = new HashMap<>();
List<ContentItem> contentItems = new ArrayList<>(streamCreateRequest.getContentItems().size());
HashMap<String, Map<String, Path>> tmpContentPaths = new HashMap<>();
CreateResponse createResponse = null;
CreateStorageRequest createStorageRequest = null;
CreateStorageResponse createStorageResponse;
streamCreateRequest = opsStorageSupport.prepareStorageRequest(streamCreateRequest, streamCreateRequest::getContentItems);
// Operation populates the metacardMap, contentItems, and tmpContentPaths
opsMetacardSupport.generateMetacardAndContentItems(streamCreateRequest.getContentItems(), metacardMap, contentItems, tmpContentPaths);
if (blockCreateMetacards(metacardMap.values(), fanoutTagBlacklist)) {
String message = "Fanout proxy does not support create operations with blacklisted metacard tag";
LOGGER.debug("{}. Tags blacklist: {}", message, fanoutTagBlacklist);
throw new IngestException(message);
}
streamCreateRequest.getProperties().put(CONTENT_PATHS, tmpContentPaths);
injectAttributes(metacardMap);
setDefaultValues(metacardMap);
streamCreateRequest = applyAttributeOverrides(streamCreateRequest, metacardMap);
try {
if (!contentItems.isEmpty()) {
createStorageRequest = new CreateStorageRequestImpl(contentItems, streamCreateRequest.getId(), streamCreateRequest.getProperties());
createStorageRequest = processPreCreateStoragePlugins(createStorageRequest);
try {
createStorageResponse = sourceOperations.getStorage().create(createStorageRequest);
createStorageResponse.getProperties().put(CONTENT_PATHS, tmpContentPaths);
} catch (StorageException e) {
throw new IngestException("Could not store content items.", e);
}
createStorageResponse = processPostCreateStoragePlugins(createStorageResponse);
populateMetacardMap(metacardMap, createStorageResponse);
}
CreateRequest createRequest = new CreateRequestImpl(new ArrayList<>(metacardMap.values()), Optional.ofNullable(createStorageRequest).map(StorageRequest::getProperties).orElseGet(HashMap::new));
createResponse = doCreate(createRequest);
} catch (IOException | RuntimeException e) {
if (createStorageRequest != null) {
try {
sourceOperations.getStorage().rollback(createStorageRequest);
} catch (StorageException e1) {
LOGGER.info("Unable to remove temporary content for id: {}", createStorageRequest.getId(), e1);
}
}
throw new IngestException("Unable to store products for request: " + streamCreateRequest.getId(), e);
} finally {
opsStorageSupport.commitAndCleanup(createStorageRequest, tmpContentPaths);
}
createResponse = doPostIngest(createResponse);
return createResponse;
}
use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.
the class TestVideoThumbnailPlugin method testCreatedItemNotVideoFile.
@Test
public void testCreatedItemNotVideoFile() throws Exception {
mockContentItem = mock(ContentItem.class);
doReturn(new MimeType("image/jpeg")).when(mockContentItem).getMimeType();
Metacard mockMetacard = new MetacardImpl();
doReturn(mockMetacard).when(mockContentItem).getMetacard();
final CreateStorageResponse mockCreateResponse = mock(CreateStorageResponse.class);
doReturn(Collections.singletonList(mockContentItem)).when(mockCreateResponse).getCreatedContentItems();
final CreateStorageResponse processedCreateResponse = videoThumbnailPlugin.process(mockCreateResponse);
assertThat(processedCreateResponse.getCreatedContentItems().get(0).getMetacard().getAttribute(Metacard.THUMBNAIL), CoreMatchers.is(nullValue()));
}
use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.
the class TestVideoThumbnailPlugin method getCreatedItemThumbnail.
private byte[] getCreatedItemThumbnail(final String videoFile) throws Exception {
setUpMockContentItem(videoFile);
final CreateStorageResponse mockCreateResponse = mock(CreateStorageResponse.class);
doReturn(Collections.singletonList(mockContentItem)).when(mockCreateResponse).getCreatedContentItems();
final CreateStorageRequest mockCreateRequest = mock(CreateStorageRequest.class);
doReturn(mockCreateRequest).when(mockCreateResponse).getRequest();
doReturn(properties).when(mockCreateResponse).getProperties();
final CreateStorageResponse processedCreateResponse = videoThumbnailPlugin.process(mockCreateResponse);
return (byte[]) processedCreateResponse.getCreatedContentItems().get(0).getMetacard().getAttribute(Metacard.THUMBNAIL).getValue();
}
Aggregations