Search in sources :

Example 11 with Resource

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;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) Resource(ddf.catalog.resource.Resource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 12 with Resource

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);
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CatalogFramework(ddf.catalog.CatalogFramework) Resource(ddf.catalog.resource.Resource) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 13 with Resource

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());
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Resource(ddf.catalog.resource.Resource)

Example 14 with Resource

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");
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) Resource(ddf.catalog.resource.Resource) ResourceRequest(ddf.catalog.operation.ResourceRequest)

Example 15 with Resource

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);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Resource(ddf.catalog.resource.Resource)

Aggregations

Resource (ddf.catalog.resource.Resource)59 ResourceResponse (ddf.catalog.operation.ResourceResponse)29 Test (org.junit.Test)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 ResourceRequest (ddf.catalog.operation.ResourceRequest)14 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 URI (java.net.URI)11 HashMap (java.util.HashMap)11 InputStream (java.io.InputStream)10 Serializable (java.io.Serializable)10 MimeType (javax.activation.MimeType)10 Result (ddf.catalog.data.Result)9 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)9 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)9 IOException (java.io.IOException)9 Map (java.util.Map)9 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)8 Metacard (ddf.catalog.data.Metacard)7