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());
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations