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-4448: Add configuration for NFD case deletion #4252

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 4 additions & 1 deletion ccd-definitions/AuthorisationComplexType.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
{"CaseTypeID": "NFD", "CaseFieldID": "applicant2SolicitorOrganisationPolicy", "ListElementCode": "Organisation.OrganisationID", "UserRole": "caseworker-approver", "CRUD": "CRU"},
{"CaseTypeID": "NFD", "CaseFieldID": "applicant2SolicitorOrganisationPolicy", "ListElementCode": "Organisation.OrganisationName", "UserRole": "caseworker-approver", "CRUD": "CRU"},
{"CaseTypeID": "NFD", "CaseFieldID": "applicant2SolicitorOrganisationPolicy", "ListElementCode": "PrepopulateToUsersOrganisation", "UserRole": "caseworker-approver", "CRUD": "CRU"},
{"CaseTypeID": "NFD", "CaseFieldID": "applicant2SolicitorOrganisationPolicy", "ListElementCode": "PreviousOrganisations", "UserRole": "caseworker-approver", "CRUD": "CRU"}
{"CaseTypeID": "NFD", "CaseFieldID": "applicant2SolicitorOrganisationPolicy", "ListElementCode": "PreviousOrganisations", "UserRole": "caseworker-approver", "CRUD": "CRU"},
{"CaseTypeID": "NFD", "CaseFieldID": "timeToLive", "ListElementCode": "SystemTTL", "UserRole": "TTL_profile", "CRUD": "CRU"},
{"CaseTypeID": "NFD", "CaseFieldID": "timeToLive", "ListElementCode": "Suspended", "UserRole": "TTL_profile", "CRUD": "CU"},
{"CaseTypeID": "NFD", "CaseFieldID": "timeToLive", "ListElementCode": "OverrideTTL", "UserRole": "TTL_profile", "CRUD": "CU"}
]
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package uk.gov.hmcts.divorce.citizen.event;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.ccd.sdk.api.CCDConfig;
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.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.model.State;
import uk.gov.hmcts.divorce.divorcecase.model.UserRole;
import uk.gov.hmcts.divorce.idam.IdamService;
import uk.gov.hmcts.divorce.idam.User;
import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService;
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;

import static uk.gov.hmcts.divorce.common.ccd.CcdPageConfiguration.NEVER_SHOW;
import static uk.gov.hmcts.divorce.divorcecase.model.State.AwaitingApplicant1Response;
Expand All @@ -21,12 +29,19 @@
import static uk.gov.hmcts.divorce.divorcecase.model.State.RequestedInformationSubmitted;
import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.CREATOR;
import static uk.gov.hmcts.divorce.divorcecase.model.access.Permissions.CREATE_READ_UPDATE;
import static uk.gov.hmcts.divorce.systemupdate.event.SystemUpdateTTL.SYSTEM_UPDATE_TTL;

@Component
@RequiredArgsConstructor
@Slf4j
public class CitizenUpdateApplication implements CCDConfig<CaseData, State, UserRole> {

public static final String CITIZEN_UPDATE = "citizen-update-application";

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

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

Expand All @@ -40,4 +55,23 @@ public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuild
.description("Patch a divorce or dissolution")
.grant(CREATE_READ_UPDATE, CREATOR);
}

public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<CaseData, State> details,
CaseDetails<CaseData, State> beforeDetails) {

CaseData caseData = details.getData();

//Set TTL for newly created cases from today's date to 6 months in future
if (caseData.getTimeToLive() == null && details.getState() == Draft) {
final User user = idamService.retrieveSystemUpdateUserDetails();
final String serviceAuthorization = authTokenGenerator.generate();

ccdUpdateService.submitEvent(details.getId(), SYSTEM_UPDATE_TTL, user, serviceAuthorization);
}
FaisalMoJ marked this conversation as resolved.
Show resolved Hide resolved

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to set the TTL in citizenCreateApplication and solicitorCreateApplication to avoid old drafts being left from the start of the application process? It might work using ttlIncrement rather than a custom event

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TtlIncreament to be 180 days (6 months) as suggested

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package uk.gov.hmcts.divorce.common.service.task;

import lombok.RequiredArgsConstructor;
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.Application;
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 uk.gov.hmcts.divorce.idam.IdamService;
import uk.gov.hmcts.divorce.idam.User;
import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService;
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;

import static java.util.Objects.nonNull;
import static org.springframework.util.CollectionUtils.isEmpty;
Expand All @@ -15,11 +20,17 @@
import static uk.gov.hmcts.divorce.divorcecase.model.State.AwaitingPayment;
import static uk.gov.hmcts.divorce.divorcecase.model.State.Submitted;
import static uk.gov.hmcts.divorce.divorcecase.model.State.WelshTranslationReview;
import static uk.gov.hmcts.divorce.systemupdate.event.SystemUpdateTTL.SYSTEM_UPDATE_TTL;

@Component
@RequiredArgsConstructor
@Slf4j
public class SetStateAfterSubmission implements CaseTask {

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

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

Expand All @@ -38,14 +49,20 @@ public CaseDetails<CaseData, State> apply(final CaseDetails<CaseData, State> cas
boolean applicantNeedsHelpWithFees = (isSoleApplication && isHWFApplicant1)
|| (!isSoleApplication && isHWFApplicant1 && isHWFApplicant2);

final User user = idamService.retrieveSystemUpdateUserDetails();
final String serviceAuthorization = authTokenGenerator.generate();

if (applicantNeedsHelpWithFees) {
caseDetails.setState(AwaitingHWFDecision);
ccdUpdateService.submitEvent(caseDetails.getId(), SYSTEM_UPDATE_TTL, user, serviceAuthorization);
} else if (applicantIsAwaitingDocuments) {
caseDetails.setState(AwaitingDocuments);
ccdUpdateService.submitEvent(caseDetails.getId(), SYSTEM_UPDATE_TTL, user, serviceAuthorization);
} else if (!application.hasBeenPaidFor()) {
caseDetails.setState(AwaitingPayment);
} else {
caseDetails.setState(Submitted);
ccdUpdateService.submitEvent(caseDetails.getId(), SYSTEM_UPDATE_TTL, user, serviceAuthorization);
}

log.info("State set to {}, CaseID {}", caseDetails.getState(), caseDetails.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import uk.gov.hmcts.ccd.sdk.type.ListValue;
import uk.gov.hmcts.ccd.sdk.type.OrderSummary;
import uk.gov.hmcts.ccd.sdk.type.ScannedDocument;
import uk.gov.hmcts.ccd.sdk.type.TTL;
import uk.gov.hmcts.ccd.sdk.type.YesOrNo;
import uk.gov.hmcts.divorce.caseworker.model.CaseNote;
import uk.gov.hmcts.divorce.divorcecase.model.access.AcaSystemUserAccess;
Expand All @@ -31,6 +32,7 @@
import uk.gov.hmcts.divorce.divorcecase.model.access.DefaultAccess;
import uk.gov.hmcts.divorce.divorcecase.model.access.SolicitorAndSystemUpdateAccess;
import uk.gov.hmcts.divorce.divorcecase.model.access.SystemUpdateAndSuperUserAccess;
import uk.gov.hmcts.divorce.divorcecase.model.access.TtlProfileAccess;
import uk.gov.hmcts.divorce.document.model.DivorceDocument;
import uk.gov.hmcts.divorce.document.model.DocumentType;
import uk.gov.hmcts.divorce.noticeofchange.model.ChangeOfRepresentative;
Expand Down Expand Up @@ -328,6 +330,13 @@ public class CaseData {
@Builder.Default
private SentNotifications sentNotifications = new SentNotifications();

@CCD(
label = "Resolved time to live",
typeOverride = Collection,
access = {TtlProfileAccess.class}
FaisalMoJ marked this conversation as resolved.
Show resolved Hide resolved
)
private TTL timeToLive;

@JsonUnwrapped
@Builder.Default
private RequestForInformationList requestForInformationList = new RequestForInformationList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public enum UserRole implements HasRole {
JUDGE("caseworker-divorce-judge", "CRU"),
NOC_APPROVER("caseworker-approver", "CRU"),
RPA_ROBOT("caseworker-divorce-rparobot", "CRU"),
TTL_PROFILE("TTL_profile", "CRU"),
CFT_TTL_MANAGER("idam:cft-ttl-manager", "CRU"),

SOLICITOR("caseworker-divorce-solicitor", "CRU"),
APPLICANT_1_SOLICITOR("[APPONESOLICITOR]", "CRU"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.hmcts.divorce.divorcecase.model.access;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import uk.gov.hmcts.ccd.sdk.api.HasAccessControl;
import uk.gov.hmcts.ccd.sdk.api.HasRole;
import uk.gov.hmcts.ccd.sdk.api.Permission;

import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.TTL_PROFILE;

public class TtlProfileAccess implements HasAccessControl {
@Override
public SetMultimap<HasRole, Permission> getGrants() {

SetMultimap<HasRole, Permission> grants = HashMultimap.create();
grants.putAll(TTL_PROFILE, Permissions.CREATE_READ_UPDATE);

return grants;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package uk.gov.hmcts.divorce.systemupdate.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.ccd.sdk.api.CCDConfig;
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.TTL;
import uk.gov.hmcts.ccd.sdk.type.YesOrNo;
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 java.time.LocalDate;

import static uk.gov.hmcts.divorce.common.ccd.CcdPageConfiguration.NEVER_SHOW;
import static uk.gov.hmcts.divorce.divorcecase.model.State.AwaitingPayment;
import static uk.gov.hmcts.divorce.divorcecase.model.State.Draft;
import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.CFT_TTL_MANAGER;
import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.TTL_PROFILE;
import static uk.gov.hmcts.divorce.divorcecase.model.access.Permissions.CREATE_READ_UPDATE;

@Component
@Slf4j
public class SystemUpdateTTL implements CCDConfig<CaseData, State, UserRole> {

public static final String SYSTEM_UPDATE_TTL = "system-update-TTL";
private static final LocalDate CURRENT_DATE_PLUS_SIX_MONTH = LocalDate.now().plusMonths(6);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's static, it will get initialised once (when a pod starts), meaning that if we have long-running pods, the TTL will be too short for some cases


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

new PageBuilder(configBuilder
.event(SYSTEM_UPDATE_TTL)
.forStates(Draft, AwaitingPayment)
.name("Resolve time to live")
.showCondition(NEVER_SHOW)
.aboutToStartCallback(this::aboutToStart)
.description("Resolve time to live")
.grant(CREATE_READ_UPDATE, TTL_PROFILE));

configBuilder.caseRoleToAccessProfile(CFT_TTL_MANAGER).accessProfiles("TTL_profile").build();
}

public AboutToStartOrSubmitResponse<CaseData, State> aboutToStart(final CaseDetails<CaseData, State> details) {

log.info("{} about to start callback invoked for Case Id: {}", SYSTEM_UPDATE_TTL, details.getId());
final CaseData caseData = details.getData();

if (caseData.getTimeToLive() == null && details.getState() == Draft) {
caseData.setTimeToLive(TTL.builder().systemTTL(CURRENT_DATE_PLUS_SIX_MONTH)
.suspended(YesOrNo.NO)
.build());
} else {
caseData.setTimeToLive(null);
}
FaisalMoJ marked this conversation as resolved.
Show resolved Hide resolved

return AboutToStartOrSubmitResponse.<CaseData, State>builder()
.data(caseData)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,47 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
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.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.idam.IdamService;
import uk.gov.hmcts.divorce.idam.User;
import uk.gov.hmcts.divorce.systemupdate.service.CcdUpdateService;
import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator;
import uk.gov.hmcts.reform.idam.client.models.UserInfo;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.divorce.citizen.event.CitizenUpdateApplication.CITIZEN_UPDATE;
import static uk.gov.hmcts.divorce.divorcecase.model.State.Draft;
import static uk.gov.hmcts.divorce.divorcecase.model.State.Submitted;
import static uk.gov.hmcts.divorce.systemupdate.event.SystemUpdateTTL.SYSTEM_UPDATE_TTL;
import static uk.gov.hmcts.divorce.testutil.ConfigTestUtil.createCaseDataConfigBuilder;
import static uk.gov.hmcts.divorce.testutil.ConfigTestUtil.getEventsFrom;
import static uk.gov.hmcts.divorce.testutil.TestConstants.SYSTEM_UPDATE_AUTH_TOKEN;
import static uk.gov.hmcts.divorce.testutil.TestConstants.SYSTEM_USER_USER_ID;
import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_CASE_ID;
import static uk.gov.hmcts.divorce.testutil.TestConstants.TEST_SERVICE_AUTH_TOKEN;

@ExtendWith(MockitoExtension.class)
class CitizenUpdateApplicationTest {

@Mock
private IdamService idamService;

@Mock
private AuthTokenGenerator authTokenGenerator;

@Mock
private CcdUpdateService ccdUpdateService;

@InjectMocks
private CitizenUpdateApplication citizenUpdateApplication;

Expand All @@ -31,4 +57,39 @@ void shouldAddConfigurationToConfigBuilder() {
.extracting(Event::getId)
.contains(CITIZEN_UPDATE);
}

@Test
void shouldCallSystemUpdateTTLEventForDraftStateAndTTLNotSetAboutToSubmitCallback() {

var userDetails = UserInfo.builder().uid(SYSTEM_USER_USER_ID).build();
var user = new User(SYSTEM_UPDATE_AUTH_TOKEN, userDetails);
when(idamService.retrieveSystemUpdateUserDetails()).thenReturn(user);
when(authTokenGenerator.generate()).thenReturn(TEST_SERVICE_AUTH_TOKEN);

CaseDetails<CaseData, State> beforeDetails = getCaseDetails(Draft);

citizenUpdateApplication.aboutToSubmit(beforeDetails, beforeDetails);

verify(ccdUpdateService).submitEvent(beforeDetails.getId(), SYSTEM_UPDATE_TTL, user, TEST_SERVICE_AUTH_TOKEN);
}

@Test
void shouldNotCallSystemUpdateTTLEventForDraftStateAndTTLNotSetAboutToSubmitCallback() {

CaseDetails<CaseData, State> beforeDetails = getCaseDetails(Submitted);

citizenUpdateApplication.aboutToSubmit(beforeDetails, beforeDetails);

verifyNoInteractions(ccdUpdateService);
}

private CaseDetails<CaseData, State> getCaseDetails(State state) {
return CaseDetails.<CaseData, State>builder()
.id(TEST_CASE_ID)
.state(state)
.data(CaseData.builder()

.build())
.build();
}
}
Loading
Loading