Skip to content

Commit

Permalink
DFPL-2610: Migration to remove locations from legal basis (#5720)
Browse files Browse the repository at this point in the history
* DFPL-2610: Migration to remove locations from legal basis

* add tests for 2585 back

* checkstyle
  • Loading branch information
AlistairEdwinOsborne authored Nov 21, 2024
1 parent 50d4a33 commit acc6bca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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.CaseRole;
import uk.gov.hmcts.reform.fpl.enums.State;
import uk.gov.hmcts.reform.fpl.model.CaseData;
import uk.gov.hmcts.reform.fpl.model.Judge;
Expand Down Expand Up @@ -49,9 +48,9 @@ public class MigrateCaseController extends CallbackController {

private final Map<String, Consumer<CaseDetails>> migrations = Map.of(
"DFPL-log", this::runLog,
"DFPL-2610", this::run2610,
"DFPL-2585", this::run2585,
"DFPL-2585Rollback", this::run2585Rollback,
"DFPL-2605", this::run2605
"DFPL-2585Rollback", this::run2585Rollback
);
private final CaseConverter caseConverter;
private final JudicialService judicialService;
Expand Down Expand Up @@ -80,11 +79,26 @@ private void runLog(CaseDetails caseDetails) {
log.info("Logging migration on case {}", caseDetails.getId());
}

private void run2610(CaseDetails caseDetails) {
final String migrationId = "DFPL-2610";
final long expectedCaseId = 1722860335639318L;
CaseData firstInstanceCaseData = getCaseData(caseDetails);

migrateCaseService.doCaseIdCheck(caseDetails.getId(), expectedCaseId, migrationId);
caseDetails.getData().putAll(migrateCaseService
.removeCharactersFromThresholdDetails(firstInstanceCaseData, migrationId,
416, 423, "****"));

CaseData secondInstanceCaseData = getCaseData(caseDetails);
caseDetails.getData().putAll(migrateCaseService
.removeCharactersFromThresholdDetails(secondInstanceCaseData, migrationId,
462, 468, "****"));
}

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

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

Expand Down Expand Up @@ -122,15 +136,4 @@ private void run2585Rollback(CaseDetails caseDetails) {
log.info("Attempting to create {} roles on case {}", rolesToAssign.size(), caseData.getId());
judicialService.migrateJudgeRoles(rolesToAssign);
}

private void run2605(CaseDetails caseDetails) {
final String migrationId = "DFPL-2605";
final long expectedCaseId = 1669804298339297L;
final String orgId = "V9753KQ";
migrateCaseService.doCaseIdCheck(caseDetails.getId(), expectedCaseId, migrationId);

caseDetails.getData().putAll(migrateCaseService.updateOutsourcingPolicy(getCaseData(caseDetails),
orgId, CaseRole.EPSMANAGING.formattedName()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ public Map<String, Object> fixIncorrectCaseManagementLocation(CaseDetails caseDe
public Map<String, Object> removeCharactersFromThresholdDetails(CaseData caseData,
String migrationId,
int startIndex,
int endIndex) {
int endIndex,
String replacement) {
Long caseId = caseData.getId();
String thresholdDetails = caseData.getGrounds().getThresholdDetails();
String textToRemove;
Expand All @@ -953,7 +954,7 @@ public Map<String, Object> removeCharactersFromThresholdDetails(CaseData caseDat
migrationId, caseId));
}

thresholdDetails = thresholdDetails.replace(textToRemove, "");
thresholdDetails = thresholdDetails.replace(textToRemove, replacement);
Grounds updatedGrounds = caseData.getGrounds().toBuilder().thresholdDetails(thresholdDetails).build();

return Map.of("grounds", updatedGrounds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ void shouldRemoveSpecificStringFromThresholdDetails() {
.build();

Map<String, Object> updatedGrounds = underTest.removeCharactersFromThresholdDetails(caseData, MIGRATION_ID,
thresholdDetailsStartIndex, thresholdDetailsEndIndex);
thresholdDetailsStartIndex, thresholdDetailsEndIndex, "");

assertThat(updatedGrounds).extracting("grounds").isEqualTo(expectedGrounds);
}
Expand All @@ -2279,7 +2279,7 @@ void shouldThrowExceptionIfNoThresholdDetailsOrOutOfLimit() {
.build();

assertThatThrownBy(() -> underTest.removeCharactersFromThresholdDetails(caseData, MIGRATION_ID,
thresholdDetailsStartIndex, thresholdDetailsEndIndex))
thresholdDetailsStartIndex, thresholdDetailsEndIndex, ""))
.isInstanceOf(AssertionError.class)
.hasMessage(format("Migration {id = %s, case reference = %s},"
+ " threshold details is shorter than provided index",
Expand All @@ -2301,7 +2301,7 @@ void shouldThrowExceptionIfBlankText() {
.build();

assertThatThrownBy(() -> underTest.removeCharactersFromThresholdDetails(caseData, MIGRATION_ID,
thresholdDetailsStartIndex, thresholdDetailsEndIndex))
thresholdDetailsStartIndex, thresholdDetailsEndIndex, ""))
.isInstanceOf(AssertionError.class)
.hasMessage(format("Migration {id = %s, case reference = %s}, "
+ "threshold details does not contain provided text",
Expand Down

0 comments on commit acc6bca

Please sign in to comment.