From 7acdac04c9b8f30c6fe03c13bebda0c806d704fa Mon Sep 17 00:00:00 2001 From: Miguel Molina <93722947+miguelMolina3691@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:25:58 +0100 Subject: [PATCH] CIV-7829 Notify successful payment claimant Lip (#3741) * CIV-7829 add notification service * CIV-7829 update test * CIV-7829 camunda changes * CIV-7829 camunda changes * CIV-7829 Test cases * CIV-7829 white space issue * CIV-7829 fixing build failure * CIV-7829 fixing build failure --------- Co-authored-by: kannan-v-hmcts <148557022+kannan-v-hmcts@users.noreply.github.com> Co-authored-by: VijayaKumarK Co-authored-by: m-meulendijks-v1 <107135537+m-meulendijks-v1@users.noreply.github.com> Co-authored-by: marianadpereira <71711509+marianadpereira@users.noreply.github.com> --- .../reform/civil/callback/CaseEvent.java | 1 + ...otifyApplicant1GenericTemplateHandler.java | 79 +++++++++++++++++++ .../ServiceRequestUpdateCallbackHandler.java | 9 ++- .../PaymentRequestUpdateCallbackService.java | 6 +- ...yApplicant1GenericTemplateHandlerTest.java | 79 +++++++++++++++++++ ...ymentRequestUpdateCallbackServiceTest.java | 29 +++++++ 6 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandler.java create mode 100644 src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandlerTest.java diff --git a/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java b/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java index 67772ee4bab..e54640574a4 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/callback/CaseEvent.java @@ -314,6 +314,7 @@ public enum CaseEvent { NOTIFY_APPLICANT1_FOR_REQUEST_JUDGEMENT_BY_ADMISSION_LIP_CLAIMANT(CAMUNDA), NOTIFY_RESPONDENT1_FOR_REQUEST_JUDGEMENT_BY_ADMISSION_LIP_CLAIMANT(CAMUNDA), TRIGGER_TASK_RECONFIG_GA(CAMUNDA), + NOTIFY_APPLICANT1_GENERIC_TEMPLATE(CAMUNDA), SEND_HEARING_TO_LIP_DEFENDANT(CAMUNDA), SEND_HEARING_TO_LIP_CLAIMANT(CAMUNDA), SEND_FINAL_ORDER_TO_LIP_DEFENDANT(CAMUNDA), diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandler.java new file mode 100644 index 00000000000..acc24e07b6f --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandler.java @@ -0,0 +1,79 @@ +package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; +import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; +import uk.gov.hmcts.reform.civil.callback.Callback; +import uk.gov.hmcts.reform.civil.callback.CallbackHandler; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.notify.NotificationService; +import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; +import uk.gov.hmcts.reform.civil.utils.PartyUtils; + +import java.util.List; +import java.util.Map; + +import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_APPLICANT1_GENERIC_TEMPLATE; + +@Service +@RequiredArgsConstructor +public class NotifyApplicant1GenericTemplateHandler extends CallbackHandler implements NotificationData { + + public static final String TASK_ID = "NotifyApplicant1GenericTemplate"; + private static final String REFERENCE_TEMPLATE = + "generic-notification-lip-%s"; + private final NotificationService notificationService; + private final NotificationsProperties notificationsProperties; + private static final List EVENTS = List.of( + NOTIFY_APPLICANT1_GENERIC_TEMPLATE + ); + + @Override + protected Map callbacks() { + return Map.of( + callbackKey(ABOUT_TO_SUBMIT), this::sendGenericNotificationLip + ); + } + + @Override + public String camundaActivityId(CallbackParams callbackParams) { + return TASK_ID; + } + + @Override + public List handledEvents() { + return EVENTS; + } + + public CallbackResponse sendGenericNotificationLip(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + notificationService.sendMail( + getRecipientEmail(caseData), + getNotificationTemplate(), + addProperties(caseData), + String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference()) + ); + return AboutToStartOrSubmitCallbackResponse.builder().build(); + } + + public Map addProperties(CaseData caseData) { + return Map.of( + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + PARTY_NAME, caseData.getApplicant1().getPartyName(), + CLAIMANT_V_DEFENDANT, PartyUtils.getAllPartyNames(caseData) + ); + } + + private String getNotificationTemplate() { + return notificationsProperties.getNotifyLipUpdateTemplate(); + } + + private String getRecipientEmail(CaseData caseData) { + return caseData.getClaimantUserDetails().getEmail(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestUpdateCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestUpdateCallbackHandler.java index 29010c9087d..882049a0283 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestUpdateCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/payment/ServiceRequestUpdateCallbackHandler.java @@ -10,6 +10,7 @@ import uk.gov.hmcts.reform.civil.callback.CallbackHandler; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; import java.util.List; @@ -17,6 +18,7 @@ import static java.util.Collections.singletonList; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SERVICE_REQUEST_RECEIVED; @Slf4j @@ -30,7 +32,8 @@ public class ServiceRequestUpdateCallbackHandler extends CallbackHandler { @Override protected Map callbacks() { return Map.of( - callbackKey(ABOUT_TO_SUBMIT), this::changeApplicationState + callbackKey(ABOUT_TO_SUBMIT), this::changeApplicationState, + callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse ); } @@ -43,6 +46,10 @@ private CallbackResponse changeApplicationState(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); CaseData.CaseDataBuilder dataBuilder = caseData.toBuilder(); + if (caseData.isLipvLipOneVOne()) { + dataBuilder.businessProcess(BusinessProcess.ready(SERVICE_REQUEST_RECEIVED)); + } + return AboutToStartOrSubmitCallbackResponse.builder() .data(dataBuilder.build().toMap(objectMapper)) .build(); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/PaymentRequestUpdateCallbackService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/PaymentRequestUpdateCallbackService.java index eb2e99cbc65..eb6bf6fef76 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/PaymentRequestUpdateCallbackService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/PaymentRequestUpdateCallbackService.java @@ -35,7 +35,6 @@ public class PaymentRequestUpdateCallbackService { public static final String serviceRequestReceived = "ServiceRequestReceived"; private final CaseDetailsConverter caseDetailsConverter; private final CoreCaseDataService coreCaseDataService; - private final FeatureToggleService featureToggleService; private final ObjectMapper objectMapper; private final Time time; @@ -43,7 +42,8 @@ public class PaymentRequestUpdateCallbackService { public void processCallback(ServiceRequestUpdateDto serviceRequestUpdateDto, String feeType) { log.info("Processing the callback for the caseId {} with status {}", serviceRequestUpdateDto.getCcdCaseNumber(), - serviceRequestUpdateDto.getServiceRequestStatus()); + serviceRequestUpdateDto.getServiceRequestStatus() + ); if (serviceRequestUpdateDto.getServiceRequestStatus().equalsIgnoreCase(PAID)) { @@ -58,7 +58,7 @@ public void processCallback(ServiceRequestUpdateDto serviceRequestUpdateDto, Str } else { log.info("Service request status is not PAID for Case id {}", - serviceRequestUpdateDto.getCcdCaseNumber()); + serviceRequestUpdateDto.getCcdCaseNumber()); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandlerTest.java new file mode 100644 index 00000000000..f8b14add359 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyApplicant1GenericTemplateHandlerTest.java @@ -0,0 +1,79 @@ +package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.IdamUserDetails; +import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.notify.NotificationService; +import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; +import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; +import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; + +import java.util.Map; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.PARTY_NAME; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIMANT_V_DEFENDANT; + +@SpringBootTest(classes = { + NotifyApplicant1GenericTemplateHandler.class, + JacksonAutoConfiguration.class +}) +class NotifyApplicant1GenericTemplateHandlerTest { + + public static final String TEMPLATE_ID = "template-id"; + + @MockBean + private NotificationService notificationService; + @MockBean + private NotificationsProperties notificationsProperties; + @Autowired + NotifyApplicant1GenericTemplateHandler handler; + + @BeforeEach + void setup() { + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn( + TEMPLATE_ID); + } + + @Test + void shouldSendGenericEmailWhenAllDataIsCorrect() { + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() + .claimantUserDetails(IdamUserDetails.builder().email("claimant@hmcts.net").build()) + .applicant1(Party.builder().individualFirstName("John").individualLastName("Doe") + .type(Party.Type.INDIVIDUAL).build()) + .respondent1(Party.builder().individualFirstName("Jack").individualLastName("Jackson") + .type(Party.Type.INDIVIDUAL).build()).build(); + + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).build(); + + handler.handle(params); + + verify(notificationService).sendMail( + "claimant@hmcts.net", + TEMPLATE_ID, + getNotificationDataMap(caseData), + "generic-notification-lip-000DC001" + ); + + } + + private Map getNotificationDataMap(CaseData caseData) { + return Map.of( + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + PARTY_NAME, "John Doe", + CLAIMANT_V_DEFENDANT, "John Doe V Jack Jackson" + ); + } + +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/PaymentRequestUpdateCallbackServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/PaymentRequestUpdateCallbackServiceTest.java index 4ba7811764e..e7973e3293d 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/PaymentRequestUpdateCallbackServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/PaymentRequestUpdateCallbackServiceTest.java @@ -14,6 +14,7 @@ import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.enums.BusinessProcessStatus; import uk.gov.hmcts.reform.civil.enums.FeeType; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; @@ -189,6 +190,34 @@ public void shouldProceed_WhenAdditionalPaymentExist_WithPaymentFailForClaimIssu verify(coreCaseDataService, times(1)).submitUpdate(any(), any()); } + @Test + public void shouldStartAndSubmitEventWithCaseDetailsInLipClaim_Hearing() { + + CaseData caseData = CaseDataBuilder.builder().receiveUpdatePaymentRequest().build(); + caseData = caseData.toBuilder() + .ccdState(CASE_PROGRESSION) + .businessProcess(BusinessProcess.builder() + .status(BusinessProcessStatus.READY) + .camundaEvent(BUSINESS_PROCESS) + .build()) + .applicant1Represented(YesOrNo.NO) + .respondent1Represented(YesOrNo.NO) + .build(); + CaseDetails caseDetails = buildCaseDetails(caseData); + + when(coreCaseDataService.getCase(CASE_ID)).thenReturn(caseDetails); + when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData); + when(coreCaseDataService.startUpdate(any(), any())).thenReturn(startEventResponse(caseDetails, + SERVICE_REQUEST_RECEIVED)); + when(coreCaseDataService.submitUpdate(any(), any())).thenReturn(caseData); + + paymentRequestUpdateCallbackService.processCallback(buildServiceDto(PAID), FeeType.HEARING.name()); + + verify(coreCaseDataService, times(1)).getCase(Long.valueOf(CASE_ID)); + verify(coreCaseDataService, times(1)).startUpdate(any(), any()); + verify(coreCaseDataService, times(1)).submitUpdate(any(), any()); + } + @Test public void shouldNotProceed_WhenPaymentFailed() { CaseData caseData = CaseDataBuilder.builder().receiveUpdatePaymentRequest().build();