use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project BridgeServer2 by Sage-Bionetworks.
the class ConsentServiceTest method resendConsentAgreementWithPhoneOK.
@Test
public void resendConsentAgreementWithPhoneOK() throws Exception {
doReturn("asdf.pdf").when(consentService).getSignedConsentUrl();
account.setConsentSignatureHistory(SUBPOP_GUID, ImmutableList.of(CONSENT_SIGNATURE));
TemplateRevision revision = TemplateRevision.create();
revision.setDocumentContent("some test content");
when(templateService.getRevisionForUser(app, TemplateType.SMS_SIGNED_CONSENT)).thenReturn(revision);
consentService.resendConsentAgreement(app, SUBPOP_GUID, PHONE_PARTICIPANT);
verify(smsService).sendSmsMessage(eq(ID), smsProviderCaptor.capture());
ArgumentCaptor<ObjectMetadata> metadataCaptor = ArgumentCaptor.forClass(ObjectMetadata.class);
verify(s3Helper).writeBytesToS3(eq(ConsentService.USERSIGNED_CONSENTS_BUCKET), eq("asdf.pdf"), any(), metadataCaptor.capture());
assertEquals(metadataCaptor.getValue().getSSEAlgorithm(), ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
SmsMessageProvider provider = smsProviderCaptor.getValue();
assertEquals(provider.getPhone(), PHONE_PARTICIPANT.getPhone());
assertEquals(provider.getApp(), app);
assertEquals(provider.getSmsType(), "Transactional");
assertEquals(provider.getTokenMap().get("consentUrl"), SHORT_URL);
assertEquals(provider.getTemplateRevision().getDocumentContent(), revision.getDocumentContent());
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project BridgeServer2 by Sage-Bionetworks.
the class UploadService method uploadComplete.
public void uploadComplete(String appId, UploadCompletionClient completedBy, Upload upload, boolean redrive) {
String uploadId = upload.getUploadId();
// We don't want to kick off upload validation on an upload that already has upload validation.
if (!upload.canBeValidated() && !redrive) {
logger.info(String.format("uploadComplete called for upload %s, which is already complete", uploadId));
return;
}
final String objectId = upload.getObjectId();
ObjectMetadata obj;
try {
Stopwatch stopwatch = Stopwatch.createStarted();
obj = s3Client.getObjectMetadata(uploadBucket, objectId);
logger.info("Finished getting S3 metadata for bucket " + uploadBucket + " key " + objectId + " in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
} catch (AmazonS3Exception ex) {
if (ex.getStatusCode() == 404) {
throw new NotFoundException(ex);
} else {
// Only S3 404s are mapped to 404s. Everything else is an internal server error.
throw new BridgeServiceException(ex);
}
}
String sse = obj.getSSEAlgorithm();
if (!AES_256_SERVER_SIDE_ENCRYPTION.equals(sse)) {
logger.error("Missing S3 server-side encryption (SSE) for presigned upload " + uploadId + ".");
}
try {
uploadDao.uploadComplete(completedBy, upload);
} catch (ConcurrentModificationException ex) {
// The old workflow is the app calls uploadComplete. The new workflow has an S3 trigger to call
// uploadComplete. During the transition, it's very likely that this will be called twice, sometimes
// concurrently. As such, we should log and squelch the ConcurrentModificationException.
logger.info("Concurrent modification of upload " + uploadId + " while marking upload complete");
// and duplicate records.
return;
}
// kick off upload validation
App app = appService.getApp(appId);
if (BridgeUtils.isExporter3Configured(app)) {
exporter3Service.completeUpload(app, upload);
}
// For backwards compatibility, always call Legacy Exporter 2.0. In the future, we may introduce a setting to
// disable this for new apps.
uploadValidationService.validateUpload(appId, upload);
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project BridgeServer2 by Sage-Bionetworks.
the class UploadFileHelperFindValueTest method attachmentFile.
@Test
public void attachmentFile() throws Exception {
// Make field def.
UploadFieldDefinition fieldDef = new UploadFieldDefinition.Builder().withName(FIELD_NAME_FILE).withType(UploadFieldType.ATTACHMENT_V2).build();
// Make file map.
File recordJsonFile = makeFileWithContent(FIELD_NAME_FILE, "dummy content");
Map<String, File> fileMap = ImmutableMap.of(FIELD_NAME_FILE, recordJsonFile);
// Execute
String expectedAttachmentFilename = UPLOAD_ID + '-' + FIELD_NAME_FILE;
JsonNode result = uploadFileHelper.findValueForField(UPLOAD_ID, fileMap, fieldDef, new HashMap<>());
assertEquals(result.textValue(), expectedAttachmentFilename);
// Verify uploaded file
verify(mockS3Helper).writeFileToS3(eq(UploadFileHelper.ATTACHMENT_BUCKET), eq(expectedAttachmentFilename), eq(recordJsonFile), metadataCaptor.capture());
ObjectMetadata metadata = metadataCaptor.getValue();
assertEquals(metadata.getUserMetaDataOf(UploadFileHelper.KEY_CUSTOM_CONTENT_MD5), TestConstants.MOCK_MD5_HEX_ENCODED);
assertEquals(metadata.getSSEAlgorithm(), ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project BridgeServer2 by Sage-Bionetworks.
the class UploadFileHelperTest method uploadBytesAsAttachment.
@Test
public void uploadBytesAsAttachment() throws Exception {
// Execute.
helper.uploadBytesAsAttachment(FILENAME, CONTENT);
// Verify.
ArgumentCaptor<ObjectMetadata> metadataCaptor = ArgumentCaptor.forClass(ObjectMetadata.class);
verify(mockS3Helper).writeBytesToS3(eq(UploadFileHelper.ATTACHMENT_BUCKET), eq(FILENAME), eq(CONTENT), metadataCaptor.capture());
ObjectMetadata metadata = metadataCaptor.getValue();
assertEquals(metadata.getUserMetaDataOf(UploadFileHelper.KEY_CUSTOM_CONTENT_MD5), TestConstants.MOCK_MD5_HEX_ENCODED);
assertEquals(metadata.getSSEAlgorithm(), ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
}
use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project BridgeServer2 by Sage-Bionetworks.
the class ConsentService method sendConsentViaSMS.
private void sendConsentViaSMS(App app, Subpopulation subpop, StudyParticipant participant, ConsentPdf consentPdf) {
String shortUrl;
try {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
String fileName = getSignedConsentUrl();
DateTime expiresOn = getDownloadExpiration();
s3Helper.writeBytesToS3(USERSIGNED_CONSENTS_BUCKET, fileName, consentPdf.getBytes(), metadata);
URL url = s3Helper.generatePresignedUrl(USERSIGNED_CONSENTS_BUCKET, fileName, expiresOn, HttpMethod.GET);
shortUrl = urlShortenerService.shortenUrl(url.toString(), SIGNED_CONSENT_DOWNLOAD_EXPIRE_IN_SECONDS);
} catch (IOException e) {
throw new BridgeServiceException(e);
}
TemplateRevision revision = templateService.getRevisionForUser(app, SMS_SIGNED_CONSENT);
SmsMessageProvider provider = new SmsMessageProvider.Builder().withApp(app).withPhone(participant.getPhone()).withExpirationPeriod(EXPIRATION_PERIOD_KEY, SIGNED_CONSENT_DOWNLOAD_EXPIRE_IN_SECONDS).withTransactionType().withTemplateRevision(revision).withToken(BridgeConstants.CONSENT_URL, shortUrl).build();
smsService.sendSmsMessage(participant.getId(), provider);
}
Aggregations