Skip to content

Commit

Permalink
CIV-7829 Notify successful payment claimant Lip (#3741)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: VijayaKumarK <[email protected]>
Co-authored-by: m-meulendijks-v1 <[email protected]>
Co-authored-by: marianadpereira <[email protected]>
  • Loading branch information
5 people authored Jan 22, 2024
1 parent e10f2c9 commit 7acdac0
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CaseEvent> EVENTS = List.of(
NOTIFY_APPLICANT1_GENERIC_TEMPLATE
);

@Override
protected Map<String, Callback> callbacks() {
return Map.of(
callbackKey(ABOUT_TO_SUBMIT), this::sendGenericNotificationLip
);
}

@Override
public String camundaActivityId(CallbackParams callbackParams) {
return TASK_ID;
}

@Override
public List<CaseEvent> 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<String, String> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
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;
import java.util.Map;

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
Expand All @@ -30,7 +32,8 @@ public class ServiceRequestUpdateCallbackHandler extends CallbackHandler {
@Override
protected Map<String, Callback> callbacks() {
return Map.of(
callbackKey(ABOUT_TO_SUBMIT), this::changeApplicationState
callbackKey(ABOUT_TO_SUBMIT), this::changeApplicationState,
callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse
);
}

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ 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;

private CaseData data;

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)) {

Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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("[email protected]").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(
"[email protected]",
TEMPLATE_ID,
getNotificationDataMap(caseData),
"generic-notification-lip-000DC001"
);

}

private Map<String, String> getNotificationDataMap(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
PARTY_NAME, "John Doe",
CLAIMANT_V_DEFENDANT, "John Doe V Jack Jackson"
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 7acdac0

Please sign in to comment.