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;
});
}
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);
}
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;
}
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);
}
}
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));
}
Aggregations