use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestResourceUsagePlugin method getMockRemoteResourceResponseNoRemoteDestinationKey.
private ResourceResponse getMockRemoteResourceResponseNoRemoteDestinationKey(String resourceSize, String expectedUsername) {
setSubject(expectedUsername);
ResourceResponse resourceResponse = getMockResourceResponse(resourceSize, expectedUsername);
when(resourceResponse.hasProperties()).thenReturn(true);
return resourceResponse;
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestResourceUsagePlugin method testPostResourcePersistenceException.
@Test
public void testPostResourcePersistenceException() throws StopProcessingException, PluginExecutionException, PersistenceException {
doThrow(PersistenceException.class).when(attributeStore).updateUserDataUsage(anyString(), anyLong());
ResourceResponse resourceResponse = getMockLocalResourceResponse(RESOURCE_SIZE, TEST_USER);
ResourceResponse response = plugin.process(resourceResponse);
assertThat(response, notNullValue());
assertThat(response, is(resourceResponse));
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestResourceUsagePlugin method testPostResourceLocalSourceNoLocalMonitoring.
@Test
public void testPostResourceLocalSourceNoLocalMonitoring() throws StopProcessingException, PluginExecutionException, PersistenceException {
plugin.setMonitorLocalSources(false);
ResourceResponse originalResponse = getMockLocalResourceResponse(RESOURCE_SIZE, TEST_USER);
ResourceResponse response = plugin.process(originalResponse);
assertThat(response, is(notNullValue()));
assertThat(response, is(originalResponse));
verify(attributeStore, never()).getDataLimitByUser(anyString());
verify(attributeStore, never()).getCurrentDataUsageByUser(anyString());
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class ProcessingPostIngestPlugin method getProcessResource.
private ProcessResource getProcessResource(Metacard metacard, Subject subject) {
LOGGER.trace("Attempting to retrieve process resource metacard with id \"{}\" and sourceId \"{}\".", metacard.getId(), metacard.getSourceId());
ResourceRequest request = new ResourceRequestById(metacard.getId());
if (subject == null) {
LOGGER.debug("No available subject to fetch metacard resource. Returning null");
return null;
}
return subject.execute(() -> {
try {
ResourceResponse response = catalogFramework.getResource(request, metacard.getSourceId());
Resource resource = response.getResource();
ProcessResource processResource = new ProcessResourceImpl(metacard.getId(), resource.getInputStream(), resource.getMimeTypeValue(), resource.getName(), resource.getSize(), false);
return processResource;
} catch (IOException | ResourceNotFoundException | ResourceNotSupportedException | RuntimeException e) {
LOGGER.debug("Unable to get resource id:{}, sourceId:{}. Returning null", metacard.getId(), metacard.getSourceId(), e);
}
return null;
});
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class ExportCommand method doContentExport.
private List<ExportItem> doContentExport(/*Mutable,IO*/
ZipFile zipFile, List<ExportItem> exportedItems) throws ZipException {
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")).filter(ei -> !ei.getMetacardTag().equals("revision") || 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;
}
writeToZip(zipFile, contentItem, resource);
exportedContentItems.add(contentItem);
if (!contentItem.getMetacardTag().equals("revision")) {
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;
}
writeToZip(zipFile, contentItem, derivedResource);
}
}
}
return exportedContentItems;
}
Aggregations