Search in sources :

Example 6 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class ResourceOperations method getOptionsFromFederatedSource.

/**
     * Get the supported options from the {@link ResourceReader} that matches the scheme in the
     * specified {@link Metacard}'s URI. Only look in the specified source for the {@link Metacard}.
     *
     * @param metacard the {@link Metacard} to get the supported options for
     * @param sourceId the ID of the federated source to look for the {@link Metacard}
     * @return the {@link Set} of supported options for the metacard
     * @throws ResourceNotFoundException if the {@link ddf.catalog.source.Source} cannot be found for the source ID
     */
@Deprecated
private Set<String> getOptionsFromFederatedSource(Metacard metacard, String sourceId) throws ResourceNotFoundException {
    LOGGER.trace("ENTERING: getOptionsFromFederatedSource");
    FederatedSource source = frameworkProperties.getFederatedSources().get(sourceId);
    if (source != null) {
        LOGGER.trace("EXITING: getOptionsFromFederatedSource");
        return source.getOptions(metacard);
    } else {
        String message = "Unable to find source corresponding to given site name: " + sourceId;
        LOGGER.trace("EXITING: getOptionsFromFederatedSource");
        throw new ResourceNotFoundException(message);
    }
}
Also used : FederatedSource(ddf.catalog.source.FederatedSource) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 7 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class ProcessingPostIngestPlugin method getProcessResource.

private ProcessResource getProcessResource(Metacard metacard, Subject subject) {
    LOGGER.trace("Attempting to retrieve process resource metacard with id \"{}\" and sourceId \"{}\".", metacard.getId(), metacard.getSourceId());
    ResourceRequest request = new ResourceRequestById(metacard.getId());
    if (subject == null) {
        LOGGER.debug("No available subject to fetch metacard resource. Returning null");
        return null;
    }
    return subject.execute(() -> {
        try {
            ResourceResponse response = catalogFramework.getResource(request, metacard.getSourceId());
            Resource resource = response.getResource();
            ProcessResource processResource = new ProcessResourceImpl(metacard.getId(), resource.getInputStream(), resource.getMimeTypeValue(), resource.getName(), resource.getSize(), false);
            return processResource;
        } catch (IOException | ResourceNotFoundException | ResourceNotSupportedException | RuntimeException e) {
            LOGGER.debug("Unable to get resource id:{}, sourceId:{}. Returning null", metacard.getId(), metacard.getSourceId(), e);
        }
        return null;
    });
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) Resource(ddf.catalog.resource.Resource) ProcessResource(org.codice.ddf.catalog.async.data.api.internal.ProcessResource) ProcessResource(org.codice.ddf.catalog.async.data.api.internal.ProcessResource) ResourceRequest(ddf.catalog.operation.ResourceRequest) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) ProcessResourceImpl(org.codice.ddf.catalog.async.data.impl.ProcessResourceImpl)

Example 8 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException 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)

Example 9 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class ZipCompression method getResource.

private Resource getResource(Metacard metacard) {
    Resource resource = null;
    try {
        ResourceRequest resourceRequest = new ResourceRequestById(metacard.getId());
        ResourceResponse resourceResponse = catalogFramework.getLocalResource(resourceRequest);
        resource = resourceResponse.getResource();
    } catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
        LOGGER.debug("Unable to retrieve content from metacard : {}", metacard.getId(), e);
    }
    return resource;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) Resource(ddf.catalog.resource.Resource) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ResourceRequest(ddf.catalog.operation.ResourceRequest) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 10 with ResourceNotFoundException

use of ddf.catalog.resource.ResourceNotFoundException in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testDownloadResourceNotFound.

@Test(expected = DownloadException.class)
public void testDownloadResourceNotFound() throws Exception {
    Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
    resourceRequest = mock(ResourceRequest.class);
    ResourceRetriever retriever = mock(ResourceRetriever.class);
    when(retriever.retrieveResource()).thenThrow(new ResourceNotFoundException());
    downloadMgr.download(resourceRequest, metacard, retriever);
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Test(org.junit.Test)

Aggregations

ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)41 IOException (java.io.IOException)25 ResourceResponse (ddf.catalog.operation.ResourceResponse)17 URI (java.net.URI)16 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)14 Serializable (java.io.Serializable)14 Metacard (ddf.catalog.data.Metacard)13 Test (org.junit.Test)12 HashMap (java.util.HashMap)11 URISyntaxException (java.net.URISyntaxException)10 Result (ddf.catalog.data.Result)8 ResourceRequest (ddf.catalog.operation.ResourceRequest)8 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)8 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)7 Resource (ddf.catalog.resource.Resource)7 QueryRequest (ddf.catalog.operation.QueryRequest)6 QueryResponse (ddf.catalog.operation.QueryResponse)6 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)6 CatalogFramework (ddf.catalog.CatalogFramework)5 FederationException (ddf.catalog.federation.FederationException)5