Search in sources :

Example 1 with ResourceRequestById

use of ddf.catalog.operation.impl.ResourceRequestById 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 2 with ResourceRequestById

use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.

the class PointOfContactPolicyPluginTest method processPreResourceDoesNothing.

@Test
public void processPreResourceDoesNothing() throws java.lang.Exception {
    PolicyResponse response = pointOfContactPolicyPlugin.processPreResource(new ResourceRequestById(TEST_ID));
    responseIsEmpty(response);
}
Also used : ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Test(org.junit.Test)

Example 3 with ResourceRequestById

use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.

the class CswEndpoint method queryProductById.

private CswRecordCollection queryProductById(String id, String rangeValue) throws CswException, UnsupportedQueryException {
    final ResourceRequestById resourceRequest = new ResourceRequestById(id);
    long bytesToSkip = getRange(rangeValue);
    if (bytesToSkip > 0) {
        LOGGER.debug("Bytes to skip: {}", String.valueOf(bytesToSkip));
        resourceRequest.getProperties().put(CswConstants.BYTES_TO_SKIP, bytesToSkip);
    }
    ResourceResponse resourceResponse;
    try {
        resourceResponse = framework.getLocalResource(resourceRequest);
    } catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
        throw new CswException(String.format(ERROR_ID_PRODUCT_RETRIEVAL, id), e);
    }
    Resource resource = resourceResponse.getResource();
    MimeType mimeType = resource.getMimeType();
    if (mimeType == null) {
        try {
            mimeType = new MimeType(MediaType.APPLICATION_OCTET_STREAM);
            resource = new ResourceImpl(resource.getInputStream(), mimeType, resource.getName());
        } catch (MimeTypeParseException e) {
            throw new CswException(String.format("Could not create mime type upon null mimeType, for mime %s.", MediaType.APPLICATION_OCTET_STREAM), e);
        }
    }
    CswRecordCollection cswRecordCollection = new CswRecordCollection();
    cswRecordCollection.setResource(resource);
    cswRecordCollection.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
    LOGGER.debug("{} successfully retrieved product for ID: {}", id);
    return cswRecordCollection;
}
Also used : MimeTypeParseException(javax.activation.MimeTypeParseException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) Resource(ddf.catalog.resource.Resource) IOException(java.io.IOException) MimeType(javax.activation.MimeType) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 4 with ResourceRequestById

use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.

the class ResourceDownload method copyToLocalSite.

@Override
public void copyToLocalSite(String sourceId, String metacardId) throws MBeanException {
    LOGGER.debug("Downloading resource associated with metacard id [{}] from source [{}] to the local site.", metacardId, sourceId);
    ResourceRequest resourceRequest = new ResourceRequestById(metacardId);
    if (!resourceCacheMBean.isCacheEnabled()) {
        String message = "Caching of resources is not enabled.";
        LOGGER.info(message);
        throw new MBeanException(new DownloadToLocalSiteException(Status.BAD_REQUEST, message), message);
    }
    try {
        LOGGER.debug("Attempting to download the resource associated with metacard [{}] from source [{}] to the local site.", metacardId, sourceId);
        ResourceResponse resourceResponse = catalogFramework.getResource(resourceRequest, sourceId);
        if (resourceResponse == null) {
            String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
            LOGGER.debug(message);
            throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
        }
    } catch (IOException | ResourceNotSupportedException e) {
        String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
        LOGGER.debug(message, e);
        throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
    } catch (ResourceNotFoundException e) {
        String message = String.format(ERROR_MESSAGE_TEMPLATE + " The resource could not be found.", metacardId, sourceId);
        LOGGER.debug(message, e);
        throw new MBeanException(new DownloadToLocalSiteException(Status.NOT_FOUND, message), message);
    }
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ResourceRequest(ddf.catalog.operation.ResourceRequest) DownloadToLocalSiteException(org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 5 with ResourceRequestById

use of ddf.catalog.operation.impl.ResourceRequestById in project ddf by codice.

the class ResourceCacheImplTest method containsSpecificResourceInCache.

@Test
public void containsSpecificResourceInCache() {
    ReliableResource cachedResource = createCachedResource(cachedMetacard);
    resourceCache.put(cachedResource);
    assertThat(newResourceCache.contains(cachedMetacard, new ResourceRequestById(METACARD_ID)), is(true));
}
Also used : ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Aggregations

ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)14 ResourceResponse (ddf.catalog.operation.ResourceResponse)7 ResourceRequest (ddf.catalog.operation.ResourceRequest)6 Resource (ddf.catalog.resource.Resource)6 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)6 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)6 IOException (java.io.IOException)6 Test (org.junit.Test)5 ReliableResource (ddf.catalog.resource.data.ReliableResource)4 Serializable (java.io.Serializable)3 HashMap (java.util.HashMap)3 Attribute (ddf.catalog.data.Attribute)2 Metacard (ddf.catalog.data.Metacard)2 Result (ddf.catalog.data.Result)2 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 PolicyResponse (ddf.catalog.plugin.PolicyResponse)2 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)2 MimeType (javax.activation.MimeType)2 CacheKey (ddf.catalog.cache.impl.CacheKey)1