Skip to content

Commit

Permalink
DFPL-2585: Setup closed case role cleanup migration (#5666)
Browse files Browse the repository at this point in the history
* DFPL-2585: Setup closed case role cleanup migration

* checkstyle

* revert accidental reformat
  • Loading branch information
DanCatchpole authored Nov 1, 2024
1 parent a1b0607 commit 6b074d2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.fpl.controllers.CallbackController;
import uk.gov.hmcts.reform.fpl.enums.State;
import uk.gov.hmcts.reform.fpl.service.CaseConverter;
import uk.gov.hmcts.reform.fpl.service.MigrateCaseService;
import uk.gov.hmcts.reform.fpl.service.RoleAssignmentService;
import uk.gov.hmcts.reform.fpl.service.orders.ManageOrderDocumentScopedFieldsCalculator;

import java.util.Map;
Expand All @@ -27,9 +29,11 @@ public class MigrateCaseController extends CallbackController {
public static final String MIGRATION_ID_KEY = "migrationId";
private final MigrateCaseService migrateCaseService;
private final ManageOrderDocumentScopedFieldsCalculator fieldsCalculator;
private final RoleAssignmentService roleAssignmentService;

private final Map<String, Consumer<CaseDetails>> migrations = Map.of(
"DFPL-log", this::runLog,
"DFPL-2585", this::run2585,
"DFPL-2579", this::run2579
);
private final CaseConverter caseConverter;
Expand Down Expand Up @@ -58,6 +62,14 @@ private void runLog(CaseDetails caseDetails) {
log.info("Logging migration on case {}", caseDetails.getId());
}

private void run2585(CaseDetails caseDetails) {
final String migrationId = "DFPL-2585";
migrateCaseService.doStateCheck(
caseDetails.getState(), State.CLOSED.toString(), caseDetails.getId(), migrationId);

roleAssignmentService.deleteAllRolesOnCase(caseDetails.getId());
}

private void run2579(CaseDetails caseDetails) {
final String migrationId = "DFPL-2579";
final long expectedCaseId = 1727273204426566L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ public Map<String, Object> removeHearingOrderBundleDraft(CaseData caseData, Stri
return Map.of("hearingOrdersBundlesDrafts", bundles);
}

public void doStateCheck(String state, String expectedState, long caseId, String migrationId)
throws AssertionError {
if (!state.equals(expectedState)) {
throw new AssertionError(format(
"Migration {id = %s, case reference = %s}, state was %s, expected %s",
migrationId, caseId, state, expectedState
));
}
}

public void doCaseIdCheck(long caseId, long expectedCaseId, String migrationId) throws AssertionError {
if (caseId != expectedCaseId) {
throw new AssertionError(format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ void shouldThrowExceptionIfCaseIdListCheckFails() {
assertThrows(AssertionError.class, () -> underTest.doCaseIdCheckList(1L, List.of(2L, 3L), MIGRATION_ID));
}

@Test
void shouldDoStateCheck() {
assertDoesNotThrow(() -> underTest.doStateCheck(
State.CASE_MANAGEMENT.toString(),
State.CASE_MANAGEMENT.toString(),
1L,
MIGRATION_ID));
}

@Test
void shouldThrowExceptionIfStateCheckFails() {
assertThrows(AssertionError.class, () -> underTest.doStateCheck(
State.CASE_MANAGEMENT.toString(),
State.CLOSED.toString(),
1L,
MIGRATION_ID
));
}

@Mock
private CaseConverter caseConverter;

Expand Down

0 comments on commit 6b074d2

Please sign in to comment.