use of ddf.catalog.resource.Resource in project ddf by codice.
the class ZipCompression method getAllMetacardContent.
private Map<String, Resource> getAllMetacardContent(Metacard metacard) {
Map<String, Resource> resourceMap = new HashMap<>();
Attribute attribute = metacard.getAttribute(Metacard.DERIVED_RESOURCE_URI);
if (attribute != null) {
List<Serializable> serializables = attribute.getValues();
serializables.forEach(serializable -> {
String fragment = ZipDecompression.CONTENT + File.separator;
URI uri = null;
try {
uri = new URI((String) serializable);
String derivedResourceFragment = uri.getFragment();
if (ContentItem.CONTENT_SCHEME.equals(uri.getScheme()) && StringUtils.isNotBlank(derivedResourceFragment)) {
fragment += derivedResourceFragment + File.separator;
Resource resource = getResource(metacard);
if (resource != null) {
resourceMap.put(fragment + uri.getSchemeSpecificPart() + "-" + resource.getName(), resource);
}
}
} catch (URISyntaxException e) {
LOGGER.debug("Invalid Derived Resource URI Syntax for metacard : {}", metacard.getId(), e);
}
});
}
URI resourceUri = metacard.getResourceURI();
Resource resource = getResource(metacard);
if (resource != null) {
resourceMap.put(ZipDecompression.CONTENT + File.separator + resourceUri.getSchemeSpecificPart() + "-" + resource.getName(), resource);
}
return resourceMap;
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class TestZipCompression method setUp.
@Before
public void setUp() throws Exception {
JarSigner jarSigner = mock(JarSigner.class);
doNothing().when(jarSigner).signJar(any(File.class), anyString(), anyString(), anyString(), anyString());
zipCompression = new ZipCompression(jarSigner);
sourceResponse = createSourceResponseWithURISchemes(null, null);
filePathArgument = new HashMap<>();
filePathArgument.put("filePath", temporaryFolder.getRoot().getAbsolutePath() + File.separator + "signed.zip");
catalogFramework = mock(CatalogFramework.class);
Resource resource = mock(Resource.class);
InputStream resourceFileStream = new FileInputStream(new File(LOCAL_RESOURCE_PATH));
when(resource.getName()).thenReturn(LOCAL_RESOURCE_FILENAME);
when(resource.getInputStream()).thenReturn(resourceFileStream);
ResourceResponse resourceResponse = new ResourceResponseImpl(resource);
when(catalogFramework.getLocalResource(any(ResourceRequestById.class))).thenReturn(resourceResponse);
zipCompression.setCatalogFramework(catalogFramework);
}
use of ddf.catalog.resource.Resource in project alliance by codice.
the class DAGConverterTest method setupMocks.
private void setupMocks() throws Exception {
byte[] testReturn = "TEST RETURN".getBytes();
Resource mockResource = mock(Resource.class);
ResourceResponse mockResponse = mock(ResourceResponse.class);
doReturn(Long.valueOf(testReturn.length)).when(mockResource).getSize();
doReturn(testReturn).when(mockResource).getByteArray();
doReturn(mockResource).when(mockResponse).getResource();
doReturn(mockResponse).when(mockResourceReader).retrieveResource(anyObject(), anyMap());
}
use of ddf.catalog.resource.Resource in project alliance by codice.
the class OrderRequestImpl method requestProductResource.
private void requestProductResource(List<ResourceContainer> files, ProductDetails productDetails) throws UnsupportedEncodingException, WrongAdapter, WrongPolicy, SecurityServiceException {
if (productDetails != null) {
Metacard metacard = accessManager.getMetacard(productDetails.aProduct);
ResourceRequest resourceRequest = new ResourceRequestById(metacard.getId());
ResourceResponse resourceResponse;
ResourceRequestCallable resourceRequestCallable = new ResourceRequestCallable(resourceRequest, metacard.getSourceId());
resourceResponse = NsiliEndpoint.getGuestSubject().execute(resourceRequestCallable);
if (resourceResponse != null && resourceResponse.getResource() != null) {
Resource resource = resourceResponse.getResource();
ResourceContainer file = new ResourceContainer(resource.getInputStream(), resource.getName(), resource.getSize(), resource.getMimeTypeValue(), metacard);
files.add(file);
// Alterations aren't supported, so we will only return original content
}
} else {
LOGGER.debug("Order requested for a null product detail");
}
}
use of ddf.catalog.resource.Resource in project alliance by codice.
the class CatalogOutputAdapter method getImage.
/**
* @param resourceResponse a ResourceResponse object returned by CatalogFramework.
* @return the requested BufferedImage.
* @throws IOException when there's a problem reading the image from the ResourceResponse
* InputStream.
*/
@SuppressWarnings("WeakerAccess")
public BufferedImage getImage(ResourceResponse resourceResponse) throws IOException {
validateArgument(resourceResponse, "resourceResponse");
validateArgument(resourceResponse.getResource(), "resourceResponse.resource");
try (InputStream resourceStream = resourceResponse.getResource().getInputStream()) {
validateObjectState(resourceStream, "resourceResponse.resource.inputStream");
Resource resource = resourceResponse.getResource();
try (InputStream inputStream = resource.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
return ImageIO.read(bufferedInputStream);
}
}
}
Aggregations