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