use of ddf.catalog.content.operation.impl.ReadStorageRequestImpl in project ddf by codice.
the class FileSystemStorageProviderTest method assertReadRequest.
private void assertReadRequest(String uriString, String mimeType, boolean extension) throws StorageException, IOException, URISyntaxException {
final URI uri = new URI(uriString);
ReadStorageRequest readRequest = new ReadStorageRequestImpl(uri, Collections.emptyMap());
ReadStorageResponse readResponse = provider.read(readRequest);
ContentItem item = readResponse.getContentItem();
LOGGER.debug("Item retrieved: {}", item);
assertThat(item, notNullValue());
assertThat(item.getId(), is(uri.getSchemeSpecificPart()));
if (uri.getFragment() != null) {
assertThat(item.getQualifier(), is(uri.getFragment()));
}
if (mimeType.equals(NITF_MIME_TYPE)) {
assertThat(item.getMimeTypeRawData(), is(NITF_MIME_TYPE));
}
List<String> parts = provider.getContentFilePathParts(uri.getSchemeSpecificPart(), uri.getFragment());
String expectedFilePath = baseDir + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_REPOSITORY + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_STORE + File.separator + parts.get(0) + File.separator + parts.get(1) + File.separator + parts.get(2) + (StringUtils.isNotBlank(item.getQualifier()) ? File.separator + item.getQualifier() : "") + File.separator + item.getFilename();
if (extension) {
expectedFilePath = expectedFilePath + "." + FileSystemStorageProvider.REF_EXT;
}
assertThat(Files.exists(Paths.get(expectedFilePath)), is(true));
assertTrue(item.getSize() > 0);
}
use of ddf.catalog.content.operation.impl.ReadStorageRequestImpl 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.content.operation.impl.ReadStorageRequestImpl in project ddf by codice.
the class FileSystemStorageProviderTest method testReadDeletedReference.
@Test(expected = StorageException.class)
public void testReadDeletedReference() throws Exception {
Path tempFile = Files.createTempFile("test", "nitf");
Files.write(tempFile, TEST_INPUT_CONTENTS.getBytes());
CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, Collections.singletonMap(Constants.STORE_REFERENCE_KEY, tempFile.toUri().toASCIIString()));
URI uri = new URI(createResponse.getCreatedContentItems().get(0).getUri());
ReadStorageResponse read = provider.read(new ReadStorageRequestImpl(uri, Collections.emptyMap()));
assertThat(read.getContentItem(), notNullValue());
Files.delete(tempFile);
provider.read(new ReadStorageRequestImpl(uri, Collections.emptyMap()));
}
use of ddf.catalog.content.operation.impl.ReadStorageRequestImpl in project ddf by codice.
the class FileSystemStorageProviderTest method assertReadRequest.
private void assertReadRequest(String uriString, String mimeType) throws StorageException, IOException, URISyntaxException {
final URI uri = new URI(uriString);
ReadStorageRequest readRequest = new ReadStorageRequestImpl(uri, Collections.emptyMap());
ReadStorageResponse readResponse = provider.read(readRequest);
ContentItem item = readResponse.getContentItem();
LOGGER.debug("Item retrieved: {}", item);
assertThat(item, notNullValue());
assertThat(item.getId(), is(uri.getSchemeSpecificPart()));
if (uri.getFragment() != null) {
assertThat(item.getQualifier(), is(uri.getFragment()));
}
if (mimeType.equals(NITF_MIME_TYPE)) {
assertThat(item.getMimeTypeRawData(), is(NITF_MIME_TYPE));
}
List<String> parts = provider.getContentFilePathParts(uri.getSchemeSpecificPart(), uri.getFragment());
String expectedFilePath = baseDir + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_REPOSITORY + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_STORE + File.separator + parts.get(0) + File.separator + parts.get(1) + File.separator + parts.get(2) + (StringUtils.isNotBlank(item.getQualifier()) ? File.separator + item.getQualifier() : "") + File.separator + item.getFilename();
assertThat(Files.exists(Paths.get(expectedFilePath)), is(true));
assertTrue(item.getSize() > 0);
}
use of ddf.catalog.content.operation.impl.ReadStorageRequestImpl in project ddf by codice.
the class FileSystemStorageProviderTest method testRollback.
@Test(expected = StorageException.class)
public void testRollback() throws Exception {
String id = UUID.randomUUID().toString().replaceAll("-", "");
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream(TEST_INPUT_CONTENTS, StandardCharsets.UTF_8);
}
};
Metacard metacard = mock(Metacard.class);
when(metacard.getId()).thenReturn(id);
ContentItem contentItem = new ContentItemImpl(id, byteSource, NITF_MIME_TYPE, TEST_INPUT_FILENAME, TEST_INPUT_CONTENTS.getBytes().length, metacard);
CreateStorageRequest createRequest = new CreateStorageRequestImpl(Collections.singletonList(contentItem), null);
CreateStorageResponse createStorageResponse = provider.create(createRequest);
provider.rollback(createRequest);
ReadStorageRequest readStorageRequest = new ReadStorageRequestImpl(new URI("content:" + id), null);
ReadStorageResponse read = provider.read(readStorageRequest);
}
Aggregations