Skip to content

Commit

Permalink
CIV-14295 Claimant LR Email notification: please resubmit discontinua…
Browse files Browse the repository at this point in the history
…nce (#5075)

* CIV-14233 Added validate discontinue event

* CIV-14146: Added midEvent and validations

* CIV-14128:Updated midEvent and caseData fields

* CIV-14128: Added more unit tests

* CIV-14128: Fix checkstyle errors

* CIV-14146: Fix checkstyle errors

* CIV-14146: Remove this field as this is not needed for now

* CIV-14146: Organized imports

* CIV-14146: Updated tests

* CIV-14236 update handler

* CIV-14194 initial commit

* CIV-14194 test cases added

* CIV-14236 update handler and classes

* CIV-14194 removed extra space

* CIV-14194 testcase updated

* CIV-14236 update handler and classes

* CIV-14236 Add unit tests

* CIV-14236 Add unit tests

* CIV-14236 Fix merging issue

* CIV-14236 Fix merging issues

* CIV-14236 Fix merging issues

* CIV-14236 Add extra condition for negative scenario

* CIV-14295 Add new notification

* CIV-14295 Add new notification

* CIV-14295 ValidateDiscontinuance handler unit tests

* CIV-14295 ValidateDiscontinuance handler unit tests

* CIV-14295 ValidateDiscontinuance handler unit tests

* CIV-14295 ValidateDiscontinuance handler unit tests

* CIV-14295 Add new Update Visibility handler

* CIV-14295 Update unit tests

* CIV-14295 Update unit tests

---------

Co-authored-by: kalachandrasekar1 <[email protected]>
Co-authored-by: kalachandrasekar1 <[email protected]>
Co-authored-by: JamiS <[email protected]>
Co-authored-by: Azam <[email protected]>
Co-authored-by: sjamihmcts <[email protected]>
  • Loading branch information
6 people authored Jul 19, 2024
1 parent d27fd0d commit 70a340b
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ public enum CaseEvent {
CREATE_DASHBOARD_NOTIFICATION_DECISION_RECONSIDERATION_CLAIMANT1(CAMUNDA),
CREATE_DASHBOARD_NOTIFICATION_DECISION_RECONSIDERATION_DEFENDANT1(CAMUNDA),
NOTIFY_CLAIMANT_UPLOADED_DOCUMENT_ORDER_NOTICE(CAMUNDA),
NOTIFY_DEFENDANT_UPLOADED_DOCUMENT_ORDER_NOTICE(CAMUNDA);
NOTIFY_DEFENDANT_UPLOADED_DOCUMENT_ORDER_NOTICE(CAMUNDA),
NOTIFY_VALIDATION_DICONTINUANCE_FAILURE_CLAIMANT(CAMUNDA),
UPDATE_VISIBILITY_NOTICE_OF_DISCONTINUANCE(CAMUNDA);

private final UserType userType;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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.service.OrganisationService;

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_VALIDATION_DICONTINUANCE_FAILURE_CLAIMANT;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.getApplicantLegalOrganizationName;

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

private static final List<CaseEvent> EVENTS = List.of(NOTIFY_VALIDATION_DICONTINUANCE_FAILURE_CLAIMANT);
public static final String TASK_ID = "NotifyValidationFailureClaimant";
private static final String REFERENCE_TEMPLATE =
"claimant-notify-validation-failure-%s";

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

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

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

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

private CallbackResponse notifyClaimantValidationFailure(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();

if (!caseData.isApplicantLiP()) {
notificationService.sendMail(
caseData.getApplicantSolicitor1UserDetails().getEmail(),
getTemplate(),
addProperties(caseData),
getReferenceTemplate(caseData)
);
}

return AboutToStartOrSubmitCallbackResponse.builder().build();
}

@Override
public Map<String, String> addProperties(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
LEGAL_ORG_NAME, getApplicantLegalOrganizationName(caseData, organisationService)
);
}

private String getTemplate() {
return notificationsProperties.getNotifyClaimantLrValidationDiscontinuanceFailureTemplate();
}

private String getReferenceTemplate(CaseData caseData) {
return String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference());
}

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

import lombok.RequiredArgsConstructor;
import org.camunda.bpm.engine.RuntimeService;
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.enums.settlediscontinue.ConfirmOrderGivesPermission;
import uk.gov.hmcts.reform.civil.model.CaseData;

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.UPDATE_VISIBILITY_NOTICE_OF_DISCONTINUANCE;

@Service
@RequiredArgsConstructor
public class UpdateVisibilityNoticeOfDiscontinuanceHandler extends CallbackHandler {

private static final List<CaseEvent> EVENTS = List.of(UPDATE_VISIBILITY_NOTICE_OF_DISCONTINUANCE);
public static final String TASK_ID = "UpdateVisibilityNoticeOfDiscontinuance";

private final RuntimeService runTimeService;

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

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

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

private CallbackResponse updateVisibilityNoticeDiscontinuance(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
//TODO add update visibility implementation here
updateCamundaVars(caseData);
return AboutToStartOrSubmitCallbackResponse.builder().build();
}

private void updateCamundaVars(CaseData caseData) {
runTimeService.setVariable(
caseData.getBusinessProcess().getProcessInstanceId(),
"discontinuanceValidationSuccess",
ConfirmOrderGivesPermission.YES.equals(caseData.getConfirmOrderGivesPermission())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import uk.gov.hmcts.reform.civil.enums.settlediscontinue.DiscontinuanceTypeList;
import uk.gov.hmcts.reform.civil.enums.settlediscontinue.SettleDiscontinueYesOrNoList;
import uk.gov.hmcts.reform.civil.helpers.settlediscontinue.DiscontinueClaimHelper;
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;

import java.util.List;
Expand Down Expand Up @@ -84,6 +85,8 @@ private CallbackResponse submitChanges(CallbackParams callbackParams) {
}
}

caseDataBuilder.businessProcess(BusinessProcess.ready(VALIDATE_DISCONTINUE_CLAIM_CLAIMANT));

return aboutToStartOrSubmitCallbackResponseBuilder.data(caseDataBuilder.build().toMap(objectMapper)).build();
}

Expand All @@ -107,4 +110,5 @@ private static String getHeader(CaseData caseData) {
public List<CaseEvent> handledEvents() {
return EVENTS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,7 @@ public class NotificationsProperties {
@NotEmpty
private String notifyLiPOrderTranslatedTemplate;

@NotEmpty
private String notifyClaimantLrValidationDiscontinuanceFailureTemplate;

}
4 changes: 3 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ notifications:
notifyDefendantLIPJudgmentByAdmissionTemplate: "734f9bb6-2e13-4364-8c25-b90a611b91a5"
notifyLiPOrderTranslatedTemplate: "d81749f7-cef5-4159-8d99-146eb572a690"

notifyClaimantLrValidationDiscontinuanceFailureTemplate: "25398d9e-bb5f-4778-b76f-625c355f7c06"

sendgrid:
api-key: ${SENDGRID_API_KEY:false}

Expand Down Expand Up @@ -745,7 +747,7 @@ idam:
id: civil-service
redirect_uri: https://localhost:3000/oauth2/callback
secret: ${CIVIL_CLIENT_SECRET:OOOOOOOOOOOOOOOO}

caseFlags:
logging:
enabled: ${CASE_FLAGS_LOGGING_ENABLED:false}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
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.enums.YesOrNo;
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.prd.model.Organisation;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import uk.gov.hmcts.reform.civil.service.OrganisationService;
import java.util.Map;
import java.util.Optional;
import static org.mockito.Mockito.times;
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.LEGAL_ORG_NAME;

@SpringBootTest(classes = {
NotifyClaimantLrValidationDiscontinuanceFailureHandler.class,
NotificationsProperties.class,
JacksonAutoConfiguration.class
})
class NotifyClaimantLrValidationDiscontinuanceFailureHandlerTest extends BaseCallbackHandlerTest {

public static final String TEMPLATE_ID = "template-id";

private static final String REFERENCE_NUMBER = "8372942374";

@MockBean
private NotificationService notificationService;

@MockBean
private NotificationsProperties notificationsProperties;

@MockBean
private OrganisationService organisationService;

@Autowired
private NotifyClaimantLrValidationDiscontinuanceFailureHandler handler;

@Nested
class AboutToSubmitCallback {

@BeforeEach
void setup() {
when(notificationsProperties.getNotifyClaimantLrValidationDiscontinuanceFailureTemplate()).thenReturn(
TEMPLATE_ID);
}

@Test
void shouldNotifyClaimantLrValidationDiscontinuanceFailure_whenInvoked() {

CaseData caseData = CaseDataBuilder.builder()
.legacyCaseReference(REFERENCE_NUMBER)
.atStateClaimDraft()
.applicant1Represented(YesOrNo.YES)
.build();

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

handler.handle(params);

verify(notificationService, times(1)).sendMail(
"[email protected]",
TEMPLATE_ID,
getNotificationDataMap(caseData),
"claimant-notify-validation-failure-8372942374"
);
}
}

public Map<String, String> getNotificationDataMap(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
LEGAL_ORG_NAME, getApplicantLegalOrganizationName(caseData)
);
}

public String getApplicantLegalOrganizationName(CaseData caseData) {
String id = caseData.getApplicant1OrganisationPolicy().getOrganisation().getOrganisationID();
Optional<Organisation> organisation = organisationService.findOrganisationById(id);
return organisation.isPresent() ? organisation.get().getName() :
caseData.getApplicantSolicitor1ClaimStatementOfTruth().getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package uk.gov.hmcts.reform.civil.handler.callback.camunda.notification;

import org.camunda.bpm.engine.RuntimeService;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
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.enums.settlediscontinue.ConfirmOrderGivesPermission;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import static org.mockito.Mockito.verify;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;

@SpringBootTest(classes = {
UpdateVisibilityNoticeOfDiscontinuanceHandler.class,
JacksonAutoConfiguration.class
})
class UpdateVisibilityNoticeOfDiscontinuanceHandlerTest extends BaseCallbackHandlerTest {

@MockBean
private RuntimeService runTimeService;

@Autowired
private UpdateVisibilityNoticeOfDiscontinuanceHandler handler;

private static final String processId = "process-id";

@Nested
class AboutToSubmitCallback {

@ParameterizedTest
@ValueSource(booleans = {true, false})
void shouldUpdateCamundaVariables_whenInvoked(Boolean toggleState) {
//Given
CaseData caseData = CaseDataBuilder.builder()
.businessProcess(BusinessProcess.builder().processInstanceId(processId).build()).build();
caseData.setConfirmOrderGivesPermission(
toggleState ? ConfirmOrderGivesPermission.YES : ConfirmOrderGivesPermission.NO);

CallbackParams params = CallbackParams.builder()
.caseData(caseData)
.type(ABOUT_TO_SUBMIT)
.request(CallbackRequest.builder()
.eventId(CaseEvent.UPDATE_VISIBILITY_NOTICE_OF_DISCONTINUANCE.name())
.build())
.build();
//When
handler.handle(params);
//Then
verify(runTimeService).setVariable(processId, "discontinuanceValidationSuccess", toggleState);
}
}

}
Loading

0 comments on commit 70a340b

Please sign in to comment.