Skip to content

Commit

Permalink
added changes for claimant response cui event. (#3376)
Browse files Browse the repository at this point in the history
Co-authored-by: sankhajuria <[email protected]>
Co-authored-by: Raja Mani <[email protected]>
  • Loading branch information
3 people authored Oct 27, 2023
1 parent 19ce3fe commit 959219d
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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 java.util.List;
import java.util.Map;
import java.util.Objects;

import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_LIP_RESPONDENT_CLAIMANT_CONFIRM_TO_PROCEED;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getPartyNameBasedOnType;

@Service
@RequiredArgsConstructor
public class ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler extends CallbackHandler
implements NotificationData {

private static final List<CaseEvent> EVENTS = List.of(NOTIFY_LIP_RESPONDENT_CLAIMANT_CONFIRM_TO_PROCEED);
public static final String TASK_ID = "NotifyLiPRespondentClaimantConfirmToProceed";
private static final String REFERENCE_TEMPLATE = "claimant-confirms-to-proceed-respondent-notification-%s";
private final NotificationService notificationService;
private final NotificationsProperties notificationsProperties;
private final Map<String, Callback> callbackMap = Map.of(
callbackKey(ABOUT_TO_SUBMIT),
this::notifyRespondentForClaimantConfirmsToProceed
);

private CallbackResponse notifyRespondentForClaimantConfirmsToProceed(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
if (Objects.nonNull(caseData.getRespondent1().getPartyEmail())) {
notificationService.sendMail(
caseData.getRespondent1().getPartyEmail(),
notificationsProperties.getRespondent1LipClaimUpdatedTemplate(),
addProperties(caseData),
String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference())
);
}
return AboutToStartOrSubmitCallbackResponse.builder().build();
}

@Override
protected Map<String, Callback> callbacks() {
return callbackMap;
}

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

@Override
public List<CaseEvent> handledEvents() {
return EVENTS;
}

@Override
public Map<String, String> addProperties(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
RESPONDENT_NAME, getPartyNameBasedOnType(caseData.getRespondent1())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.notify.NotificationsProperties;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.notify.NotificationService;
import uk.gov.hmcts.reform.civil.service.OrganisationService;
Expand All @@ -20,7 +19,6 @@
import java.util.Optional;

import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_LIP_RESPONDENT_CLAIMANT_CONFIRM_TO_PROCEED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED_CC;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_RESPONDENT_SOLICITOR2_FOR_CLAIMANT_CONFIRMS_TO_PROCEED;
Expand All @@ -37,21 +35,18 @@ public class ClaimantResponseConfirmsToProceedRespondentNotificationHandler exte
private static final List<CaseEvent> EVENTS = List.of(
NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED,
NOTIFY_RESPONDENT_SOLICITOR2_FOR_CLAIMANT_CONFIRMS_TO_PROCEED,
NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED_CC,
NOTIFY_LIP_RESPONDENT_CLAIMANT_CONFIRM_TO_PROCEED);
NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED_CC);

public static final String TASK_ID = "ClaimantConfirmsToProceedNotifyRespondentSolicitor1";
public static final String Task_ID_RESPONDENT_SOL2 = "ClaimantConfirmsToProceedNotifyRespondentSolicitor2";
public static final String TASK_ID_CC = "ClaimantConfirmsToProceedNotifyApplicantSolicitor1CC";
private static final String REFERENCE_TEMPLATE = "claimant-confirms-to-proceed-respondent-notification-%s";
private static final String REFERENCE_TEMPLATE_APPLICANT = "claimant-confirms-to-proceed-applicant-notification-%s";
private static final String NP_PROCEED_REFERENCE_TEMPLATE
= "claimant-confirms-not-to-proceed-respondent-notification-%s";

private final NotificationService notificationService;
private final NotificationsProperties notificationsProperties;
private final OrganisationService organisationService;
private final FeatureToggleService featureToggleService;

@Override
protected Map<String, Callback> callbacks() {
Expand Down Expand Up @@ -84,12 +79,12 @@ private CallbackResponse notifyRespondentSolicitorForClaimantConfirmsToProceed(C
recipient = caseData.getRespondentSolicitor2EmailAddress();
}

if (isLiPDefendant(callbackParams)) {
if (isLRvLipToDefendant(callbackParams)) {
if (caseData.getRespondent1().getPartyEmail() != null) {
notificationService.sendMail(
caseData.getRespondent1().getPartyEmail(),
notificationsProperties.getRespondent1LipClaimUpdatedTemplate(),
addPropertiesForLiPDefendant(caseData),
addPropertiesLRvLip(caseData),
String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference())
);
}
Expand Down Expand Up @@ -145,7 +140,7 @@ APPLICANT_ONE_NAME, getPartyNameBasedOnType(caseData.getApplicant1())
);
}

public Map<String, String> addPropertiesForLiPDefendant(CaseData caseData) {
public Map<String, String> addPropertiesLRvLip(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
RESPONDENT_NAME, getPartyNameBasedOnType(caseData.getRespondent1())
Expand Down Expand Up @@ -177,7 +172,7 @@ private String getLegalOrganisationName(CaseData caseData, CaseEvent caseEvent)
caseData.getApplicantSolicitor1ClaimStatementOfTruth().getName();
}

private boolean isLiPDefendant(CallbackParams callbackParams) {
private boolean isLRvLipToDefendant(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
return SPEC_CLAIM.equals(caseData.getCaseAccessCategory())
&& caseData.isLRvLipOneVOne()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.enums.CaseState;
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;

Expand Down Expand Up @@ -50,9 +51,22 @@ private CallbackResponse aboutToSubmit(CallbackParams callbackParams) {
CaseData updatedData = caseData.toBuilder()
.businessProcess(BusinessProcess.ready(CLAIMANT_RESPONSE_CUI))
.build();
return AboutToStartOrSubmitCallbackResponse.builder()
.data(updatedData.toMap(objectMapper))
.build();

AboutToStartOrSubmitCallbackResponse.AboutToStartOrSubmitCallbackResponseBuilder response =
AboutToStartOrSubmitCallbackResponse.builder()
.data(updatedData.toMap(objectMapper));

updateClaimEndState(response, updatedData);

return response.build();
}

private void updateClaimEndState(AboutToStartOrSubmitCallbackResponse.AboutToStartOrSubmitCallbackResponseBuilder response, CaseData updatedData) {

if (updatedData.hasClaimantAgreedToFreeMediation()) {
response.state(CaseState.IN_MEDIATION.name());
} else {
response.state(CaseState.JUDICIAL_REFERRAL.name());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
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.CallbackVersion.V_1;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_LIP_CLAIM;
import static uk.gov.hmcts.reform.civil.enums.CaseCategory.SPEC_CLAIM;
Expand All @@ -46,6 +47,7 @@ protected Map<String, Callback> callbacks() {
.put(callbackKey(V_1, ABOUT_TO_START), this::lipClaimInitialState)
.put(callbackKey(ABOUT_TO_SUBMIT), this::submitClaim)
.put(callbackKey(V_1, ABOUT_TO_SUBMIT), this::submitClaim)
.put(callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
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.ccd.client.model.CallbackRequest;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
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.sampledata.CallbackParamsBuilder;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;

import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
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.ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler.TASK_ID;
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.RESPONDENT_NAME;
import static uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder.LEGACY_CASE_REFERENCE;

@SpringBootTest(classes = {
ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler.class,
JacksonAutoConfiguration.class
})
public class ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandlerTest extends BaseCallbackHandlerTest {

@MockBean
private NotificationService notificationService;
@MockBean
private NotificationsProperties notificationsProperties;
@Autowired
private ClaimantResponseConfirmsToProceedLiPRespondentNotificationHandler handler;

@Nested
class AboutToSubmitCallback {

private static final String RESPONDENT_EMAIL_TEMPLATE = "template-id-respondent";
private static final String RESPONDENT_EMAIL_ID = "[email protected]";
private static final String REFERENCE_NUMBER = "claimant-confirms-to-proceed-respondent-notification-000DC001";
private static final String DEFENDANT = "Mr. Sole Trader";

@BeforeEach
void setup() {
when(notificationsProperties.getRespondent1LipClaimUpdatedTemplate()).thenReturn(
RESPONDENT_EMAIL_TEMPLATE);
}

@Test
void shouldNotifyLipRespondent_whenInvoked() {
CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build();
CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request(
CallbackRequest.builder().eventId(CaseEvent.NOTIFY_LIP_RESPONDENT_CLAIMANT_CONFIRM_TO_PROCEED.name())
.build()).build();

handler.handle(params);

verify(notificationService).sendMail(
RESPONDENT_EMAIL_ID,
RESPONDENT_EMAIL_TEMPLATE,
getNotificationDataMap(caseData),
REFERENCE_NUMBER
);
}

private Map<String, String> getNotificationDataMap(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, LEGACY_CASE_REFERENCE,
RESPONDENT_NAME, DEFENDANT
);
}

@Test
void shouldReturnCorrectCamundaActivityId_whenInvoked() {
assertThat(handler.camundaActivityId(CallbackParamsBuilder.builder().request(CallbackRequest.builder().eventId(
CaseEvent.NOTIFY_LIP_RESPONDENT_CLAIMANT_CONFIRM_TO_PROCEED.name()).build()).build())).isEqualTo(TASK_ID);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.enums.CaseState;
import uk.gov.hmcts.reform.civil.enums.MediationDecision;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
import uk.gov.hmcts.reform.civil.model.CaseData;
Expand Down Expand Up @@ -103,5 +104,21 @@ void shouldOnlyUpdateClaimStatus_whenPartAdmitNotSettled_NoMediation() {
.isEqualTo("READY");

}

@Test
void shouldChangeCaseState_whenApplicantRejectClaimSettlementAndAgreeToMediation() {
CaseData caseData = CaseDataBuilder.builder()
.atStateClaimIssued()
.applicant1PartAdmitConfirmAmountPaidSpec(NO)
.caseDataLip(CaseDataLiP.builder().applicant1ClaimMediationSpecRequiredLip(ClaimantMediationLip.builder().hasAgreedFreeMediation(
MediationDecision.Yes).build())
.build())
.build();

CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

assertThat(response.getState()).isEqualTo(CaseState.IN_MEDIATION.name());
}
}
}

0 comments on commit 959219d

Please sign in to comment.