Search in sources :

Example 46 with Resource

use of ddf.catalog.resource.Resource in project ddf by codice.

the class DumpCommand method getDerivedResources.

@Nullable
private Map.Entry<String, Resource> getDerivedResources(Metacard metacard, Serializable serializable) {
    if (!(serializable instanceof String)) {
        LOGGER.debug("Input ({}) should have been a string but was a {}", serializable, serializable.getClass());
        return null;
    }
    URI uri = null;
    try {
        uri = new URI((String) serializable);
    } catch (URISyntaxException e) {
        LOGGER.debug("Invalid Derived Resource URI Syntax for metacard : {}", metacard.getId(), e);
        return null;
    }
    String derivedResourceFragment = uri.getFragment();
    if (!ContentItem.CONTENT_SCHEME.equals(uri.getScheme()) || StringUtils.isBlank(derivedResourceFragment)) {
        return null;
    }
    String fragment = CONTENT + File.separator + derivedResourceFragment + File.separator;
    Resource resource = getResource(metacard);
    if (resource == null) {
        return null;
    }
    return new SimpleEntry<>(fragment + uri.getSchemeSpecificPart() + "-" + resource.getName(), resource);
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Resource(ddf.catalog.resource.Resource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Nullable(javax.annotation.Nullable)

Example 47 with Resource

use of ddf.catalog.resource.Resource 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;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) Resource(ddf.catalog.resource.Resource) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ResourceRequest(ddf.catalog.operation.ResourceRequest) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 48 with Resource

use of ddf.catalog.resource.Resource in project ddf by codice.

the class ResourceOperationsTest method testGetResourceThrowsDownloadException.

@Test(expected = ResourceNotFoundException.class)
public void testGetResourceThrowsDownloadException() throws Exception {
    ArrayList<Result> mockResultList = new ArrayList<>();
    mockResultList.add(resultMock);
    setGetResourceMocks();
    when(queryResponseMock.getResults()).thenReturn(mockResultList);
    when(queryResponseMock.getResults().get(0).getMetacard()).thenReturn(metacard);
    when(reliableResourceDownloadManagerMock.download(any(ResourceRequest.class), any(MetacardImpl.class), isNull())).thenThrow(DownloadException.class);
    Resource resourceMock = mock(Resource.class);
    when(resourceResponseMock.getResource()).thenReturn(resourceMock);
    frameworkProperties.setReliableResourceDownloadManager(reliableResourceDownloadManagerMock);
    resourceOperations.getResource(resourceRequestMock, isEnterprise, resourceName, fanoutEnabled);
    verify(queryResponseMock).getResults();
    verify(reliableResourceDownloadManagerMock).download(any(ResourceRequest.class), any(MetacardImpl.class), isNull());
}
Also used : ArrayList(java.util.ArrayList) Resource(ddf.catalog.resource.Resource) ResourceRequest(ddf.catalog.operation.ResourceRequest) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 49 with Resource

use of ddf.catalog.resource.Resource in project ddf by codice.

the class ResourceOperationsTest method testValidateFixGetResourceReturnsResourceResponse.

@Test
public void testValidateFixGetResourceReturnsResourceResponse() throws Exception {
    ArrayList<Result> mockResultList = new ArrayList<>();
    mockResultList.add(resultMock);
    setGetResourceMocks();
    when(queryResponseMock.getResults()).thenReturn(mockResultList);
    when(queryResponseMock.getResults().get(0).getMetacard()).thenReturn(metacard);
    when(reliableResourceDownloadManagerMock.download(any(ResourceRequest.class), any(MetacardImpl.class), isNull())).thenReturn(resourceResponseMock);
    Resource resourceMock = mock(Resource.class);
    when(resourceResponseMock.getResource()).thenReturn(resourceMock);
    frameworkProperties.setReliableResourceDownloadManager(reliableResourceDownloadManagerMock);
    resourceOperations.getResource(resourceRequestMock, isEnterprise, resourceName, fanoutEnabled);
}
Also used : ArrayList(java.util.ArrayList) Resource(ddf.catalog.resource.Resource) ResourceRequest(ddf.catalog.operation.ResourceRequest) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 50 with Resource

use of ddf.catalog.resource.Resource in project ddf by codice.

the class URLResourceReaderTest method verifyFile.

private void verifyFile(String filePath, String filename, String expectedMimeType, String... rootResourceDirectories) throws Exception {
    URLResourceReader resourceReader = new URLResourceReader(mimeTypeMapper, clientBuilderFactory);
    resourceReader.setRootResourceDirectories(new HashSet<String>(Arrays.asList(rootResourceDirectories)));
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    LOGGER.info("Getting resource: {}", filePath);
    // Test using the URL ResourceReader
    File file = new File(filePath);
    URI uri = file.toURI();
    LOGGER.info("URI: {}", uri.toString());
    ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);
    Resource resource = resourceResponse.getResource();
    assert (resource != null);
    LOGGER.info("MimeType: {}", resource.getMimeType());
    LOGGER.info("Got resource: {}", resource.getName());
    String name = resource.getName();
    assertNotNull(name);
    assertThat(name, is(filename));
    assertThat(resource.getMimeType().toString(), containsString(expectedMimeType));
}
Also used : Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Resource(ddf.catalog.resource.Resource) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) URI(java.net.URI)

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