Search in sources :

Example 1 with ContentItem

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);
}
Also used : CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Example 2 with ContentItem

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);
}
Also used : ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem)

Example 3 with ContentItem

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Map(java.util.Map) ContentItem(ddf.catalog.content.data.ContentItem)

Example 4 with ContentItem

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);
}
Also used : TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessResource(org.codice.ddf.catalog.async.data.api.internal.ProcessResource) IOException(java.io.IOException) Metacard(ddf.catalog.data.Metacard) ByteSource(com.google.common.io.ByteSource) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Example 5 with ContentItem

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;
}
Also used : Ansi(org.fusesource.jansi.Ansi) StringUtils(org.apache.commons.lang.StringUtils) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) BinaryContent(ddf.catalog.data.BinaryContent) LoggerFactory(org.slf4j.LoggerFactory) SecurityLogger(ddf.security.common.audit.SecurityLogger) Command(org.apache.karaf.shell.api.action.Command) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) MetacardVersion(ddf.catalog.core.versioning.MetacardVersion) Map(java.util.Map) ExportItem(org.codice.ddf.commands.catalog.export.ExportItem) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) URI(java.net.URI) ParseException(java.text.ParseException) ZipFile(net.lingala.zip4j.core.ZipFile) TimeZone(java.util.TimeZone) Predicate(java.util.function.Predicate) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Objects(java.util.Objects) ZipException(net.lingala.zip4j.exception.ZipException) StorageException(ddf.catalog.content.StorageException) List(java.util.List) FilenameUtils(org.apache.commons.io.FilenameUtils) ResourceResponse(ddf.catalog.operation.ResourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SimpleDateFormat(java.text.SimpleDateFormat) CatalogCommandRuntimeException(org.codice.ddf.commands.util.CatalogCommandRuntimeException) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Reference(org.apache.karaf.shell.api.action.lifecycle.Reference) SortBy(org.opengis.filter.sort.SortBy) ContentItem(ddf.catalog.content.data.ContentItem) Metacard(ddf.catalog.data.Metacard) CQLException(org.geotools.filter.text.cql2.CQLException) StorageProvider(ddf.catalog.content.StorageProvider) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) ZipParameters(net.lingala.zip4j.model.ZipParameters) QueryResultIterable(org.codice.ddf.commands.util.QueryResultIterable) IngestException(ddf.catalog.source.IngestException) ResourceRequestByProductUri(ddf.catalog.operation.impl.ResourceRequestByProductUri) IOException(java.io.IOException) IdAndUriMetacard(org.codice.ddf.commands.catalog.export.IdAndUriMetacard) File(java.io.File) JarSigner(org.codice.ddf.catalog.transformer.zip.JarSigner) TimeUnit(java.util.concurrent.TimeUnit) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) Paths(java.nio.file.Paths) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Filter(org.opengis.filter.Filter) Option(org.apache.karaf.shell.api.action.Option) Collections(java.util.Collections) ExportItem(org.codice.ddf.commands.catalog.export.ExportItem) ArrayList(java.util.ArrayList) CatalogCommandRuntimeException(org.codice.ddf.commands.util.CatalogCommandRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ResourceRequestByProductUri(ddf.catalog.operation.impl.ResourceRequestByProductUri) URI(java.net.URI) ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Aggregations

ContentItem (ddf.catalog.content.data.ContentItem)92 Test (org.junit.Test)51 Metacard (ddf.catalog.data.Metacard)44 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)31 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)30 ArrayList (java.util.ArrayList)29 IOException (java.io.IOException)21 HashMap (java.util.HashMap)21 ByteSource (com.google.common.io.ByteSource)20 URI (java.net.URI)20 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)17 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)16 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)16 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 InputStream (java.io.InputStream)14 StorageException (ddf.catalog.content.StorageException)13 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)13 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)12 Map (java.util.Map)12 StorageProvider (ddf.catalog.content.StorageProvider)11