-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into DTSCCI-480-Remove-Spring-context
- Loading branch information
Showing
9 changed files
with
367 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...callback/camunda/notification/NotifyClaimantLrValidationDiscontinuanceFailureHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
.../handler/callback/camunda/notification/UpdateVisibilityNoticeOfDiscontinuanceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...back/camunda/notification/NotifyClaimantLrValidationDiscontinuanceFailureHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...dler/callback/camunda/notification/UpdateVisibilityNoticeOfDiscontinuanceHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.