-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DFPL-2631 Adds ability to remove refused orders through the removal t…
…ool (#5786) * Adds ability to remove refused orders through the removal tool * Fix to handle case where the refusedHearingOrders collection is null. * Add test for refused orders action to OrderRemovalActionsTest * Fix failing order action test. * Fix failing order action test. --------- Co-authored-by: Braimah101 <[email protected]>
- Loading branch information
1 parent
20c42e4
commit 8811cfb
Showing
7 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...in/java/uk/gov/hmcts/reform/fpl/service/removeorder/RefusedHearingOrderRemovalAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package uk.gov.hmcts.reform.fpl.service.removeorder; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.reform.fpl.model.CaseData; | ||
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.HearingOrder; | ||
import uk.gov.hmcts.reform.fpl.utils.CaseDetailsMap; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
import static uk.gov.hmcts.reform.fpl.enums.CMOStatus.RETURNED; | ||
import static uk.gov.hmcts.reform.fpl.enums.YesNo.NO; | ||
|
||
@Component | ||
@RequiredArgsConstructor(onConstructor_ = {@Autowired}) | ||
public class RefusedHearingOrderRemovalAction implements OrderRemovalAction { | ||
|
||
@Override | ||
public boolean isAccepted(RemovableOrder removableOrder) { | ||
return removableOrder instanceof HearingOrder && Optional.of((HearingOrder) removableOrder) | ||
.filter(this::isRemovableOrder) | ||
.isPresent(); | ||
} | ||
|
||
@Override | ||
public void populateCaseFields(CaseData caseData, CaseDetailsMap data, UUID removedOrderId, | ||
RemovableOrder removableOrder) { | ||
HearingOrder draftOrder = (HearingOrder) removableOrder; | ||
|
||
data.put("orderToBeRemoved", draftOrder.getOrder()); | ||
data.put("orderTitleToBeRemoved", draftOrder.getTitle()); | ||
data.put("showRemoveCMOFieldsFlag", EMPTY); | ||
data.put("showReasonFieldFlag", NO.getValue()); | ||
} | ||
|
||
@Override | ||
public void remove(CaseData caseData, CaseDetailsMap data, UUID removedOrderId, RemovableOrder removableOrder) { | ||
HearingOrder draftOrder = (HearingOrder) removableOrder; | ||
|
||
Element<HearingOrder> refusedHearingOrderElement = caseData.getRefusedHearingOrders() | ||
.stream() | ||
.filter(element -> element.getId().equals(removedOrderId)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalStateException("Failed to find refused hearing order")); | ||
|
||
List<Element<HearingOrder>> refusedHearingOrders = caseData.getRefusedHearingOrders(); | ||
refusedHearingOrders.removeIf(element -> element.getId().equals(refusedHearingOrderElement.getId())); | ||
data.putIfNotEmpty("refusedHearingOrders", refusedHearingOrders); | ||
} | ||
|
||
private boolean isRemovableOrder(HearingOrder hearingOrder) { | ||
return RETURNED == hearingOrder.getStatus(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...ava/uk/gov/hmcts/reform/fpl/service/removeorder/RefusedHearingOrderRemovalActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package uk.gov.hmcts.reform.fpl.service.removeorder; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.jupiter.api.Test; | ||
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; | ||
import uk.gov.hmcts.reform.fpl.model.CaseData; | ||
import uk.gov.hmcts.reform.fpl.model.common.DocumentReference; | ||
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.HearingOrder; | ||
import uk.gov.hmcts.reform.fpl.utils.CaseDetailsMap; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static com.google.common.collect.Lists.newArrayList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
import static uk.gov.hmcts.reform.fpl.enums.CMOStatus.RETURNED; | ||
import static uk.gov.hmcts.reform.fpl.enums.HearingOrderType.DRAFT_CMO; | ||
import static uk.gov.hmcts.reform.fpl.enums.YesNo.NO; | ||
import static uk.gov.hmcts.reform.fpl.utils.CaseDetailsMap.caseDetailsMap; | ||
import static uk.gov.hmcts.reform.fpl.utils.DateFormatterHelper.formatLocalDateTimeBaseUsingFormat; | ||
import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.element; | ||
import static uk.gov.hmcts.reform.fpl.utils.TestDataHelper.testDocumentReference; | ||
|
||
class RefusedHearingOrderRemovalActionTest { | ||
|
||
public static final UUID ORDER_TO_REMOVE_ID = UUID.randomUUID(); | ||
|
||
private RefusedHearingOrderRemovalAction underTest = new RefusedHearingOrderRemovalAction(); | ||
|
||
@Test | ||
void acceptsReturnedOrder() { | ||
RemovableOrder order = HearingOrder.builder().status(RETURNED).build(); | ||
|
||
assertThat(underTest.isAccepted(order)).isTrue(); | ||
} | ||
|
||
@Test | ||
void shouldRaiseExceptionIfReturnedHearingIdNotFound() { | ||
DocumentReference order = testDocumentReference(); | ||
|
||
Element<HearingOrder> orderToBeRemoved = element(ORDER_TO_REMOVE_ID, returnedOrder(testDocumentReference())); | ||
Element<HearingOrder> anotherOrder = element(returnedOrder(order)); | ||
|
||
CaseData caseData = CaseData.builder() | ||
.refusedHearingOrders(newArrayList(anotherOrder)) | ||
.build(); | ||
|
||
CaseDetailsMap caseDetailsMap = caseDetailsMap(CaseDetails.builder().data(new HashMap<>()).build()); | ||
|
||
assertThatThrownBy(() -> underTest.remove(caseData, caseDetailsMap, ORDER_TO_REMOVE_ID, | ||
orderToBeRemoved.getValue())) | ||
.isInstanceOf(IllegalStateException.class) | ||
.hasMessage("Failed to find refused hearing order"); | ||
} | ||
|
||
@Test | ||
void shouldRemoveReturnedOrder() { | ||
DocumentReference order = testDocumentReference(); | ||
|
||
Element<HearingOrder> orderToBeRemoved = element(ORDER_TO_REMOVE_ID, returnedOrder(testDocumentReference())); | ||
Element<HearingOrder> anotherOrder = element(returnedOrder(order)); | ||
|
||
CaseData caseData = CaseData.builder() | ||
.refusedHearingOrders(newArrayList(orderToBeRemoved, anotherOrder)) | ||
.build(); | ||
|
||
CaseDetailsMap caseDetailsMap = caseDetailsMap(CaseDetails.builder().data(new HashMap<>()).build()); | ||
underTest.remove(caseData, caseDetailsMap, ORDER_TO_REMOVE_ID, orderToBeRemoved.getValue()); | ||
|
||
List<Object> expectedOrders = newArrayList(anotherOrder); | ||
|
||
assertThat(caseDetailsMap.get("refusedHearingOrders")).isEqualTo(expectedOrders); | ||
} | ||
|
||
@Test | ||
void shouldPopulateCaseFieldsFromRemovableReturnedOrder() { | ||
DocumentReference order = testDocumentReference(); | ||
|
||
Element<HearingOrder> orderToBeRemoved = element(ORDER_TO_REMOVE_ID, returnedOrder(testDocumentReference())); | ||
Element<HearingOrder> anotherOrder = element(returnedOrder(order)); | ||
|
||
CaseData caseData = CaseData.builder() | ||
.refusedHearingOrders(newArrayList(orderToBeRemoved, anotherOrder)) | ||
.build(); | ||
|
||
CaseDetailsMap caseDetailsMap = caseDetailsMap(CaseDetails.builder().data(new HashMap<>()).build()); | ||
|
||
underTest.populateCaseFields(caseData, caseDetailsMap, ORDER_TO_REMOVE_ID, orderToBeRemoved.getValue()); | ||
|
||
assertThat(caseDetailsMap) | ||
.extracting("orderToBeRemoved", | ||
"orderTitleToBeRemoved", | ||
"showRemoveCMOFieldsFlag", | ||
"showReasonFieldFlag") | ||
.containsExactly(orderToBeRemoved.getValue().getOrder(), | ||
orderToBeRemoved.getValue().getTitle(), | ||
StringUtils.EMPTY, | ||
NO.getValue()); | ||
} | ||
|
||
private HearingOrder returnedOrder(DocumentReference order) { | ||
return HearingOrder.builder() | ||
.type(DRAFT_CMO) | ||
.status(RETURNED) | ||
.order(order) | ||
.dateSent(LocalDate.now().minusWeeks(1)) | ||
.hearing("Draft Case management hearing sent on " | ||
+ formatLocalDateTimeBaseUsingFormat(LocalDateTime.now(), "d MMMM yyyy")) | ||
.build(); | ||
} | ||
} |