use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class ContentResourceReader method retrieveResource.
@Override
public ResourceResponse retrieveResource(URI resourceUri, Map<String, Serializable> arguments) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
LOGGER.trace("ENTERING: retrieveResource");
ResourceResponse response = null;
if (resourceUri == null) {
throw new ResourceNotFoundException("Unable to find resource - resource URI was null");
}
if (resourceUri.getScheme().equals(ContentItem.CONTENT_SCHEME)) {
LOGGER.debug("Resource URI is content scheme");
String contentId = resourceUri.getSchemeSpecificPart();
if (contentId != null && !contentId.isEmpty()) {
if (arguments != null && arguments.get(ContentItem.QUALIFIER_KEYWORD) instanceof String && StringUtils.isNotBlank((String) arguments.get(ContentItem.QUALIFIER_KEYWORD))) {
try {
resourceUri = new URI(resourceUri.getScheme(), resourceUri.getSchemeSpecificPart(), (String) arguments.get(ContentItem.QUALIFIER_KEYWORD));
} catch (URISyntaxException e) {
throw new ResourceNotFoundException("Unable to create with qualifier", e);
}
}
ReadStorageRequest readRequest = new ReadStorageRequestImpl(resourceUri, arguments);
try {
ReadStorageResponse readResponse = storage.read(readRequest);
ContentItem contentItem = readResponse.getContentItem();
String fileName = contentItem.getFilename();
LOGGER.debug("resource name: {}", fileName);
InputStream is = contentItem.getInputStream();
response = new ResourceResponseImpl(new ResourceImpl(new BufferedInputStream(is), contentItem.getMimeType(), fileName));
} catch (StorageException e) {
throw new ResourceNotFoundException(e);
}
}
}
LOGGER.trace("EXITING: retrieveResource");
return response;
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestResourceUsagePlugin method testPostResourceRemoteSourceFalseRemoteDestinationKey.
@Test
public void testPostResourceRemoteSourceFalseRemoteDestinationKey() throws Exception {
plugin.setMonitorLocalSources(false);
ResourceResponse originalResponse = getMockRemoteResourceResponseFalseRemoteDestinationKey(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 TestResourceUsagePlugin method testPostResourceRemoteSourceValidSize.
@Test
public void testPostResourceRemoteSourceValidSize() throws Exception {
plugin.setMonitorLocalSources(false);
ArgumentCaptor<String> usernameArg = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Long> dataUsage = ArgumentCaptor.forClass(Long.class);
ResourceResponse originalResponse = getMockRemoteResourceResponse(RESOURCE_SIZE, TEST_USER);
ResourceResponse response = plugin.process(originalResponse);
assertThat(response, notNullValue());
assertThat(response, is(originalResponse));
verify(attributeStore).updateUserDataUsage(usernameArg.capture(), dataUsage.capture());
assertThat(usernameArg.getValue(), is(TEST_USER));
assertThat(dataUsage.getValue(), is(Long.valueOf(RESOURCE_SIZE)));
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestResourceUsagePlugin method getMockRemoteResourceResponseFalseRemoteDestinationKey.
private ResourceResponse getMockRemoteResourceResponseFalseRemoteDestinationKey(String resourceSize, String expectedUsername) {
setSubject(expectedUsername);
ResourceResponse resourceResponse = getMockResourceResponse(resourceSize, expectedUsername);
when(resourceResponse.getPropertyValue(Constants.REMOTE_DESTINATION_KEY)).thenReturn(false);
when(resourceResponse.hasProperties()).thenReturn(true);
return resourceResponse;
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestResourceUsagePlugin method getMockResourceResponse.
private ResourceResponse getMockResourceResponse(String resourceSize, String expectedUsername) {
setSubject(expectedUsername);
ResourceResponse resourceResponse = mock(ResourceResponse.class);
Map<String, Serializable> responseProperties = new HashMap<>();
responseProperties.put(SecurityConstants.SECURITY_SUBJECT, subject);
responseProperties.put(Metacard.RESOURCE_SIZE, resourceSize);
when(resourceResponse.getPropertyNames()).thenReturn(responseProperties.keySet());
when(resourceResponse.getPropertyValue(SecurityConstants.SECURITY_SUBJECT)).thenReturn(subject);
when(resourceResponse.getPropertyValue(Metacard.RESOURCE_SIZE)).thenReturn(resourceSize);
return resourceResponse;
}
Aggregations