use of org.sagebionetworks.bridge.sms.SmsMessageProvider 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 org.sagebionetworks.bridge.sms.SmsMessageProvider in project BridgeServer2 by Sage-Bionetworks.
the class AccountWorkflowService method requestPhoneSignIn.
/**
* Request a token to be sent via SMS to the user, that can be used to start a session on the Bridge server.
* Returns the userId, or null if the user doesn't exist.
*/
public String requestPhoneSignIn(SignIn signIn) {
return requestChannelSignIn(PHONE, PHONE_SIGNIN_REQUEST, phoneSignInRequestInMillis, signIn, true, this::getNextPhoneToken, (app, account, token) -> {
// Put a dash in the token so it's easier to enter into the UI. All this should
// eventually come from a template
String formattedToken = token.substring(0, 3) + "-" + token.substring(3, 6);
TemplateRevision revision = templateService.getRevisionForUser(app, SMS_PHONE_SIGN_IN);
SmsMessageProvider provider = new SmsMessageProvider.Builder().withApp(app).withTemplateRevision(revision).withTransactionType().withPhone(signIn.getPhone()).withExpirationPeriod(PHONE_SIGNIN_EXPIRATION_PERIOD, SIGNIN_EXPIRE_IN_SECONDS).withToken(TOKEN_KEY, formattedToken).build();
smsService.sendSmsMessage(account.getId(), provider);
});
}
use of org.sagebionetworks.bridge.sms.SmsMessageProvider 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);
}
use of org.sagebionetworks.bridge.sms.SmsMessageProvider in project BridgeServer2 by Sage-Bionetworks.
the class SmsServiceTest method sendPromotionalSMSMessageOK.
@Test
public void sendPromotionalSMSMessageOK() throws Exception {
// Mock participant service.
when(mockParticipantService.getParticipant(any(), anyString(), eq(false))).thenReturn(PARTICIPANT_WITH_TIME_ZONE);
// Set up test and execute.
SmsMessageProvider provider = new SmsMessageProvider.Builder().withApp(app).withTemplateRevision(REVISION).withPromotionType().withPhone(TestConstants.PHONE).build();
svc.sendSmsMessage(HEALTH_CODE, provider);
ArgumentCaptor<PublishRequest> requestCaptor = ArgumentCaptor.forClass(PublishRequest.class);
verify(mockSnsClient).publish(requestCaptor.capture());
PublishRequest request = requestCaptor.getValue();
assertEquals(request.getPhoneNumber(), TestConstants.PHONE.getNumber());
assertEquals(request.getMessage(), MESSAGE_BODY);
assertEquals(request.getMessageAttributes().get(BridgeConstants.AWS_SMS_TYPE).getStringValue(), "Promotional");
assertEquals(request.getMessageAttributes().get(BridgeConstants.AWS_SMS_SENDER_ID).getStringValue(), APP_SHORT_NAME);
// We log the SMS message to DDB and to health data.
verifyLoggedSmsMessage(HEALTH_CODE, MESSAGE_BODY, SmsType.PROMOTIONAL);
verifyHealthData(PARTICIPANT_WITH_TIME_ZONE, TIME_ZONE, SmsType.PROMOTIONAL, MESSAGE_BODY);
}
use of org.sagebionetworks.bridge.sms.SmsMessageProvider in project BridgeServer2 by Sage-Bionetworks.
the class SmsServiceTest method sendSmsMessage_NoParticipant.
// branch coverage
@Test
public void sendSmsMessage_NoParticipant() throws Exception {
// Mock participant service.
when(mockParticipantService.getParticipant(any(), anyString(), eq(false))).thenReturn(null);
// Set up test and execute.
SmsMessageProvider provider = new SmsMessageProvider.Builder().withApp(app).withTemplateRevision(REVISION).withPromotionType().withPhone(TestConstants.PHONE).build();
svc.sendSmsMessage(null, provider);
// Everything else is verified. Just verified that the sent message contains no health code.
verifyLoggedSmsMessage(null, MESSAGE_BODY, SmsType.PROMOTIONAL);
// We submit no health data.
verify(mockHealthDataService, never()).submitHealthData(any(), any(), any());
}
Aggregations