Skip to content

Commit

Permalink
CIV-15228 Stay Lifted LIP Email Notification (#5627)
Browse files Browse the repository at this point in the history
* CIV-15230 Notify LR stay update requested

* CIV-15230 add template

* CIV-15230 add abstract classes

* CIV-15230 lint

* CIV-15230 lint

* CIV-15228 Stay Lift Lip Email Notification

* CIV-15228 sonar issues

* CIV-15228 sonar issues

* CIV-15228 checkstyle error

---------

Co-authored-by: miguelMolina3691 <[email protected]>
Co-authored-by: Miguel Molina <[email protected]>
Co-authored-by: mounikahmcts <[email protected]>
Co-authored-by: ss-evoco <[email protected]>
  • Loading branch information
5 people authored Oct 24, 2024
1 parent 7d8dec8 commit a5e152f
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ protected String getPartyName(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
return caseData.getApplicant1().getPartyName();
}

@Override
protected boolean isBilingual(CaseData caseData) {
return caseData.isClaimantBilingual();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ protected boolean isLiP(CaseData caseData) {
}

protected abstract boolean isRespondentSolicitor2(CallbackParams callbackParams);

@Override
protected boolean isBilingual(CaseData caseData) {
return caseData.isRespondentResponseBilingual();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.Map;

Expand All @@ -27,9 +28,7 @@ public Map<String, Callback> callbacks() {

public CallbackResponse sendNotification(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
if (isLiP(caseData)) { // TODO: remove when lip notification is developed
return AboutToStartOrSubmitCallbackResponse.builder().build();
}

notificationService.sendMail(
getRecipient(callbackParams),
getNotificationTemplate(caseData),
Expand All @@ -39,26 +38,28 @@ public CallbackResponse sendNotification(CallbackParams callbackParams) {
return AboutToStartOrSubmitCallbackResponse.builder().build();
}

protected abstract String getReferenceTemplate();

protected abstract String getRecipient(CallbackParams callbackParams);

protected String getNotificationTemplate(CaseData caseData) {
if (isLiP(caseData)) {
// TODO: add lip template
return null;
} else {
return notificationsProperties.getNotifyLRStayLifted();
return isBilingual(caseData) ? notificationsProperties.getNotifyLipUpdateTemplateBilingual()
: notificationsProperties.getNotifyLipUpdateTemplate();
}
return notificationsProperties.getNotifyLRStayLifted();
}

protected abstract String getReferenceTemplate();

protected abstract String getRecipient(CallbackParams callbackParams);

protected abstract boolean isBilingual(CaseData caseData);

protected abstract boolean isLiP(CaseData caseData);

protected Map<String, String> addPropertiesForStayLifted(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
PARTY_NAME, getPartyName(callbackParams)
PARTY_NAME, getPartyName(callbackParams),
CLAIMANT_V_DEFENDANT, PartyUtils.getAllPartyNames(caseData)
);
}

Expand All @@ -68,4 +69,5 @@ public Map<String, String> addProperties(CaseData caseData) {
}

protected abstract String getPartyName(CallbackParams callbackParams);

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ public String camundaActivityId(CallbackParams callbackParams) {
public List<CaseEvent> handledEvents() {
return EVENTS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,12 @@ private CallbackResponse handleSubmitted(CallbackParams params) {
private CallbackResponse manageStay(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
CaseState newState;
if (nonNull(caseData.getManageStayOption()) && caseData.getManageStayOption().equals(LIFT_STAY)) {
caseDataBuilder.businessProcess(BusinessProcess.ready(STAY_LIFTED));
newState = STATE_MAP.getOrDefault(caseData.getPreStayState(), caseData.getCcdState());
} else {
caseDataBuilder.businessProcess(BusinessProcess.ready(STAY_UPDATE_REQUESTED));
newState = caseData.getCcdState();
}

CaseState newState = nonNull(caseData.getManageStayOption()) && caseData.getManageStayOption().equals(LIFT_STAY)
? STATE_MAP.getOrDefault(caseData.getPreStayState(), caseData.getCcdState())
: caseData.getCcdState();
caseDataBuilder.businessProcess(BusinessProcess.ready(
LIFT_STAY.equals(caseData.getManageStayOption()) ? STAY_LIFTED : STAY_UPDATE_REQUESTED
));
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(mapper))
.state(newState.name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,36 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest;
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.enums.dq.Language;
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.model.citizenui.CaseDataLiP;
import uk.gov.hmcts.reform.civil.model.citizenui.RespondentLiPResponse;
import uk.gov.hmcts.reform.civil.notify.NotificationService;
import uk.gov.hmcts.reform.civil.notify.NotificationsProperties;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
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.callback.CaseEvent.NOTIFY_CLAIMANT_STAY_LIFTED;

@ExtendWith(MockitoExtension.class)
Expand All @@ -38,6 +49,38 @@ class NotifyClaimantStayLiftedHandlerTest {

private CaseData caseData;

private CaseDataBuilder commonCaseData() {
return 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())
.applicantSolicitor1UserDetails(IdamUserDetails.builder().email("[email protected]").build());
}

private CaseData getCaseData(boolean isClaimantLiP, boolean isClaimantBilingual) {
String claimantBilingualLanguagePreference = isClaimantBilingual ? Language.BOTH.toString()
: Language.ENGLISH.toString();
RespondentLiPResponse respondentLip = RespondentLiPResponse.builder()
.respondent1ResponseLanguage(claimantBilingualLanguagePreference).build();
return commonCaseData()
.applicant1Represented(isClaimantLiP ? YesOrNo.NO : YesOrNo.YES)
.applicantSolicitor1UserDetails(IdamUserDetails.builder().email("[email protected]").build())
.claimantBilingualLanguagePreference(claimantBilingualLanguagePreference)
.build().toBuilder()
.caseDataLiP(CaseDataLiP.builder()
.respondent1LiPResponse(respondentLip).build())
.build();
}

static Stream<Arguments> provideCaseDataLip() {
return Stream.of(
Arguments.of(true, true, "bilingual-template"),
Arguments.of(true, false, "default-template")
);
}

@BeforeEach
void setUp() {
caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified()
Expand Down Expand Up @@ -77,7 +120,46 @@ void sendNotificationShouldSendEmail() {
"solicitor-template",
Map.of(
"claimReferenceNumber", "1594901956117591",
"name", "John Doe"
"name", "John Doe",
"claimantvdefendant", "John Doe V Jack Jackson"
),
"stay-lifted-claimant-notification-1594901956117591"
);
assertNotNull(response);
}

@ParameterizedTest
@MethodSource("provideCaseDataLip")
void sendNotificationShouldSendEmail(boolean isRespondentLiP, boolean isRespondentBilingual, String template) {
CaseData caseData = getCaseData(isRespondentLiP, isRespondentBilingual);

CallbackRequest callbackRequest = CallbackRequest
.builder()
.eventId(CaseEvent.NOTIFY_CLAIMANT_DISMISS_CASE.name())
.build();
CallbackParams params = CallbackParams.builder()
.request(callbackRequest)
.caseData(caseData)
.type(ABOUT_TO_SUBMIT)
.build();

if (isRespondentLiP && isRespondentBilingual) {
when(notificationsProperties.getNotifyLipUpdateTemplateBilingual()).thenReturn("bilingual-template");
} else if (isRespondentLiP) {
when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("default-template");
} else {
when(notificationsProperties.getNotifyLRStayLifted()).thenReturn("solicitor-template");
}

CallbackResponse response = handler.sendNotification(params);

verify(notificationService).sendMail(
isRespondentLiP ? "[email protected]" : "[email protected]",
template,
Map.of(
"claimReferenceNumber", "1594901956117591",
"name", "John Doe",
"claimantvdefendant", "John Doe V Jack Jackson"
),
"stay-lifted-claimant-notification-1594901956117591"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ void sendNotificationShouldSendEmail() {
"solicitor-template",
Map.of(
"claimReferenceNumber", "1594901956117591",
"name", "John Doe"
"name", "John Doe",
"claimantvdefendant", "John Doe V Jack Jackson"
),
"stay-update-requested-claimant-notification-1594901956117591"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.enums.dq.Language;
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.model.citizenui.CaseDataLiP;
import uk.gov.hmcts.reform.civil.model.citizenui.RespondentLiPResponse;
import uk.gov.hmcts.reform.civil.notify.NotificationService;
import uk.gov.hmcts.reform.civil.notify.NotificationsProperties;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
Expand All @@ -29,6 +32,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
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.callback.CaseEvent.NOTIFY_DEFENDANT2_STAY_LIFTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_DEFENDANT_STAY_LIFTED;

Expand Down Expand Up @@ -112,7 +116,8 @@ void sendNotificationShouldSendEmail(boolean isDefendant2, CaseEvent caseEvent)
"solicitor-template",
Map.of(
"claimReferenceNumber", "1594901956117591",
"name", "Jim Jameson"
"name", "Jim Jameson",
"claimantvdefendant", "Mr. John Rambo V Jack Jackson"
),
"stay-lifted-defendant-notification-1594901956117591"
);
Expand All @@ -122,12 +127,82 @@ void sendNotificationShouldSendEmail(boolean isDefendant2, CaseEvent caseEvent)
"solicitor-template",
Map.of(
"claimReferenceNumber", "1594901956117591",
"name", "Jack Jackson"
"name", "Jack Jackson",
"claimantvdefendant", "Mr. John Rambo V Jack Jackson"
),
"stay-lifted-defendant-notification-1594901956117591"
);
}
assertNotNull(response);
}

private CaseDataBuilder commonCaseData() {
return 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")
.partyEmail("[email protected]")
.type(Party.Type.INDIVIDUAL).build())
.respondentSolicitor1EmailAddress("[email protected]");
}

private CaseData getCaseData(boolean isRespondentLiP, boolean isRespondentBilingual) {
RespondentLiPResponse respondentLip = RespondentLiPResponse.builder()
.respondent1ResponseLanguage(isRespondentBilingual ? Language.BOTH.toString()
: Language.ENGLISH.toString()).build();
return commonCaseData()
.respondent1Represented(isRespondentLiP ? YesOrNo.NO : YesOrNo.YES)

.build().toBuilder()
.caseDataLiP(CaseDataLiP.builder()
.respondent1LiPResponse(respondentLip).build())
.build();
}

static Stream<Arguments> provideLipCaseData() {
return Stream.of(
Arguments.of(true, true, "bilingual-template"),
Arguments.of(true, false, "default-template")
);
}

@ParameterizedTest
@MethodSource("provideLipCaseData")
void sendNotificationShouldSendLipEmail(boolean isRespondentLiP, boolean isRespondentBilingual, String template) {
CaseData caseData = getCaseData(isRespondentLiP, isRespondentBilingual);

CallbackRequest callbackRequest = CallbackRequest
.builder()
.eventId(CaseEvent.NOTIFY_DEFENDANT_DISMISS_CASE.name())
.build();
CallbackParams params = CallbackParams.builder()
.request(callbackRequest)
.caseData(caseData)
.type(ABOUT_TO_SUBMIT)
.build();

if (isRespondentLiP && isRespondentBilingual) {
when(notificationsProperties.getNotifyLipUpdateTemplateBilingual()).thenReturn("bilingual-template");
} else if (isRespondentLiP) {
when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn("default-template");
} else {
when(notificationsProperties.getNotifyLRStayLifted()).thenReturn("solicitor-template");
}

CallbackResponse response = handler.sendNotification(params);

verify(notificationService).sendMail(
isRespondentLiP ? "[email protected]" : "[email protected]",
template,
Map.of(
"claimReferenceNumber", "1594901956117591",
"name", "Jack Jackson",
"claimantvdefendant", "John Doe V Jack Jackson"
),
"stay-lifted-defendant-notification-1594901956117591"
);
assertNotNull(response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ void sendNotificationShouldSendEmail(boolean isDefendant2, CaseEvent caseEvent)
"solicitor-template",
Map.of(
"claimReferenceNumber", "1594901956117591",
"name", "Jim Jameson"
"name", "Jim Jameson",
"claimantvdefendant", "Mr. John Rambo V Jack Jackson"
),
"stay-update-requested-defendant-notification-1594901956117591"
);
Expand All @@ -122,7 +123,8 @@ void sendNotificationShouldSendEmail(boolean isDefendant2, CaseEvent caseEvent)
"solicitor-template",
Map.of(
"claimReferenceNumber", "1594901956117591",
"name", "Jack Jackson"
"name", "Jack Jackson",
"claimantvdefendant", "Mr. John Rambo V Jack Jackson"
),
"stay-update-requested-defendant-notification-1594901956117591"
);
Expand Down

0 comments on commit a5e152f

Please sign in to comment.