Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -46,7 +46,8 @@ public class MigrateCaseController extends CallbackController {
"DFPL-2740", this::run2740,
"DFPL-2744", this::run2744,
"DFPL-2739", this::run2739,
"DFPL-2756", this::run2756
"DFPL-2756", this::run2756,
"DFPL-2837", this::run2837
);
private final CaseConverter caseConverter;
private final JudicialService judicialService;
Expand Down Expand Up @@ -157,4 +158,16 @@ private void run2739(CaseDetails caseDetails) {
UUID.fromString("3ef67b37-17ee-48ca-9d32-58c887a6918d"),
UUID.fromString("dbe742bb-f7a1-4373-8100-52261c81ef34")));
}

private void run2837(CaseDetails caseDetails) {
CaseData caseData = getCaseData(caseDetails);

migrateCaseService.doCaseIdCheck(caseDetails.getId(), 1732700347667956L, "DFPL-2837");

caseDetails.getData().putAll(migrateCaseService.removeSupportingEvidenceBundleFromAdditionalApplication(
caseData,
"DFPL-2837",
UUID.fromString("bef6a7d7-0ee1-4984-b6a2-1cda165b5b92"),
UUID.fromString("4628b139-e483-4918-b809-ca5f065e7131")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import uk.gov.hmcts.reform.fpl.model.Respondent;
import uk.gov.hmcts.reform.fpl.model.SentDocuments;
import uk.gov.hmcts.reform.fpl.model.SkeletonArgument;
import uk.gov.hmcts.reform.fpl.model.SupportingEvidenceBundle;
import uk.gov.hmcts.reform.fpl.model.common.AdditionalApplicationsBundle;
import uk.gov.hmcts.reform.fpl.model.common.C2DocumentBundle;
import uk.gov.hmcts.reform.fpl.model.common.DocumentBundle;
Expand Down Expand Up @@ -1342,4 +1343,29 @@ public Map<String, Object> removeDraftOrderFromAdditionalApplication(CaseData ca

return Map.of("additionalApplicationsBundle", caseData.getAdditionalApplicationsBundle());
}

public Map<String, Object> removeSupportingEvidenceBundleFromAdditionalApplication(CaseData caseData,
String migrationId,
UUID bundleId, UUID docId) {
List<Element<AdditionalApplicationsBundle>> bundles = caseData.getAdditionalApplicationsBundle();

Element<AdditionalApplicationsBundle> bundle = ElementUtils.findElement(bundleId, bundles)
.orElseThrow(() -> new AssertionError(format(
"Migration {id = %s, case reference = %s}, additional application bundle not found",
migrationId, caseData.getId())));

C2DocumentBundle c2DocumentBundle = bundle.getValue().getC2DocumentBundle();
if (c2DocumentBundle == null || isEmpty(c2DocumentBundle.getSupportingEvidenceBundle())) {
throw new AssertionError(format(
"Migration {id = %s, case reference = %s}, C2DocumentBundle or SupportingEvidenceBundle is null",
migrationId, caseData.getId()));
}

List<Element<SupportingEvidenceBundle>> supportingEvidenceBundle =
ElementUtils.removeElementWithUUID(c2DocumentBundle.getSupportingEvidenceBundle(), docId);

c2DocumentBundle.setSupportingEvidenceBundle(supportingEvidenceBundle);

return Map.of("additionalApplicationsBundle", bundles);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3623,4 +3623,93 @@ void shouldThrowExceptionIfBundleNotFound() {
.hasMessageContaining("additional application bundle not found");
}
}

@Nested
class RemoveSupportingEvidenceBundleFromAdditionalApplication {
@Test
void shouldRemoveSupportingEvidenceBundleFromAdditionalApplication() {
UUID bundleId = UUID.randomUUID();
UUID evidenceToRemoveId = UUID.randomUUID();
UUID evidenceToRetainId = UUID.randomUUID();

Element<SupportingEvidenceBundle> evidenceToRemove = element(evidenceToRemoveId,
SupportingEvidenceBundle.builder().name("evidence to remove").build());

Element<SupportingEvidenceBundle> evidenceToRetain = element(evidenceToRetainId,
SupportingEvidenceBundle.builder().name("evidence to retain").build());

Element<AdditionalApplicationsBundle> applicationBundle = element(bundleId,
AdditionalApplicationsBundle.builder()
.c2DocumentBundle(C2DocumentBundle.builder()
.supportingEvidenceBundle(List.of(evidenceToRemove, evidenceToRetain))
.build())
.build());

Element<AdditionalApplicationsBundle> otherBundle = element(UUID.randomUUID(),
AdditionalApplicationsBundle.builder()
.c2DocumentBundle(C2DocumentBundle.builder()
.supportingEvidenceBundle(List.of(evidenceToRemove, evidenceToRetain))
.build())
.build());

CaseData caseData = CaseData.builder()
.id(1L)
.additionalApplicationsBundle(List.of(applicationBundle, otherBundle))
.build();

Map<String, Object> result = underTest.removeSupportingEvidenceBundleFromAdditionalApplication(caseData,
MIGRATION_ID, bundleId, evidenceToRemoveId);


Element<AdditionalApplicationsBundle> expectedBundle = element(bundleId,
AdditionalApplicationsBundle.builder()
.c2DocumentBundle(C2DocumentBundle.builder()
.supportingEvidenceBundle(List.of(evidenceToRetain))
.build())
.build());

assertThat(result).containsEntry("additionalApplicationsBundle", List.of(expectedBundle, otherBundle));
}

@Test
void shouldThrowExceptionIfBundleNotFound() {
UUID nonExistentBundleId = UUID.randomUUID();
UUID evidenceToRemoveId = UUID.randomUUID();

Stream.of(
CaseData.builder().id(1L).additionalApplicationsBundle(new ArrayList<>()).build(),
CaseData.builder().id(1L).additionalApplicationsBundle(null).build()
).forEach(caseData ->
assertThatThrownBy(() -> underTest.removeSupportingEvidenceBundleFromAdditionalApplication(caseData,
MIGRATION_ID, nonExistentBundleId, evidenceToRemoveId))
.isInstanceOf(AssertionError.class)
.hasMessageContaining("additional application bundle not found")
);
}

@Test
void shouldThrowExceptionIfC2OrEvidenceNotFound() {
UUID bundleId = UUID.randomUUID();
UUID evidenceToRemoveId = UUID.randomUUID();

Stream.of(
CaseData.builder()
.id(1L)
.additionalApplicationsBundle(List.of(
element(bundleId, AdditionalApplicationsBundle.builder().build())))
.build(),
CaseData.builder()
.id(1L)
.additionalApplicationsBundle(List.of(
element(bundleId, AdditionalApplicationsBundle.builder()
.c2DocumentBundle(C2DocumentBundle.builder().build()).build())))
.build()
).forEach(caseData ->
assertThatThrownBy(() -> underTest.removeSupportingEvidenceBundleFromAdditionalApplication(caseData,
MIGRATION_ID, bundleId, evidenceToRemoveId))
.isInstanceOf(AssertionError.class)
.hasMessageContaining("C2DocumentBundle or SupportingEvidenceBundle is null"));
;
}
}
}