diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandler.java index b69de76b260..27c62f6d2a6 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandler.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; @@ -29,6 +30,7 @@ import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getPartyNameBasedOnType; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getResponseIntentionForEmail; +@Slf4j @Service @RequiredArgsConstructor public class AcknowledgeClaimApplicantNotificationHandler extends CallbackHandler implements NotificationData { @@ -67,12 +69,16 @@ private CallbackResponse notifyApplicantSolicitorForClaimAcknowledgement(Callbac ? getRespondentSolicitorEmailAddress(caseData) : caseData.getApplicantSolicitor1UserDetails().getEmail(); - notificationService.sendMail( - recipient, - notificationsProperties.getRespondentSolicitorAcknowledgeClaim(), - addProperties(caseData), - String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference()) - ); + if (recipient != null) { + notificationService.sendMail( + recipient, + notificationsProperties.getRespondentSolicitorAcknowledgeClaim(), + addProperties(caseData), + String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference()) + ); + } else { + log.info(String.format("Email address is null for %s", caseData.getLegacyCaseReference())); + } return AboutToStartOrSubmitCallbackResponse.builder().build(); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/CreateClaimRespondentNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/CreateClaimRespondentNotificationHandler.java index adade9c1a72..7f8ffaff36d 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/CreateClaimRespondentNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/CreateClaimRespondentNotificationHandler.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; @@ -26,6 +27,7 @@ import static uk.gov.hmcts.reform.civil.utils.PartyUtils.buildPartiesReferences; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getPartyNameBasedOnType; +@Slf4j @Service @RequiredArgsConstructor public class CreateClaimRespondentNotificationHandler extends CallbackHandler implements NotificationData { @@ -109,7 +111,15 @@ private CallbackResponse notifyARespondentSolicitorForClaimIssue(CallbackParams throw new CallbackException(String.format("Callback handler received illegal event: %s", caseEvent)); } - sendNotificationToSolicitor(caseData, recipient); + if (recipient != null) { + sendNotificationToSolicitor(caseData, recipient); + } else { + log.info(String.format( + "Email address is null for caseEvent: %s for: %s", + caseEvent, + caseData.getLegacyCaseReference() + )); + } return AboutToStartOrSubmitCallbackResponse.builder() .data(caseData.toMap(objectMapper)) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantClaimDetailsNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantClaimDetailsNotificationHandler.java index ac57d23a574..488e5641b28 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantClaimDetailsNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantClaimDetailsNotificationHandler.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; @@ -30,6 +31,7 @@ import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.buildPartiesReferences; +@Slf4j @Service @RequiredArgsConstructor public class DefendantClaimDetailsNotificationHandler extends CallbackHandler implements NotificationData { @@ -86,12 +88,20 @@ private CallbackResponse notifyRespondentSolicitorForClaimDetails(CallbackParams String recipient = getRecipientEmail(caseData, caseEvent); String emailTemplate = notificationsProperties.getRespondentSolicitorClaimDetailsEmailTemplate(); - notificationService.sendMail( - recipient, - emailTemplate, - addProperties(caseData), - String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference()) - ); + if (recipient != null) { + notificationService.sendMail( + recipient, + emailTemplate, + addProperties(caseData), + String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference()) + ); + } else { + log.info(String.format( + "Email address is null for caseEvent: %s for: %s", + caseEvent, + caseData.getLegacyCaseReference() + )); + } return AboutToStartOrSubmitCallbackResponse.builder() .data(caseData.toMap(objectMapper)) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandlerTest.java index 3bc6f72a827..d32dd7e979f 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/AcknowledgeClaimApplicantNotificationHandlerTest.java @@ -10,6 +10,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.model.IdamUserDetails; import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; import uk.gov.hmcts.reform.civil.enums.YesOrNo; @@ -25,6 +26,7 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; @@ -85,6 +87,51 @@ void shouldNotifyApplicantSolicitor_whenInvoked() { ); } + @Test + void shouldNotNotifyApplicantSolicitor_whenRecipeintIsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateNotificationAcknowledged() + .applicantSolicitor1UserDetails(IdamUserDetails.builder().email(null).build()) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_CLAIM_ACKNOWLEDGEMENT").build()) + .build(); + + handler.handle(params); + + assertThatNoException(); + } + + @Test + void shouldNotNotifyRespondentSolicitor_whenRecipeint1IsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateNotificationAcknowledged() + .respondentSolicitor1EmailAddress(null) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_CLAIM_ACKNOWLEDGEMENT").build()) + .build(); + + handler.handle(params); + + assertThatNoException(); + } + + @Test + void shouldNotNotifyRespondentSolicitor_whenRecipeint2IsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateNotificationAcknowledged() + .respondentSolicitor2EmailAddress(null) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_CLAIM_ACKNOWLEDGEMENT").build()) + .build(); + + handler.handle(params); + + assertThatNoException(); + } + @Test void shouldNotifyRespondentSolicitor_whenInvokedWithCcEvent() { CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build(); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/CreateClaimRespondentNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/CreateClaimRespondentNotificationHandlerTest.java index 80ae6965c89..91f50469330 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/CreateClaimRespondentNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/CreateClaimRespondentNotificationHandlerTest.java @@ -9,6 +9,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.model.IdamUserDetails; import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; @@ -20,6 +21,7 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; @@ -91,6 +93,46 @@ void shouldNotifyApplicantSolicitor_whenInvokedWithCcEvent() { ); } + @Test + void shouldNotNotify_whenApplicantEmailIsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateRespondentFullDefence() + .applicantSolicitor1UserDetails(IdamUserDetails.builder().email(null).build()) + .build(); + + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIM_ISSUE_CC").build()).build(); + + handler.handle(params); + assertThatNoException(); + } + + @Test + void shouldNotNotify_whenRespondent1RecipientIsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateRespondentFullDefence() + .respondentSolicitor1EmailAddress(null) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIM_ISSUE").build()).build(); + + handler.handle(params); + assertThatNoException(); + } + + @Test + void shouldNotNotify_whenRespondent2RecipientIsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateRespondentFullDefence() + .respondentSolicitor2EmailAddress(null) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIM_ISSUE").build()).build(); + + handler.handle(params); + assertThatNoException(); + } + private Map getNotificationDataMap(CaseData caseData) { return Map.of( CLAIM_REFERENCE_NUMBER, LEGACY_CASE_REFERENCE, diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantClaimDetailsNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantClaimDetailsNotificationHandlerTest.java index 71a92ae6eb6..f86caa31001 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantClaimDetailsNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantClaimDetailsNotificationHandlerTest.java @@ -10,6 +10,7 @@ import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.config.ToggleConfiguration; +import uk.gov.hmcts.reform.civil.model.IdamUserDetails; import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; @@ -22,6 +23,7 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatNoException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; @@ -188,6 +190,57 @@ void shouldNotifyRespondentSolicitor_whenInvokedWithMultipartyEnabled() { ); } + @Test + void shouldNotNotifyRespondentSolicitor_when1v2SSRecipient1IsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateRespondentFullDefenceAfterNotificationAcknowledgement() + .respondentSolicitor1EmailAddress(null) + .build(); + CallbackParams params = CallbackParamsBuilder.builder() + .of(ABOUT_TO_SUBMIT, caseData) + .request(CallbackRequest.builder() + .eventId(NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIM_DETAILS.name()) + .build()) + .build(); + + handler.handle(params); + assertThatNoException(); + } + + @Test + void shouldNotNotifyApplicantSolicitor_ApplicantRecipient1IsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateRespondentFullDefenceAfterNotificationAcknowledgement() + .applicantSolicitor1UserDetails(IdamUserDetails.builder().email(null).build()) + .build(); + CallbackParams params = CallbackParamsBuilder.builder() + .of(ABOUT_TO_SUBMIT, caseData) + .request(CallbackRequest.builder() + .eventId(NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIM_DETAILS_CC.name()) + .build()) + .build(); + + handler.handle(params); + assertThatNoException(); + } + + @Test + void shouldNotNotifyRespondentSolicitor_1v2DSRecipient1IsNull() { + CaseData caseData = CaseDataBuilder.builder() + .atStateRespondentFullDefenceAfterNotificationAcknowledgement() + .respondentSolicitor2EmailAddress(null) + .build(); + CallbackParams params = CallbackParamsBuilder.builder() + .of(ABOUT_TO_SUBMIT, caseData) + .request(CallbackRequest.builder() + .eventId(NOTIFY_RESPONDENT_SOLICITOR2_FOR_CLAIM_DETAILS.name()) + .build()) + .build(); + + handler.handle(params); + assertThatNoException(); + } + } @Test