Search in sources :

Example 21 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project BridgeServer2 by Sage-Bionetworks.

the class UploadServiceTest method uploadCompleteConcurrentModificationException.

@Test
public void uploadCompleteConcurrentModificationException() throws Exception {
    UploadRequest uploadRequest = constructUploadRequest();
    DynamoUpload2 upload = new DynamoUpload2(uploadRequest, HEALTH_CODE);
    upload.setUploadId(ORIGINAL_UPLOAD_ID);
    upload.setRecordId(RECORD_ID);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setSSEAlgorithm(AES_256_SERVER_SIDE_ENCRYPTION);
    when(mockS3Client.getObjectMetadata(UPLOAD_BUCKET_NAME, ORIGINAL_UPLOAD_ID)).thenReturn(metadata);
    doThrow(new ConcurrentModificationException("error")).when(mockUploadDao).uploadComplete(S3_WORKER, upload);
    svc.uploadComplete(TEST_APP_ID, S3_WORKER, upload, true);
    verify(mockUploadDao).uploadComplete(S3_WORKER, upload);
    verify(mockUploadValidationService, never()).validateUpload(TEST_APP_ID, upload);
}
Also used : ConcurrentModificationException(org.sagebionetworks.bridge.exceptions.ConcurrentModificationException) UploadRequest(org.sagebionetworks.bridge.models.upload.UploadRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) Test(org.testng.annotations.Test)

Example 22 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project BridgeServer2 by Sage-Bionetworks.

the class UploadServiceTest method uploadComplete.

@Test
public void uploadComplete() throws Exception {
    App app = App.create();
    app.setExporter3Enabled(false);
    when(mockAppService.getApp(TEST_APP_ID)).thenReturn(app);
    UploadRequest uploadRequest = constructUploadRequest();
    DynamoUpload2 upload = new DynamoUpload2(uploadRequest, HEALTH_CODE);
    upload.setUploadId(ORIGINAL_UPLOAD_ID);
    upload.setRecordId(RECORD_ID);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setSSEAlgorithm(AES_256_SERVER_SIDE_ENCRYPTION);
    when(mockS3Client.getObjectMetadata(UPLOAD_BUCKET_NAME, ORIGINAL_UPLOAD_ID)).thenReturn(metadata);
    svc.uploadComplete(TEST_APP_ID, S3_WORKER, upload, true);
    verify(mockUploadDao).uploadComplete(S3_WORKER, upload);
    verify(mockUploadValidationService).validateUpload(TEST_APP_ID, upload);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) UploadRequest(org.sagebionetworks.bridge.models.upload.UploadRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DynamoUpload2(org.sagebionetworks.bridge.dynamodb.DynamoUpload2) Test(org.testng.annotations.Test)

Example 23 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project BridgeServer2 by Sage-Bionetworks.

the class HibernateTemplateRevisionDao method createTemplateRevision.

@Override
public void createTemplateRevision(TemplateRevision revision) {
    checkNotNull(revision);
    try {
        String storagePath = getStoragePath(revision.getTemplateGuid(), revision.getCreatedOn());
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setSSEAlgorithm(AES_256_SERVER_SIDE_ENCRYPTION);
        s3Helper.writeBytesToS3(publicationsBucket, storagePath, revision.getDocumentContent().getBytes(defaultCharset()), metadata);
    } catch (IOException ioe) {
        throw new BridgeServiceException("Error persisting template revision document", ioe);
    }
    hibernateHelper.create(revision);
}
Also used : BridgeServiceException(org.sagebionetworks.bridge.exceptions.BridgeServiceException) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 24 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project quality-measure-and-cohort-service by Alvearie.

the class ValueSetImporter method putToS3.

private static void putToS3(ValueSetImporterArguments arguments, FhirContext fhirContext, ValueSet vs, String vsFileName, AmazonS3 S3Client) {
    ObjectMetadata metadata = new ObjectMetadata();
    byte[] arr = fhirContext.newJsonParser().encodeResourceToString(vs).getBytes();
    metadata.setContentLength(arr.length);
    PutObjectRequest put = new PutObjectRequest(arguments.bucket, vsFileName, new ByteArrayInputStream(arr), metadata);
    S3Client.putObject(put);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 25 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project refonte-implicaction by dyno-nuggets.

the class S3CloudServiceImpl method uploadFile.

@Override
public FileModel uploadFile(MultipartFile file) {
    final String originalFilename = file.getOriginalFilename();
    final String filenameExtension = StringUtils.getFilenameExtension(originalFilename);
    final String key = UUID.randomUUID() + filenameExtension;
    final ObjectMetadata metadata = new ObjectMetadata();
    final long fileSize = file.getSize();
    final String contentType = file.getContentType();
    metadata.setContentLength(fileSize);
    metadata.setContentType(contentType);
    try {
        if (!client.doesBucketExist(BUCKET_NAME)) {
            client.createBucket(BUCKET_NAME);
        }
        client.putObject(BUCKET_NAME, key, file.getInputStream(), metadata);
        client.setObjectAcl(BUCKET_NAME, key, CannedAccessControlList.PublicRead);
        return FileModel.builder().filename(file.getOriginalFilename()).contentType(contentType).url(client.getResourceUrl(BUCKET_NAME, key)).objectKey(key).build();
    } catch (IOException exception) {
        throw new ResponseStatusException(INTERNAL_SERVER_ERROR, String.format(UNKNOWN_FILE_UPLOAD_MESSAGE, originalFilename));
    }
}
Also used : IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) ResponseStatusException(org.springframework.web.server.ResponseStatusException)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)566 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)191 ByteArrayInputStream (java.io.ByteArrayInputStream)157 Test (org.junit.Test)143 IOException (java.io.IOException)101 InputStream (java.io.InputStream)80 File (java.io.File)62 AmazonClientException (com.amazonaws.AmazonClientException)61 AmazonServiceException (com.amazonaws.AmazonServiceException)61 S3Object (com.amazonaws.services.s3.model.S3Object)59 AmazonS3 (com.amazonaws.services.s3.AmazonS3)54 Date (java.util.Date)46 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)34 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)33 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)32 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)30 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)29 Upload (com.amazonaws.services.s3.transfer.Upload)26 SdkClientException (com.amazonaws.SdkClientException)24 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)24