use of ddf.catalog.operation.ResourceResponse in project alliance by codice.
the class CatalogOutputAdapterTest method testGetImageNullInputStream.
@Test(expected = IllegalStateException.class)
public void testGetImageNullInputStream() throws IOException {
ResourceResponse resourceResponse = mock(ResourceResponse.class);
Resource resource = mock(Resource.class);
when(resourceResponse.getResource()).thenReturn(resource);
when(resource.getInputStream()).thenReturn(null);
catalogOutputAdapter.getImage(resourceResponse);
}
use of ddf.catalog.operation.ResourceResponse in project alliance by codice.
the class DAGConverter method getThumbnail.
private byte[] getThumbnail(String thumbnailUrlStr) {
byte[] thumbnail = null;
try {
URI thumbnailURI = new URI(thumbnailUrlStr);
ResourceResponse resourceResponse = null;
try {
resourceResponse = resourceReader.retrieveResource(thumbnailURI, new HashMap<>());
thumbnail = resourceResponse.getResource().getByteArray();
} catch (ResourceNotSupportedException e) {
LOGGER.debug("Resource is not supported: {} ", thumbnailURI, e);
}
} catch (IOException | ResourceNotFoundException | URISyntaxException e) {
LOGGER.debug("Unable to get thumbnail from URL {}", thumbnailUrlStr, e);
}
return thumbnail;
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class SeedCommandTest method mockResourceResponse.
private ResourceResponse mockResourceResponse() throws IOException {
InputStream mockInputStream = mock(InputStream.class);
doReturn(-1).when(mockInputStream).read(any(byte[].class), anyInt(), anyInt());
Resource mockResource = mock(Resource.class);
when(mockResource.getInputStream()).thenReturn(mockInputStream);
ResourceResponse mockResponse = mock(ResourceResponse.class);
when(mockResponse.getResource()).thenReturn(mockResource);
return mockResponse;
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class ExportCommand method doContentExport.
@SuppressWarnings("squid:S3776")
private List<ExportItem> doContentExport(ZipOutputStream zipOutputStream, List<ExportItem> exportedItems) {
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_METACARD)).filter(ei -> !ei.getMetacardTag().equals(REVISION_METACARD) || 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;
}
writeResourceToZip(zipOutputStream, contentItem, resource);
exportedContentItems.add(contentItem);
if (!contentItem.getMetacardTag().equals(REVISION_METACARD)) {
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;
}
writeResourceToZip(zipOutputStream, contentItem, derivedResource);
}
}
}
return exportedContentItems;
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class DumpCommand 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;
}
Aggregations