Search in sources :

Example 11 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata in project hippo by NHS-digital-website.

the class ResourceUploadPlugin method handleUpload.

/**
 * Handles the file upload from the form.
 *
 * @param upload the {@link FileUpload} containing the upload information
 */
private void handleUpload(FileUpload upload) throws FileUploadViolationException {
    final PooledS3Connector s3Connector = HippoServiceRegistry.getService(PooledS3Connector.class);
    String fileName = upload.getClientFileName();
    String mimeType = upload.getContentType();
    try {
        final S3ObjectMetadata s3ObjectMetadata = s3Connector.upload(wrapCheckedException(upload::getInputStream), fileName, mimeType);
        JcrNodeModel nodeModel = (JcrNodeModel) this.getDefaultModel();
        Node node = nodeModel.getNode();
        try {
            setResourceProperties(node, s3ObjectMetadata);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    } catch (Exception ex) {
        log.error("Cannot upload resource", ex);
        throw new FileUploadViolationException(ex.getMessage());
    }
}
Also used : PooledS3Connector(uk.nhs.digital.externalstorage.s3.PooledS3Connector) FileUploadViolationException(org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException) Node(javax.jcr.Node) S3ObjectMetadata(uk.nhs.digital.externalstorage.s3.S3ObjectMetadata) JcrNodeModel(org.hippoecm.frontend.model.JcrNodeModel) FileUploadViolationException(org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException) RepositoryException(javax.jcr.RepositoryException) PooledS3Connector.wrapCheckedException(uk.nhs.digital.externalstorage.s3.PooledS3Connector.wrapCheckedException)

Example 12 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata in project hippo by NHS-digital-website.

the class ExternalFileCopyTaskTest method newResourceNode.

private Node newResourceNode(final Node copiedDocUnpublishedVariant, final String pathSuffix, final String oldS3ObjectReference, final String newS3ObjectReference, final String newS3ObjectUrl, final String fileName) throws RepositoryException {
    final Node copiedDocExtResourceNodeA = copiedDocUnpublishedVariant.addNode("copied-doc-ext-attachment" + pathSuffix, "publicationsystem:extattachment").addNode("copied-doc-ext-resource", "externalstorage:resource");
    copiedDocExtResourceNodeA.setProperty(PROPERTY_EXTERNAL_STORAGE_FILE_NAME, fileName);
    copiedDocExtResourceNodeA.setProperty(PROPERTY_EXTERNAL_STORAGE_REFERENCE, oldS3ObjectReference);
    final S3ObjectMetadata s3ObjectMetadataA = mock(S3ObjectMetadata.class);
    given(s3ObjectMetadataA.getReference()).willReturn(newS3ObjectReference);
    given(s3ObjectMetadataA.getUrl()).willReturn(newS3ObjectUrl);
    given(s3Connector.copyFile(oldS3ObjectReference, fileName)).willReturn(s3ObjectMetadataA);
    return copiedDocExtResourceNodeA;
}
Also used : Node(javax.jcr.Node) S3ObjectMetadata(uk.nhs.digital.externalstorage.s3.S3ObjectMetadata)

Example 13 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata in project hippo by NHS-digital-website.

the class S3StorageManagerTest method shouldNotBeAbleToUploadNonS3File.

@Test
public void shouldNotBeAbleToUploadNonS3File() {
    S3StorageManager sm = new S3StorageManager(mockPooledS3Connector);
    S3ObjectMetadata meta = sm.uploadFileToS3(HTTP_SOURCE_BUCKET, OBJECT_FOLDER_OBJECT_KEY);
    assertNull(meta);
}
Also used : S3ObjectMetadata(uk.nhs.digital.externalstorage.s3.S3ObjectMetadata) Test(org.junit.Test)

Example 14 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata in project hippo by NHS-digital-website.

the class S3StorageManagerTest method shouldNotBeAbleToUploadS3FileThatDoesNonExistInSourceBucket.

@Test
public void shouldNotBeAbleToUploadS3FileThatDoesNonExistInSourceBucket() {
    S3StorageManager sm = new S3StorageManager(mockPooledS3Connector);
    when(mockPooledS3Connector.doesObjectExist(SOURCE_BUCKET, OBJECT_FOLDER_OBJECT_KEY_2)).thenReturn(false);
    S3ObjectMetadata meta = sm.uploadFileToS3(S3_SOURCE_BUCKET, OBJECT_FOLDER_OBJECT_KEY_2);
    assertNull(meta);
    verify(mockPooledS3Connector, times(1)).doesObjectExist(SOURCE_BUCKET, OBJECT_FOLDER_OBJECT_KEY_2);
    verifyNoMoreInteractions(mockPooledS3Connector);
}
Also used : S3ObjectMetadata(uk.nhs.digital.externalstorage.s3.S3ObjectMetadata) Test(org.junit.Test)

Example 15 with S3ObjectMetadata

use of com.formkiq.aws.s3.S3ObjectMetadata in project hippo by NHS-digital-website.

the class S3StorageManagerTest method shouldBeAbleToUploadS3FileThatDoesExistInSourceBucket.

@Test
public void shouldBeAbleToUploadS3FileThatDoesExistInSourceBucket() {
    S3StorageManager sm = new S3StorageManager(mockPooledS3Connector);
    // given
    when(mockPooledS3Connector.doesObjectExist(SOURCE_BUCKET, OBJECT_FOLDER_OBJECT_KEY)).thenReturn(true);
    when(mockObjectKeyGenerator.generateObjectKey(OBJECT_KEY)).thenReturn(XYZ_OBJECT_KEY);
    when(mockPooledS3Connector.copyFileFromOtherBucket(OBJECT_FOLDER_OBJECT_KEY, SOURCE_BUCKET, OBJECT_KEY)).thenReturn(mockMetaData);
    // when
    S3ObjectMetadata meta = sm.uploadFileToS3(S3_SOURCE_BUCKET, OBJECT_FOLDER_OBJECT_KEY);
    // then
    assertNotNull(meta);
}
Also used : S3ObjectMetadata(uk.nhs.digital.externalstorage.s3.S3ObjectMetadata) Test(org.junit.Test)

Aggregations

S3ObjectMetadata (com.emc.object.s3.S3ObjectMetadata)16 S3Exception (com.emc.object.s3.S3Exception)7 S3ObjectMetadata (com.formkiq.aws.s3.S3ObjectMetadata)7 S3ObjectMetadata (uk.nhs.digital.externalstorage.s3.S3ObjectMetadata)7 S3Client (software.amazon.awssdk.services.s3.S3Client)5 AccessControlList (com.emc.object.s3.bean.AccessControlList)4 PutObjectRequest (com.emc.object.s3.request.PutObjectRequest)4 Test (org.junit.Test)4 CopyPartResult (com.emc.object.s3.bean.CopyPartResult)3 MultipartPartETag (com.emc.object.s3.bean.MultipartPartETag)3 PutObjectResult (com.emc.object.s3.bean.PutObjectResult)3 CompleteMultipartUploadRequest (com.emc.object.s3.request.CompleteMultipartUploadRequest)3 CopyPartRequest (com.emc.object.s3.request.CopyPartRequest)3 ChunkAlreadyExistsException (io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException)3 ChunkNotFoundException (io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException)3 ChunkStorageException (io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)3 InvalidOffsetException (io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException)3 Date (java.util.Date)3 TreeSet (java.util.TreeSet)3 CanonicalUser (com.emc.object.s3.bean.CanonicalUser)2