From 2130713a2edf097be916e96b127143e852d1e76c Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Thu, 12 Dec 2024 17:40:03 +0000 Subject: [PATCH 1/2] remove confidential order --- .../orderCollectionConfidential.json | 27 ++++ .../fpl/model/ConfidentialOrderBundle.java | 2 + .../GeneratedOrderRemovalAction.java | 29 ++++- .../removeorder/RemoveOrderService.java | 2 +- .../GeneratedOrderRemovalActionTest.java | 119 ++++++++++++++++++ 5 files changed, 176 insertions(+), 3 deletions(-) diff --git a/ccd-definition/AuthorisationCaseField/CareSupervision/orderCollectionConfidential.json b/ccd-definition/AuthorisationCaseField/CareSupervision/orderCollectionConfidential.json index 9780fb9daf2..bc50a4ac4f0 100644 --- a/ccd-definition/AuthorisationCaseField/CareSupervision/orderCollectionConfidential.json +++ b/ccd-definition/AuthorisationCaseField/CareSupervision/orderCollectionConfidential.json @@ -8,6 +8,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -25,6 +26,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -52,6 +54,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -75,6 +78,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -98,6 +102,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -121,6 +126,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -144,6 +150,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -167,6 +174,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -190,6 +198,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -213,6 +222,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -236,6 +246,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -259,6 +270,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -282,6 +294,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -306,6 +319,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -330,6 +344,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -354,6 +369,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -378,6 +394,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -402,6 +419,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -426,6 +444,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -450,6 +469,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -474,6 +494,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -498,6 +519,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -522,6 +544,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -546,6 +569,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -570,6 +594,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -594,6 +619,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" @@ -618,6 +644,7 @@ "UserRoles": [ "caseworker-publiclaw-courtadmin", "caseworker-publiclaw-systemupdate", + "caseworker-publiclaw-superuser", "caseworker-publiclaw-gatekeeper", "caseworker-publiclaw-judiciary", "caseworker-publiclaw-magistrate" diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java index 3a1d2bc0c70..d0b8cb2b45f 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import org.apache.commons.lang3.StringUtils; import uk.gov.hmcts.reform.fpl.model.common.Element; +import uk.gov.hmcts.reform.fpl.utils.ElementUtils; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -10,6 +11,7 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.function.BiConsumer; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalAction.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalAction.java index 17133ce66a6..7d1095d0841 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalAction.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalAction.java @@ -4,11 +4,14 @@ import uk.gov.hmcts.reform.fpl.exceptions.removaltool.RemovableOrderOrApplicationNotFoundException; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.Child; +import uk.gov.hmcts.reform.fpl.model.ConfidentialOrderBundle; import uk.gov.hmcts.reform.fpl.model.common.Element; import uk.gov.hmcts.reform.fpl.model.interfaces.RemovableOrder; import uk.gov.hmcts.reform.fpl.model.order.generated.GeneratedOrder; import uk.gov.hmcts.reform.fpl.utils.CaseDetailsMap; +import uk.gov.hmcts.reform.fpl.utils.ElementUtils; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -35,7 +38,14 @@ public void remove(CaseData caseData, GeneratedOrder generatedRemovableOrder = (GeneratedOrder) removableOrder; List> generatedOrders = caseData.getOrderCollection(); - boolean removed = generatedOrders.remove(element(removedOrderId, generatedRemovableOrder)); + boolean removed = false; + if (ElementUtils.findElement(removedOrderId, generatedOrders).isPresent()) { + removed = generatedOrders.remove(element(removedOrderId, generatedRemovableOrder)); + data.putIfNotEmpty("orderCollection", generatedOrders); + } else { + removed = removeConfidentialOrder(data, removedOrderId, generatedRemovableOrder, + caseData.getConfidentialOrders()); + } if (!removed) { throw new RemovableOrderOrApplicationNotFoundException(removedOrderId); @@ -51,7 +61,6 @@ public void remove(CaseData caseData, data.put("children1", removeFinalOrderPropertiesFromChildren(caseData, generatedRemovableOrder)); data.put("hiddenOrders", hiddenGeneratedOrders); - data.putIfNotEmpty("orderCollection", generatedOrders); } @Override @@ -91,4 +100,20 @@ private List> removeFinalOrderPropertiesFromChildren(CaseData cas return element; }).collect(Collectors.toList()); } + + private boolean removeConfidentialOrder(CaseDetailsMap data, UUID removedOrderId, + T removableOrder, + ConfidentialOrderBundle confidentialOrderBundle) { + final List fieldNames = new ArrayList<>(); + confidentialOrderBundle.processAllConfidentialOrders((suffix, orders) -> { + if (orders != null && orders.remove(element(removedOrderId, removableOrder))) { + String fieldName = confidentialOrderBundle.getFieldBaseName() + suffix; + data.putIfNotEmpty(fieldName, orders); + fieldNames.add(fieldName); + } + }); + + // Same order can potentially exist in multiple collection. + return !fieldNames.isEmpty(); + } } diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/RemoveOrderService.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/RemoveOrderService.java index cc0700fd772..8a52d4c8f5d 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/RemoveOrderService.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/RemoveOrderService.java @@ -95,7 +95,7 @@ private Optional getRemovedOrder( private List> getRemovableOrderList(CaseData caseData) { List> orders = new ArrayList<>(); - orders.addAll(caseData.getOrderCollection()); + orders.addAll(caseData.getAllOrderCollections()); orders.addAll(caseData.getSealedCMOs()); orders.addAll(getDraftHearingOrders(caseData)); diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalActionTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalActionTest.java index cb6725ad1ef..32fdae01baa 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalActionTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalActionTest.java @@ -8,6 +8,7 @@ import uk.gov.hmcts.reform.fpl.exceptions.removaltool.RemovableOrderOrApplicationNotFoundException; import uk.gov.hmcts.reform.fpl.model.CaseData; import uk.gov.hmcts.reform.fpl.model.Child; +import uk.gov.hmcts.reform.fpl.model.ConfidentialGeneratedOrders; import uk.gov.hmcts.reform.fpl.model.RemovalToolData; import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; import uk.gov.hmcts.reform.fpl.model.common.Element; @@ -482,6 +483,124 @@ void shouldPopulateGeneratedOrderCaseFieldsFromRemovedUploadedOrder() { generatedOrder.getRemovalReason()); } + @Test + void shouldPopulateGeneratedOrderCaseFieldsFromConfidentialOrder() { + String orderType = "Appointment of a children's guardian (C47A)"; + + GeneratedOrder generatedOrder = GeneratedOrder.builder() + .type(orderType) + .title(null) + .dateOfIssue("15 June 2020") + .build(); + + DocumentReference document = DocumentReference.builder().build(); + generatedOrder = generatedOrder.toBuilder().document(document).build(); + + CaseData caseData = CaseData.builder() + .removalToolData(RemovalToolData.builder() + .reasonToRemoveOrder(REASON) + .build()) + .confidentialOrders(ConfidentialGeneratedOrders.builder() + .orderCollectionCTSC(newArrayList(element(TO_REMOVE_ORDER_ID, generatedOrder))) + .build()) + .build(); + + CaseDetailsMap caseDetailsMap = caseDetailsMap(CaseDetails.builder() + .data(Map.of()) + .build()); + + underTest.populateCaseFields(caseData, caseDetailsMap, TO_REMOVE_ORDER_ID, generatedOrder); + + assertThat(caseDetailsMap) + .extracting("orderToBeRemoved", + "orderTitleToBeRemoved", + "orderIssuedDateToBeRemoved", + "orderDateToBeRemoved") + .containsExactly(document, + orderType, + generatedOrder.getDateOfIssue(), + generatedOrder.getRemovalReason()); + } + + @Test + void shouldRemoveConfidentialOrder() { + GeneratedOrder generatedOrder = buildOrder( + NON_FINAL_ORDER_NEW, + "order 1", + DATE_OF_ISSUE, + newArrayList( + element(CHILD_ONE_ID, Child.builder() + .finalOrderIssued("Yes") + .finalOrderIssuedType("Some type") + .build()), + element(CHILD_TWO_ID, Child.builder() + .finalOrderIssued("Yes") + .finalOrderIssuedType("Some type") + .build()) + ), YesNo.NO.getValue() + ); + + JudgeAndLegalAdvisor emptyJudge = JudgeAndLegalAdvisor.builder().build(); + GeneratedOrder order = generatedOrder.toBuilder().judgeAndLegalAdvisor(emptyJudge).build(); + + CaseData caseData = CaseData.builder() + .removalToolData(RemovalToolData.builder() + .reasonToRemoveOrder(REASON) + .build()) + .children1(List.of( + element(CHILD_ONE_ID, Child.builder() + .finalOrderIssued("Yes") + .finalOrderIssuedType("Some type") + .build()), + element(CHILD_TWO_ID, Child.builder() + .finalOrderIssued("Yes") + .finalOrderIssuedType("Some type") + .build()) + )) + .confidentialOrders(ConfidentialGeneratedOrders.builder() + .orderCollectionCTSC(newArrayList(element(TO_REMOVE_ORDER_ID, order))) + .orderCollectionChild0(newArrayList(element(TO_REMOVE_ORDER_ID, order))) + .build()) + .build(); + + CaseDetailsMap caseDetailsMap = caseDetailsMap(CaseDetails.builder() + .data(Map.of()) + .build()); + + underTest.remove(caseData, caseDetailsMap, TO_REMOVE_ORDER_ID, order); + + assertThat(caseDetailsMap).isEqualTo(Map.of( + "children1", List.of( + element(CHILD_ONE_ID, Child.builder() + .finalOrderIssued("Yes") + .finalOrderIssuedType("Some type") + .build()), + element(CHILD_TWO_ID, Child.builder() + .finalOrderIssued("Yes") + .finalOrderIssuedType("Some type") + .build()) + ), + "hiddenOrders", List.of( + element(TO_REMOVE_ORDER_ID, buildOrder( + NON_FINAL_ORDER_NEW, + "order 1", + DATE_OF_ISSUE, + newArrayList( + element(CHILD_ONE_ID, Child.builder() + .finalOrderIssued("Yes") + .finalOrderIssuedType("Some type") + .build()), + element(CHILD_TWO_ID, Child.builder() + .finalOrderIssued("Yes") + .finalOrderIssuedType("Some type") + .build()) + ), + REASON, YesNo.NO.getValue() + ))) + )); + + } + private GeneratedOrder buildOrder(Order type, String title, LocalDateTime dateOfIssue, String markedFinal) { return GeneratedOrder.builder() .type(type.getHistoryTitle()) From 4816f6f5337bac898412fe99eedc59dc45d6a7ab Mon Sep 17 00:00:00 2001 From: "Chak Shing, Lo" Date: Fri, 13 Dec 2024 10:01:40 +0000 Subject: [PATCH 2/2] fix code style check --- .../gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java | 2 -- .../fpl/service/removeorder/GeneratedOrderRemovalAction.java | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java index d0b8cb2b45f..3a1d2bc0c70 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/ConfidentialOrderBundle.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import org.apache.commons.lang3.StringUtils; import uk.gov.hmcts.reform.fpl.model.common.Element; -import uk.gov.hmcts.reform.fpl.utils.ElementUtils; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -11,7 +10,6 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.function.BiConsumer; diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalAction.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalAction.java index 7d1095d0841..60698ceb393 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalAction.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/service/removeorder/GeneratedOrderRemovalAction.java @@ -106,11 +106,11 @@ private boolean removeConfidentialOrder(CaseDetailsMap data, UUID removedOrd ConfidentialOrderBundle confidentialOrderBundle) { final List fieldNames = new ArrayList<>(); confidentialOrderBundle.processAllConfidentialOrders((suffix, orders) -> { - if (orders != null && orders.remove(element(removedOrderId, removableOrder))) { + if (orders != null && orders.remove(element(removedOrderId, removableOrder))) { String fieldName = confidentialOrderBundle.getFieldBaseName() + suffix; data.putIfNotEmpty(fieldName, orders); fieldNames.add(fieldName); - } + } }); // Same order can potentially exist in multiple collection.