Search in sources :

Example 1 with SmsMessageProvider

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());
}
Also used : TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) SmsMessageProvider(org.sagebionetworks.bridge.sms.SmsMessageProvider) Test(org.testng.annotations.Test)

Example 2 with SmsMessageProvider

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);
    });
}
Also used : TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) SmsMessageProvider(org.sagebionetworks.bridge.sms.SmsMessageProvider)

Example 3 with SmsMessageProvider

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);
}
Also used : BridgeServiceException(org.sagebionetworks.bridge.exceptions.BridgeServiceException) TemplateRevision(org.sagebionetworks.bridge.models.templates.TemplateRevision) IOException(java.io.IOException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DateTime(org.joda.time.DateTime) URL(java.net.URL) SmsMessageProvider(org.sagebionetworks.bridge.sms.SmsMessageProvider)

Example 4 with SmsMessageProvider

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);
}
Also used : PublishRequest(com.amazonaws.services.sns.model.PublishRequest) SmsMessageProvider(org.sagebionetworks.bridge.sms.SmsMessageProvider) Test(org.testng.annotations.Test)

Example 5 with SmsMessageProvider

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());
}
Also used : SmsMessageProvider(org.sagebionetworks.bridge.sms.SmsMessageProvider) Test(org.testng.annotations.Test)

Aggregations

SmsMessageProvider (org.sagebionetworks.bridge.sms.SmsMessageProvider)15 Test (org.testng.annotations.Test)12 TemplateRevision (org.sagebionetworks.bridge.models.templates.TemplateRevision)7 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)3 PublishRequest (com.amazonaws.services.sns.model.PublishRequest)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 URL (java.net.URL)1 DateTime (org.joda.time.DateTime)1 BridgeServiceException (org.sagebionetworks.bridge.exceptions.BridgeServiceException)1 SmsTemplate (org.sagebionetworks.bridge.models.apps.SmsTemplate)1 UploadFieldDefinition (org.sagebionetworks.bridge.models.upload.UploadFieldDefinition)1 UploadSchema (org.sagebionetworks.bridge.models.upload.UploadSchema)1