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);
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FileSystemStorageProviderTest method assertReadRequest.
private void assertReadRequest(String uriString, String mimeType, boolean extension) throws StorageException, IOException, URISyntaxException {
final URI uri = new URI(uriString);
ReadStorageRequest readRequest = new ReadStorageRequestImpl(uri, Collections.emptyMap());
ReadStorageResponse readResponse = provider.read(readRequest);
ContentItem item = readResponse.getContentItem();
LOGGER.debug("Item retrieved: {}", item);
assertThat(item, notNullValue());
assertThat(item.getId(), is(uri.getSchemeSpecificPart()));
if (uri.getFragment() != null) {
assertThat(item.getQualifier(), is(uri.getFragment()));
}
if (mimeType.equals(NITF_MIME_TYPE)) {
assertThat(item.getMimeTypeRawData(), is(NITF_MIME_TYPE));
}
List<String> parts = provider.getContentFilePathParts(uri.getSchemeSpecificPart(), uri.getFragment());
String expectedFilePath = baseDir + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_REPOSITORY + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_STORE + File.separator + parts.get(0) + File.separator + parts.get(1) + File.separator + parts.get(2) + (StringUtils.isNotBlank(item.getQualifier()) ? File.separator + item.getQualifier() : "") + File.separator + item.getFilename();
if (extension) {
expectedFilePath = expectedFilePath + "." + FileSystemStorageProvider.REF_EXT;
}
assertThat(Files.exists(Paths.get(expectedFilePath)), is(true));
assertTrue(item.getSize() > 0);
}
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 InMemoryProcessingFramework method storeProcessRequest.
private <T extends ProcessResourceItem> void storeProcessRequest(ProcessRequest<T> processRequest) {
LOGGER.trace("Storing update request post processing change(s)");
Map<String, ContentItem> contentItemsToUpdate = new HashMap<>();
Map<String, Metacard> metacardsToUpdate = new HashMap<>();
List<TemporaryFileBackedOutputStream> tfbosToCleanUp = new ArrayList<>();
for (T item : processRequest.getProcessItems()) {
if (item.getProcessResource() == null && item.isMetacardModified()) {
metacardsToUpdate.put(item.getMetacard().getId(), item.getMetacard());
}
final ProcessResource processResource = item.getProcessResource();
TemporaryFileBackedOutputStream tfbos = null;
if (processResource != null && processResource.isModified() && !contentItemsToUpdate.containsKey(getContentItemKey(item.getMetacard(), processResource))) {
try {
tfbos = new TemporaryFileBackedOutputStream();
long numberOfBytes = IOUtils.copyLarge(processResource.getInputStream(), tfbos);
LOGGER.debug("Copied {} bytes to TemporaryFileBackedOutputStream.", numberOfBytes);
ByteSource byteSource = tfbos.asByteSource();
ContentItem contentItem = new ContentItemImpl(item.getMetacard().getId(), processResource.getQualifier(), byteSource, processResource.getMimeType(), processResource.getName(), processResource.getSize(), item.getMetacard());
contentItemsToUpdate.put(getContentItemKey(item.getMetacard(), processResource), contentItem);
tfbosToCleanUp.add(tfbos);
} catch (IOException | RuntimeException e) {
LOGGER.debug("Unable to store process request", e);
if (tfbos != null) {
close(tfbos);
}
}
}
}
storeContentItemUpdates(contentItemsToUpdate, processRequest.getProperties());
storeMetacardUpdates(metacardsToUpdate, processRequest.getProperties());
closeTfbos(tfbosToCleanUp);
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class ExportCommand method doContentExport.
private List<ExportItem> doContentExport(/*Mutable,IO*/
ZipFile zipFile, List<ExportItem> exportedItems) throws ZipException {
List<ExportItem> contentItemsToExport = exportedItems.stream().filter(ei -> ei.getResourceUri() != null).filter(ei -> ei.getResourceUri().getScheme() != null).filter(ei -> ei.getResourceUri().getScheme().startsWith(ContentItem.CONTENT_SCHEME)).filter(ei -> !ei.getMetacardTag().equals("deleted")).filter(ei -> !ei.getMetacardTag().equals("revision") || ei.getResourceUri().getSchemeSpecificPart().equals(ei.getId())).filter(distinctByKey(ei -> ei.getResourceUri().getSchemeSpecificPart())).collect(Collectors.toList());
List<ExportItem> exportedContentItems = new ArrayList<>();
for (ExportItem contentItem : contentItemsToExport) {
ResourceResponse resource;
try {
resource = catalogFramework.getLocalResource(new ResourceRequestByProductUri(contentItem.getResourceUri()));
} catch (IOException | ResourceNotSupportedException e) {
throw new CatalogCommandRuntimeException("Unable to retrieve resource for " + contentItem.getId(), e);
} catch (ResourceNotFoundException e) {
continue;
}
writeToZip(zipFile, contentItem, resource);
exportedContentItems.add(contentItem);
if (!contentItem.getMetacardTag().equals("revision")) {
for (String derivedUri : contentItem.getDerivedUris()) {
URI uri;
try {
uri = new URI(derivedUri);
} catch (URISyntaxException e) {
LOGGER.debug("Uri [{}] is not a valid URI. Derived content will not be included in export", derivedUri);
continue;
}
ResourceResponse derivedResource;
try {
derivedResource = catalogFramework.getLocalResource(new ResourceRequestByProductUri(uri));
} catch (IOException e) {
throw new CatalogCommandRuntimeException("Unable to retrieve resource for " + contentItem.getId(), e);
} catch (ResourceNotFoundException | ResourceNotSupportedException e) {
LOGGER.warn("Could not retreive resource [{}]", uri, e);
console.printf("%sUnable to retrieve resource for export : %s%s%n", Ansi.ansi().fg(Ansi.Color.RED).toString(), uri, Ansi.ansi().reset().toString());
continue;
}
writeToZip(zipFile, contentItem, derivedResource);
}
}
}
return exportedContentItems;
}
Aggregations