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;
}
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");
}
}
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);
}
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;
}
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);
}
}
Aggregations