Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFDIV-4319 - Set HMCTSService ID when case is being submitted #4261

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.ccd.sdk.type.YesOrNo;
import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService;
import uk.gov.hmcts.divorce.common.ccd.PageBuilder;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.model.State;
import uk.gov.hmcts.divorce.divorcecase.model.UserRole;
import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse;

import static uk.gov.hmcts.divorce.divorcecase.model.State.AwaitingDocuments;
import static uk.gov.hmcts.divorce.divorcecase.model.State.AwaitingHWFDecision;
Expand All @@ -34,6 +37,7 @@ public class CaseworkerHwfApplicationAccepted implements CCDConfig<CaseData, Sta
public static final String CASEWORKER_HWF_APPLICATION_ACCEPTED = "caseworker-hwf-application-accepted";

private final CaseworkerHwfApplicationAndPaymentHelper caseworkerHwfApplicationAndPaymentHelper;
private final CaseFlagsService caseFlagsService;

@Override
public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuilder) {
Expand All @@ -52,6 +56,7 @@ public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuild
.name("HWF application accepted")
.description("HWF application accepted")
.aboutToSubmitCallback(this::aboutToSubmit)
.submittedCallback(this::submitted)
.showEventNotes()
.grant(CREATE_READ_UPDATE, CASE_WORKER)
.grantHistoryOnly(SOLICITOR, SUPER_USER, LEGAL_ADVISOR, JUDGE));
Expand All @@ -62,13 +67,22 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(
log.info("{} about to submit callback invoked for Case Id: {}", CASEWORKER_HWF_APPLICATION_ACCEPTED, details.getId());
CaseData caseData = details.getData();

caseData.setCaseFlagsSetupComplete(YesOrNo.YES);

details.setState(caseworkerHwfApplicationAndPaymentHelper.getState(caseData));
details.setData(caseworkerHwfApplicationAndPaymentHelper.setDateSubmittedAndDueDate(caseData));
caseworkerHwfApplicationAndPaymentHelper.setRequiredCaseFieldsForPostSubmissionCase(details);

return AboutToStartOrSubmitResponse.<CaseData, State>builder()
.data(details.getData())
.state(details.getState())
.build();
}

public SubmittedCallbackResponse submitted(final CaseDetails<CaseData, State> details,
final CaseDetails<CaseData, State> beforeDetails) {
log.info("{} submitted callback invoked CaseID: {}", CASEWORKER_HWF_APPLICATION_ACCEPTED, details.getId());
caseFlagsService.setSupplementaryDataForCaseFlags(details.getId());
return SubmittedCallbackResponse.builder().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package uk.gov.hmcts.divorce.caseworker.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.divorce.idam.IdamService;
import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService;
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;

@Service
@RequiredArgsConstructor
@Slf4j
public class CaseFlagsService {

private final CcdUpdateService ccdUpdateService;
private final IdamService idamService;
private final AuthTokenGenerator authTokenGenerator;

public void setSupplementaryDataForCaseFlags(Long caseId) {

String sysUserToken = idamService.retrieveSystemUpdateUserDetails().getAuthToken();
String s2sToken = authTokenGenerator.generate();

ccdUpdateService.submitSupplementaryDataToCcdForServiceID(
caseId.toString(),
sysUserToken,
s2sToken
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService;
import uk.gov.hmcts.divorce.common.service.PaymentValidatorService;
import uk.gov.hmcts.divorce.common.service.SubmissionService;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.model.State;
import uk.gov.hmcts.divorce.divorcecase.model.UserRole;
import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse;

import java.util.List;

Expand All @@ -36,6 +38,8 @@ public class CitizenPaymentMade implements CCDConfig<CaseData, State, UserRole>

public static final String CITIZEN_PAYMENT_MADE = "citizen-payment-made";

private final CaseFlagsService caseFlagsService;

private final SubmissionService submissionService;

private final PaymentValidatorService paymentValidatorService;
Expand All @@ -51,7 +55,8 @@ public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuild
.retries(120, 120)
.grant(CREATE_READ_UPDATE, CITIZEN, SYSTEMUPDATE)
.grantHistoryOnly(SUPER_USER, CASE_WORKER, LEGAL_ADVISOR)
.aboutToSubmitCallback(this::aboutToSubmit);
.aboutToSubmitCallback(this::aboutToSubmit)
.submittedCallback(this::submitted);
}

public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(final CaseDetails<CaseData, State> details,
Expand Down Expand Up @@ -97,5 +102,12 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(final CaseDet
.state(updatedCaseDetails.getState())
.build();
}

public SubmittedCallbackResponse submitted(final CaseDetails<CaseData, State> details,
final CaseDetails<CaseData, State> beforeDetails) {
log.info("Add payment submitted callback invoked CaseID: {}", details.getId());
caseFlagsService.setSupplementaryDataForCaseFlags(details.getId());
return SubmittedCallbackResponse.builder().build();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.ccd.sdk.type.OrderSummary;
import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService;
import uk.gov.hmcts.divorce.common.service.SubmissionService;
import uk.gov.hmcts.divorce.divorcecase.model.Application;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.model.State;
import uk.gov.hmcts.divorce.divorcecase.model.UserRole;
import uk.gov.hmcts.divorce.payment.PaymentSetupService;
import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService;
import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse;

import java.util.List;

Expand Down Expand Up @@ -41,6 +44,12 @@ public class CitizenSubmitApplication implements CCDConfig<CaseData, State, User
@Autowired
private SubmissionService submissionService;

@Autowired
private CaseFlagsService caseFlagsService;

@Autowired
private CcdUpdateService ccdUpdateService;

@Override
public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuilder) {

Expand All @@ -53,7 +62,8 @@ public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuild
.retries(120, 120)
.grant(CREATE_READ_UPDATE, CITIZEN)
.grantHistoryOnly(CASE_WORKER, SUPER_USER, LEGAL_ADVISOR, JUDGE)
.aboutToSubmitCallback(this::aboutToSubmit);
.aboutToSubmitCallback(this::aboutToSubmit)
.submittedCallback(this::submitted);
}

public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<CaseData, State> details,
Expand Down Expand Up @@ -102,6 +112,14 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<C
.build();
}

public SubmittedCallbackResponse submitted(final CaseDetails<CaseData, State> details,
final CaseDetails<CaseData, State> beforeDetails) {
log.info("{} submitted callback invoked CaseID: {}", CITIZEN_SUBMIT, details.getId());
caseFlagsService.setSupplementaryDataForCaseFlags(details.getId());

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

public void prepareCaseDataForApplicationPayment(CaseData data, long caseId, String redirectUrl) {
Application application = data.getApplication();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uk.gov.hmcts.divorce.common.service.task.SendSubmissionNotifications;
import uk.gov.hmcts.divorce.common.service.task.SetApplicant2Email;
import uk.gov.hmcts.divorce.common.service.task.SetApplicantOfflineStatus;
import uk.gov.hmcts.divorce.common.service.task.SetCaseFlagsSetupStatus;
import uk.gov.hmcts.divorce.common.service.task.SetDateSubmitted;
import uk.gov.hmcts.divorce.common.service.task.SetDefaultOrganisationPolicies;
import uk.gov.hmcts.divorce.common.service.task.SetStateAfterSubmission;
Expand Down Expand Up @@ -34,6 +35,9 @@ public class SubmissionService {
@Autowired
private SetDefaultOrganisationPolicies setDefaultOrganisationPolicies;

@Autowired
private SetCaseFlagsSetupStatus setCaseFlagsSetupStatus;

public CaseDetails<CaseData, State> submitApplication(final CaseDetails<CaseData, State> caseDetails) {

return CaseTaskRunner.caseTasks(
Expand All @@ -42,7 +46,8 @@ public CaseDetails<CaseData, State> submitApplication(final CaseDetails<CaseData
setApplicant2Email,
setApplicantOfflineStatus,
setDefaultOrganisationPolicies,
sendSubmissionNotifications
sendSubmissionNotifications,
setCaseFlagsSetupStatus
).run(caseDetails);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package uk.gov.hmcts.divorce.common.service.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.model.State;
import uk.gov.hmcts.divorce.divorcecase.task.CaseTask;

import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES;

@Component
@Slf4j
public class SetCaseFlagsSetupStatus implements CaseTask {

@Override
public CaseDetails<CaseData, State> apply(final CaseDetails<CaseData, State> caseDetails) {

final CaseData caseData = caseDetails.getData();
caseData.setCaseFlagsSetupComplete(YES);

return caseDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ public class CaseData {
)
private YesOrNo isJudicialSeparation;

@CCD(
access = {DefaultAccess.class}
)
private YesOrNo caseFlagsSetupComplete;

@CCD(
label = "Previous Service Applications",
typeOverride = Collection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.ccd.sdk.type.OrderSummary;
import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService;
import uk.gov.hmcts.divorce.common.ccd.CcdPageConfiguration;
import uk.gov.hmcts.divorce.common.ccd.PageBuilder;
import uk.gov.hmcts.divorce.common.service.SubmissionService;
Expand All @@ -23,6 +24,7 @@
import uk.gov.hmcts.divorce.solicitor.event.page.SolPayment;
import uk.gov.hmcts.divorce.solicitor.event.page.SolPaymentSummary;
import uk.gov.hmcts.divorce.solicitor.event.page.SolStatementOfTruth;
import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse;

import java.math.BigDecimal;
import java.text.NumberFormat;
Expand Down Expand Up @@ -55,6 +57,7 @@ public class SolicitorSubmitApplication implements CCDConfig<CaseData, State, Us
private final SolPayment solPayment;
private final SubmissionService submissionService;
private final PaymentSetupService paymentSetupService;
private final CaseFlagsService caseFlagsService;

@Override
public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuilder) {
Expand Down Expand Up @@ -174,6 +177,13 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(final CaseDet
.build();
}

public SubmittedCallbackResponse submitted(final CaseDetails<CaseData, State> details,
final CaseDetails<CaseData, State> beforeDetails) {
log.info("{} submitted callback invoked CaseID: {}", SOLICITOR_SUBMIT, details.getId());
caseFlagsService.setSupplementaryDataForCaseFlags(details.getId());
return SubmittedCallbackResponse.builder().build();
}

private void updateApplicant2DigitalDetails(CaseData caseData) {
if (caseData.getApplicant2().getSolicitor() != null
&& caseData.getApplicant2().getSolicitor().getOrganisationPolicy() != null) {
Expand All @@ -195,6 +205,7 @@ private PageBuilder addEventConfig(final ConfigBuilder<CaseData, State, UserRole
.endButtonLabel("Submit Application")
.aboutToStartCallback(this::aboutToStart)
.aboutToSubmitCallback(this::aboutToSubmit)
.submittedCallback(this::submitted)
.grant(CREATE_READ_UPDATE, APPLICANT_1_SOLICITOR)
.grantHistoryOnly(
CASE_WORKER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class CcdUpdateService {

private static final String DIVORCE_CASE_SUBMISSION_EVENT_SUMMARY = "No Fault Divorce case submission event";
private static final String DIVORCE_CASE_SUBMISSION_EVENT_DESCRIPTION = "Submitting No Fault Divorce Case Event";
private static final String SERVICE_ID = "ABA1";
private static final String SERVICE_ID_FIELD = "HMCTSServiceId";
private static final String SET_OPERATION = "$set";

@Autowired
private CoreCaseDataApi coreCaseDataApi;
Expand Down Expand Up @@ -357,6 +360,17 @@ public void incrementOrgAssignedUsersSupplementaryData(final String caseId,
submitSupplementaryDataUpdateToCcd(caseId, authorisation, serviceAuth, supplementaryData);
}

public void submitSupplementaryDataToCcdForServiceID(final String caseId,
final String authorisation,
final String serviceAuth) {
log.info("submitSupplementaryDataToCcdForServiceID Case ID: {}", caseId);
Map<String, Map<String, Map<String, Object>>> supplementaryData = new HashMap<>();
supplementaryData.put("supplementary_data_updates",
singletonMap(SET_OPERATION,
singletonMap(SERVICE_ID_FIELD, SERVICE_ID)));
submitSupplementaryDataUpdateToCcd(caseId, authorisation, serviceAuth, supplementaryData);
}

private void submitSupplementaryDataUpdateToCcd(final String caseId,
final String authorisation,
final String serviceAuth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl;
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.type.YesOrNo;
import uk.gov.hmcts.divorce.caseworker.service.CaseFlagsService;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.model.State;
import uk.gov.hmcts.divorce.divorcecase.model.UserRole;
import uk.gov.hmcts.divorce.testutil.TestConstants;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
Expand All @@ -27,6 +30,9 @@ class CaseworkerHwfApplicationAcceptedTest {
@Mock
private CaseworkerHwfApplicationAndPaymentHelper caseworkerHwfApplicationAndPaymentHelper;

@Mock
private CaseFlagsService caseFlagsService;

@InjectMocks
private CaseworkerHwfApplicationAccepted caseworkerHwfApplicationAccepted;

Expand Down Expand Up @@ -66,4 +72,30 @@ void shouldSetDefaultCaseDataRequiredForPostSubmissionCases() {

verify(caseworkerHwfApplicationAndPaymentHelper).setRequiredCaseFieldsForPostSubmissionCase(caseDetails);
}

@Test
void shouldSetCaseFlagsSetupStatusInAboutToSubmit() {
final CaseData caseData = caseData();
final CaseDetails<CaseData, State> caseDetails = new CaseDetails<>();
caseDetails.setData(caseData);
caseData.setCaseFlagsSetupComplete(YesOrNo.YES);

when(caseworkerHwfApplicationAndPaymentHelper.setDateSubmittedAndDueDate(caseData)).thenReturn(caseData);

var response = caseworkerHwfApplicationAccepted.aboutToSubmit(caseDetails, null);

assertThat(response.getData().getCaseFlagsSetupComplete()).isEqualTo(YesOrNo.YES);
}

@Test
void shouldCallCaseFlagsServiceToSetHmctsServiceId() {
final CaseData caseData = caseData();
final CaseDetails<CaseData, State> caseDetails = new CaseDetails<>();
caseDetails.setData(caseData);
caseDetails.setId(TestConstants.TEST_CASE_ID);

caseworkerHwfApplicationAccepted.submitted(caseDetails, null);

verify(caseFlagsService).setSupplementaryDataForCaseFlags(TestConstants.TEST_CASE_ID);
}
}
Loading
Loading