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