Search in sources :

Example 1 with NotificationClientException

use of uk.gov.service.notify.NotificationClientException in project di-authentication-api by alphagov.

the class NotificationHandler method handleRequest.

@Override
public Void handleRequest(SQSEvent event, Context context) {
    for (SQSMessage msg : event.getRecords()) {
        try {
            LOG.info("Message received from SQS queue");
            NotifyRequest notifyRequest = objectMapper.readValue(msg.getBody(), NotifyRequest.class);
            try {
                switch(notifyRequest.getNotificationType()) {
                    case VERIFY_EMAIL:
                        Map<String, Object> emailPersonalisation = new HashMap<>();
                        emailPersonalisation.put("validation-code", notifyRequest.getCode());
                        emailPersonalisation.put("email-address", notifyRequest.getDestination());
                        emailPersonalisation.put("contact-us-link", buildContactUsUrl());
                        LOG.info("Sending VERIFY_EMAIL email using Notify");
                        notificationService.sendEmail(notifyRequest.getDestination(), emailPersonalisation, notificationService.getNotificationTemplateId(NotificationType.VERIFY_EMAIL));
                        LOG.info("VERIFY_EMAIL email has been sent using Notify");
                        break;
                    case VERIFY_PHONE_NUMBER:
                        Map<String, Object> phonePersonalisation = new HashMap<>();
                        phonePersonalisation.put("validation-code", notifyRequest.getCode());
                        LOG.info("Sending VERIFY_PHONE_NUMBER email using Notify");
                        notificationService.sendText(notifyRequest.getDestination(), phonePersonalisation, notificationService.getNotificationTemplateId(NotificationType.VERIFY_PHONE_NUMBER));
                        LOG.info("VERIFY_PHONE_NUMBER text has been sent using Notify");
                        break;
                    case EMAIL_UPDATED:
                        Map<String, Object> emailUpdatePersonalisation = new HashMap<>();
                        emailUpdatePersonalisation.put("email-address", notifyRequest.getDestination());
                        emailUpdatePersonalisation.put("customer-support-link", buildURI(configurationService.getFrontendBaseUrl(), configurationService.getCustomerSupportLinkRoute()).toString());
                        LOG.info("Sending EMAIL_UPDATED email using Notify");
                        notificationService.sendEmail(notifyRequest.getDestination(), emailUpdatePersonalisation, notificationService.getNotificationTemplateId(NotificationType.EMAIL_UPDATED));
                        LOG.info("EMAIL_UPDATED email has been sent using Notify");
                        break;
                    case DELETE_ACCOUNT:
                        LOG.info("Sending DELETE_ACCOUNT email using Notify");
                        Map<String, Object> accountDeletedPersonalisation = new HashMap<>();
                        accountDeletedPersonalisation.put("customer-support-link", buildURI(configurationService.getFrontendBaseUrl(), configurationService.getCustomerSupportLinkRoute()).toString());
                        notificationService.sendEmail(notifyRequest.getDestination(), accountDeletedPersonalisation, notificationService.getNotificationTemplateId(NotificationType.DELETE_ACCOUNT));
                        LOG.info("DELETE_ACCOUNT email has been sent using Notify");
                        break;
                    case PHONE_NUMBER_UPDATED:
                        LOG.info("Sending PHONE_NUMBER_UPDATED email using Notify");
                        Map<String, Object> phoneNumberUpdatedPersonalisation = new HashMap<>();
                        phoneNumberUpdatedPersonalisation.put("customer-support-link", buildURI(configurationService.getFrontendBaseUrl(), configurationService.getCustomerSupportLinkRoute()).toString());
                        notificationService.sendEmail(notifyRequest.getDestination(), phoneNumberUpdatedPersonalisation, notificationService.getNotificationTemplateId(NotificationType.PHONE_NUMBER_UPDATED));
                        LOG.info("PHONE_NUMBER_UPDATED email has been sent using Notify");
                        break;
                    case PASSWORD_UPDATED:
                        LOG.info("Sending PASSWORD_UPDATED email using Notify");
                        Map<String, Object> passwordUpdatedPersonalisation = new HashMap<>();
                        passwordUpdatedPersonalisation.put("customer-support-link", buildURI(configurationService.getFrontendBaseUrl(), configurationService.getCustomerSupportLinkRoute()).toString());
                        notificationService.sendEmail(notifyRequest.getDestination(), passwordUpdatedPersonalisation, notificationService.getNotificationTemplateId(NotificationType.PASSWORD_UPDATED));
                        LOG.info("PASSWORD_UPDATED email has been sent using Notify");
                        break;
                }
            } catch (NotificationClientException e) {
                LOG.error("Error sending with Notify", e);
                throw new RuntimeException(String.format("Error sending with Notify using NotificationType: %s", notifyRequest.getNotificationType()), e);
            }
        } catch (JsonProcessingException e) {
            LOG.error("Error when mapping message from queue to a NotifyRequest");
            throw new RuntimeException("Error when mapping message from queue to a NotifyRequest");
        }
    }
    return null;
}
Also used : NotificationClientException(uk.gov.service.notify.NotificationClientException) HashMap(java.util.HashMap) SQSMessage(com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage) NotifyRequest(uk.gov.di.accountmanagement.entity.NotifyRequest) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with NotificationClientException

use of uk.gov.service.notify.NotificationClientException in project div-case-orchestration-service by hmcts.

the class SendDaGrantedNotificationEmailTaskTest method shouldCallEmailServiceForDaNotificationIfSolicitorIsRepresentingRespAndRespSolRepresentedValueIsNotPresent.

// test until we implement setting respondentSolicitorRepresented from CCD for RespSols
@Test
public void shouldCallEmailServiceForDaNotificationIfSolicitorIsRepresentingRespAndRespSolRepresentedValueIsNotPresent() throws TaskException {
    testData.put(CASE_ID_JSON_KEY, UNFORMATTED_CASE_ID);
    testData.put(D8_RESPONDENT_SOLICITOR_EMAIL, TEST_RESP_SOLICITOR_EMAIL);
    testData.put(D8_RESPONDENT_SOLICITOR_NAME, TEST_RESP_SOLICITOR_NAME);
    testData.put(D8_RESPONDENT_SOLICITOR_COMPANY, TEST_SOLICITOR_COMPANY);
    testData.put(D_8_PETITIONER_FIRST_NAME, TEST_PETITIONER_FIRST_NAME);
    testData.put(D_8_PETITIONER_LAST_NAME, TEST_PETITIONER_LAST_NAME);
    testData.put(D_8_PETITIONER_EMAIL, TEST_PETITIONER_EMAIL);
    testData.put(RESP_FIRST_NAME_CCD_FIELD, TEST_RESPONDENT_FIRST_NAME);
    testData.put(RESP_LAST_NAME_CCD_FIELD, TEST_RESPONDENT_LAST_NAME);
    testData.put(LANGUAGE_PREFERENCE_WELSH, "No");
    Map returnPayload = sendDaGrantedNotificationEmail.execute(context, testData);
    assertEquals(testData, returnPayload);
    try {
        verify(emailService).sendEmailAndReturnExceptionIfFails(eq(TEST_PETITIONER_EMAIL), eq(EmailTemplateNames.DA_GRANTED_NOTIFICATION.name()), eq(expectedPetitionerTemplateVars), eq(DA_GRANTED_NOTIFICATION_EMAIL_DESC), eq(LanguagePreference.ENGLISH));
        verify(emailService).sendEmail(eq(TEST_RESP_SOLICITOR_EMAIL), eq(EmailTemplateNames.SOL_DA_GRANTED_NOTIFICATION.name()), eq(expectedRespSolicitorTemplateVars), eq(SOL_DA_GRANTED_NOTIFICATION_EMAIL_DESC), eq(LanguagePreference.ENGLISH));
    } catch (NotificationClientException e) {
        fail("Failed to throw task exception");
    }
}
Also used : NotificationClientException(uk.gov.service.notify.NotificationClientException) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with NotificationClientException

use of uk.gov.service.notify.NotificationClientException in project div-case-orchestration-service by hmcts.

the class SendDaRequestedNotifyRespondentEmailTaskTest method shouldThrowTaskExceptionWhenEmailServiceThrowsException.

@Test(expected = TaskException.class)
public void shouldThrowTaskExceptionWhenEmailServiceThrowsException() throws TaskException, NotificationClientException {
    testData.put(RESPONDENT_EMAIL_ADDRESS, TEST_RESPONDENT_EMAIL);
    testData.put(RESP_FIRST_NAME_CCD_FIELD, TEST_RESPONDENT_FIRST_NAME);
    testData.put(RESP_LAST_NAME_CCD_FIELD, TEST_RESPONDENT_LAST_NAME);
    testData.put(NOTIFICATION_HUSBAND_OR_WIFE, TEST_RELATIONSHIP);
    testData.put(D_8_INFERRED_PETITIONER_GENDER, TEST_INFERRED_GENDER);
    testData.put(LANGUAGE_PREFERENCE_WELSH, "Yes");
    when(templateConfigService.getRelationshipTermByGender(same(TEST_INFERRED_GENDER), eq(LanguagePreference.ENGLISH))).thenReturn(TEST_RELATIONSHIP);
    when(templateConfigService.getRelationshipTermByGender(same(TEST_INFERRED_GENDER), eq(LanguagePreference.WELSH))).thenReturn(TEST_WELSH_FEMALE_GENDER_IN_RELATION);
    doThrow(new NotificationClientException(new Exception(TEST_ERROR))).when(emailService).sendEmailAndReturnExceptionIfFails(eq(TEST_RESPONDENT_EMAIL), eq(EmailTemplateNames.DECREE_ABSOLUTE_REQUESTED_NOTIFICATION.name()), anyMap(), eq(REQUESTED_BY_APPLICANT), eq(LanguagePreference.WELSH));
    sendDaRequestedNotifyRespondentEmailTask.execute(context, testData);
}
Also used : NotificationClientException(uk.gov.service.notify.NotificationClientException) TaskException(uk.gov.hmcts.reform.divorce.orchestration.framework.workflow.task.TaskException) NotificationClientException(uk.gov.service.notify.NotificationClientException) Test(org.junit.Test)

Example 4 with NotificationClientException

use of uk.gov.service.notify.NotificationClientException in project div-case-orchestration-service by hmcts.

the class SendPetitionerUpdateNotificationsEmailTask method execute.

@Override
public Map<String, Object> execute(TaskContext context, Map<String, Object> caseData) throws TaskException {
    final String caseId = context.getTransientObject(CASE_ID_JSON_KEY);
    final String eventId = context.getTransientObject(CASE_EVENT_ID_JSON_KEY);
    log.info("CaseId: {} SendPetitionerUpdateNotificationsEmailTask is going to be executed for event {}", caseId, eventId);
    String petEmail = (String) caseData.get(D_8_PETITIONER_EMAIL);
    String petSolEmail = (String) caseData.get(PETITIONER_SOLICITOR_EMAIL);
    String petitionerFirstName = getMandatoryPropertyValueAsString(caseData, D_8_PETITIONER_FIRST_NAME);
    String petitionerLastName = getMandatoryPropertyValueAsString(caseData, D_8_PETITIONER_LAST_NAME);
    LanguagePreference languagePreference = CaseDataUtils.getLanguagePreference(caseData);
    Map<String, String> templateVars = new HashMap<>();
    if (StringUtils.isNotBlank(petSolEmail)) {
        String respFirstName = getMandatoryPropertyValueAsString(caseData, RESP_FIRST_NAME_CCD_FIELD);
        String respLastName = getMandatoryPropertyValueAsString(caseData, RESP_LAST_NAME_CCD_FIELD);
        String solicitorName = getMandatoryPropertyValueAsString(caseData, PETITIONER_SOLICITOR_NAME);
        templateVars.put(NOTIFICATION_EMAIL, petSolEmail);
        templateVars.put(NOTIFICATION_CCD_REFERENCE_KEY, context.getTransientObject(CASE_ID_JSON_KEY));
        templateVars.put(NOTIFICATION_PET_NAME, petitionerFirstName + " " + petitionerLastName);
        templateVars.put(NOTIFICATION_RESP_NAME, respFirstName + " " + respLastName);
        templateVars.put(NOTIFICATION_SOLICITOR_NAME, solicitorName);
        try {
            sendSolicitorEmail(petSolEmail, eventId, templateVars, languagePreference);
        } catch (NotificationClientException e) {
            log.error("Error sending AOS overdue notification email to solicitor", e);
            throw new TaskException(e.getMessage(), e);
        }
    } else if (StringUtils.isNotBlank(petEmail)) {
        String relationship = getMandatoryPropertyValueAsString(caseData, D_8_DIVORCED_WHO);
        String welshRelationship = templateConfig.getTemplate().get(TEMPLATE_RELATION).get(LanguagePreference.WELSH).get(relationship);
        templateVars.put(NOTIFICATION_EMAIL, petEmail);
        templateVars.put(NOTIFICATION_ADDRESSEE_FIRST_NAME_KEY, petitionerFirstName);
        templateVars.put(NOTIFICATION_ADDRESSEE_LAST_NAME_KEY, petitionerLastName);
        templateVars.put(NOTIFICATION_RELATIONSHIP_KEY, relationship);
        templateVars.put(NOTIFICATION_WELSH_RELATIONSHIP_KEY, welshRelationship);
        templateVars.put(NOTIFICATION_CCD_REFERENCE_KEY, getMandatoryPropertyValueAsString(caseData, D_8_CASE_REFERENCE));
        try {
            sendPetitionerEmail(caseData, petEmail, eventId, templateVars, languagePreference);
        } catch (NotificationClientException e) {
            log.error("Error sending AOS overdue notification email to petitioner", e);
            throw new TaskException(e.getMessage(), e);
        }
    }
    return caseData;
}
Also used : NotificationClientException(uk.gov.service.notify.NotificationClientException) TaskException(uk.gov.hmcts.reform.divorce.orchestration.framework.workflow.task.TaskException) LanguagePreference(uk.gov.hmcts.reform.divorce.orchestration.domain.model.LanguagePreference) HashMap(java.util.HashMap) TaskUtils.getMandatoryPropertyValueAsString(uk.gov.hmcts.reform.divorce.orchestration.tasks.util.TaskUtils.getMandatoryPropertyValueAsString)

Example 5 with NotificationClientException

use of uk.gov.service.notify.NotificationClientException in project div-case-orchestration-service by hmcts.

the class SendSolicitorPersonalServiceEmailTask method execute.

@Override
public Map<String, Object> execute(TaskContext context, Map<String, Object> caseData) throws TaskException {
    String petSolicitorEmail = getMandatoryPropertyValueAsString(caseData, PETITIONER_SOLICITOR_EMAIL);
    String caseId = context.getTransientObject(CASE_ID_JSON_KEY);
    LanguagePreference languagePreference = CaseDataUtils.getLanguagePreference(caseData);
    Map<String, String> templateVars = buildEmailTemplateVars(petSolicitorEmail, caseId, caseData);
    try {
        emailService.sendEmailAndReturnExceptionIfFails(petSolicitorEmail, EmailTemplateNames.SOL_PERSONAL_SERVICE.name(), templateVars, SOL_PERSONAL_SERVICE_EMAIL, languagePreference);
        return caseData;
    } catch (NotificationClientException e) {
        log.error(String.format("Error sending solicitor personal service notification for case %s", caseId), e);
        throw new TaskException(e);
    }
}
Also used : NotificationClientException(uk.gov.service.notify.NotificationClientException) TaskException(uk.gov.hmcts.reform.divorce.orchestration.framework.workflow.task.TaskException) LanguagePreference(uk.gov.hmcts.reform.divorce.orchestration.domain.model.LanguagePreference) TaskUtils.getMandatoryPropertyValueAsString(uk.gov.hmcts.reform.divorce.orchestration.tasks.util.TaskUtils.getMandatoryPropertyValueAsString)

Aggregations

NotificationClientException (uk.gov.service.notify.NotificationClientException)36 Test (org.junit.Test)15 HashMap (java.util.HashMap)11 NotificationException (uk.gov.hmcts.divorce.notification.exception.NotificationException)6 Map (java.util.Map)5 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 LanguagePreference (uk.gov.hmcts.reform.divorce.orchestration.domain.model.LanguagePreference)5 SQSMessage (com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 TaskException (uk.gov.hmcts.reform.divorce.orchestration.framework.workflow.task.TaskException)3 MockedFunctionalTest (uk.gov.hmcts.reform.divorce.orchestration.functionaltest.MockedFunctionalTest)3 TaskUtils.getMandatoryPropertyValueAsString (uk.gov.hmcts.reform.divorce.orchestration.tasks.util.TaskUtils.getMandatoryPropertyValueAsString)3 ObjectMapperTestUtil.convertObjectToJsonString (uk.gov.hmcts.reform.divorce.orchestration.testutil.ObjectMapperTestUtil.convertObjectToJsonString)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Stopwatch (com.google.common.base.Stopwatch)2 NotifyRequest (uk.gov.di.accountmanagement.entity.NotifyRequest)2 NotifyRequest (uk.gov.di.authentication.shared.entity.NotifyRequest)2 JsonException (uk.gov.di.authentication.shared.serialization.Json.JsonException)2 DefaultTaskContext (uk.gov.hmcts.reform.divorce.orchestration.framework.workflow.task.DefaultTaskContext)2