Search in sources :

Example 1 with ReadStorageRequestImpl

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);
}
Also used : ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem)

Example 2 with ReadStorageRequestImpl

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) URI(java.net.URI) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) BufferedInputStream(java.io.BufferedInputStream) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem)

Example 3 with ReadStorageRequestImpl

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()));
}
Also used : Path(java.nio.file.Path) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) URI(java.net.URI) Test(org.junit.Test)

Example 4 with ReadStorageRequestImpl

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);
}
Also used : ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem)

Example 5 with ReadStorageRequestImpl

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);
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Metacard(ddf.catalog.data.Metacard) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ByteSource(com.google.common.io.ByteSource) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Aggregations

ReadStorageRequestImpl (ddf.catalog.content.operation.impl.ReadStorageRequestImpl)6 URI (java.net.URI)6 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)5 ContentItem (ddf.catalog.content.data.ContentItem)4 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)4 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)3 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)3 Test (org.junit.Test)3 ByteSource (com.google.common.io.ByteSource)1 StorageException (ddf.catalog.content.StorageException)1 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)1 Metacard (ddf.catalog.data.Metacard)1 ResourceResponse (ddf.catalog.operation.ResourceResponse)1 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)1 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)1 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1