use of ddf.catalog.content.data.ContentItem 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.data.ContentItem 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.data.ContentItem in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateStorage.
/**
* Tests that the framework properly passes an update request to the local provider.
*/
@Test
public void testUpdateStorage() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
MetacardImpl metacard = new MetacardImpl();
metacard.setId(null);
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("blah".getBytes());
}
};
ContentItemImpl contentItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, metacard);
contentItems.add(contentItem);
CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, null));
Metacard insertedCard = response.getCreatedMetacards().get(0);
List<ContentItem> updatedContentItems = new ArrayList<>();
updatedContentItems.add(new ContentItemImpl(insertedCard.getId(), byteSource, "application/octet-stream", insertedCard));
UpdateStorageRequest request = new UpdateStorageRequestImpl(updatedContentItems, null);
List<Result> mockFederationResults = Stream.of(insertedCard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
assertThat(returnedCards, hasSize(1));
final Metacard newMetacard = returnedCards.get(0).getNewMetacard();
assertThat(newMetacard.getId(), notNullValue());
assertThat(newMetacard.getResourceURI().toString(), is(contentItem.getUri()));
assertThat(newMetacard.getResourceSize(), is(Long.toString(byteSource.size())));
assertThat(response.getCreatedMetacards(), hasSize(storageProvider.size()));
// make sure that the event was posted correctly
assertThat(eventAdmin.wasEventPosted(), is(true));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class VideoThumbnailPlugin method processContentItems.
private void processContentItems(final List<ContentItem> contentItems, final Map<String, Serializable> properties) throws PluginExecutionException, IllegalArgumentException {
Map<String, Map<String, Path>> tmpContentPaths = (Map<String, Map<String, Path>>) properties.get(Constants.CONTENT_PATHS);
for (ContentItem contentItem : contentItems) {
if (isVideo(contentItem)) {
Map<String, Path> contentPaths = tmpContentPaths.get(contentItem.getId());
if (contentPaths == null || contentPaths.isEmpty()) {
throw new IllegalArgumentException("No path for contentItem " + contentItem.getId() + " provided. Skipping.");
}
// create a thumbnail for the unqualified content item
Path tmpPath = contentPaths.get(null);
if (tmpPath != null) {
createThumbnail(contentItem, tmpPath);
}
}
}
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FtpRequestHandler method getCreateStorageRequest.
private CreateStorageRequest getCreateStorageRequest(String fileName, TemporaryFileBackedOutputStream outputStream) throws IOException {
String fileExtension = FilenameUtils.getExtension(fileName);
String mimeType = getMimeType(fileExtension, outputStream);
ContentItem newItem = new ContentItemImpl(uuidGenerator.generateUuid(), outputStream.asByteSource(), mimeType, fileName, 0L, null);
return new CreateStorageRequestImpl(Collections.singletonList(newItem), null);
}
Aggregations