Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIV-15614 - add obligations to notes tab #5930

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cdbbdd3
add confirm order review
laarmada Nov 14, 2024
255fa2f
add confirm order review
laarmada Nov 14, 2024
59a8308
add toggle
laarmada Nov 14, 2024
a0a1205
fix sonar coverage
laarmada Nov 14, 2024
0dbc401
Merge branch 'master' into CIV-15505_ConfirmOrderReview
mounikahmcts Nov 19, 2024
89978c7
Merge branch 'CIV-15505_ConfirmOrderReview' of https://github.com/hmc…
m-meulendijks-v1 Nov 20, 2024
a449e05
CIV-15720 - no obligation journey
m-meulendijks-v1 Nov 20, 2024
8fc157a
CIV-15720 - Add unit tests
m-meulendijks-v1 Nov 21, 2024
8d55186
CIV-15720 - refactor test for confirm order
m-meulendijks-v1 Nov 21, 2024
8322604
CIV-15720 delete notifications when case is stayed
kannan-v-hmcts Nov 18, 2024
25c2de7
CIV-15720 - checkstyle fixes
m-meulendijks-v1 Nov 21, 2024
c01491e
Merge branch 'feat/CIV-15720' into feat/CIV-15611
m-meulendijks-v1 Nov 21, 2024
1194b24
Update ServiceRequestAPIHandler.java
m-meulendijks-v1 Nov 21, 2024
afe1c91
CIV-15611 - confirm order test checkstyle fixes
m-meulendijks-v1 Nov 21, 2024
590a1f0
CIV-15611 - checkstyle fix
m-meulendijks-v1 Nov 21, 2024
5509558
CIV-15611 - flow state update
m-meulendijks-v1 Nov 21, 2024
b703039
CIV-15611 - change error format
m-meulendijks-v1 Nov 22, 2024
eb560ff
CIV-15611 - change confirmation header size
m-meulendijks-v1 Nov 22, 2024
6cd45db
Merge branch 'master' into feat/CIV-15611
m-meulendijks-v1 Nov 22, 2024
cdf28bc
CIV-15612 Obligation journey fields
miguelMolina3691 Nov 25, 2024
e86a566
CIV-15612 lint
miguelMolina3691 Nov 25, 2024
aac4c0c
Merge branch 'master' into feat/CIV-15612
miguelMolina3691 Nov 29, 2024
4f5e50f
Merge branch 'master' into feat/CIV-15612
miguelMolina3691 Dec 2, 2024
ce51da1
CIV-15612 obligation data screen
miguelMolina3691 Dec 2, 2024
c5303fd
CIV-15612 add storedObligationData
miguelMolina3691 Dec 2, 2024
a220d5b
CIV-15612 update test
miguelMolina3691 Dec 2, 2024
0f59d15
Merge branch 'master' into feat/CIV-15612
kannan-v-hmcts Dec 3, 2024
fbbdaad
Merge branch 'master' into feat/CIV-15612
miguelMolina3691 Dec 3, 2024
4e8997f
Merge branch 'master' into feat/CIV-15612
miguelMolina3691 Dec 10, 2024
5d0d1d8
Merge branch 'master' into feat/CIV-15612
miguelMolina3691 Dec 10, 2024
cfa4ce0
CIV-15612 add date validation
miguelMolina3691 Dec 12, 2024
b050189
CIV-15612 update
miguelMolina3691 Dec 12, 2024
26252b9
Merge branch 'master' into feat/CIV-15612
mounikahmcts Dec 13, 2024
ceaef4b
Merge branch 'master' into feat/CIV-15612
ss-evoco Dec 13, 2024
d50385f
Merge branch 'master' into feat/CIV-15612
ss-evoco Dec 13, 2024
1171531
CIV-15614 - Changes for obligation to show on case note tab
m-meulendijks-v1 Dec 16, 2024
1bcf1d2
CIV-15614 - fix checkstyle errors
m-meulendijks-v1 Dec 16, 2024
5a87620
Merge branch 'master' into feat/CIV-15614
m-meulendijks-v1 Dec 16, 2024
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 @@ -11,12 +11,16 @@
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.enums.CaseState;
import uk.gov.hmcts.reform.civil.enums.ObligationReason;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.ObligationData;
import uk.gov.hmcts.reform.civil.model.StoredObligationData;
import uk.gov.hmcts.reform.civil.model.common.Element;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;
import uk.gov.hmcts.reform.civil.service.Time;
import uk.gov.hmcts.reform.civil.service.UserService;
import uk.gov.hmcts.reform.idam.client.models.UserDetails;

import java.time.LocalDate;
import java.util.ArrayList;
Expand All @@ -29,12 +33,14 @@

import static java.lang.String.format;
import static java.util.Objects.nonNull;
import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CONFIRM_ORDER_REVIEW;
import static uk.gov.hmcts.reform.civil.enums.CourtStaffNextSteps.STILL_TASKS;
import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element;

@Service
@RequiredArgsConstructor
Expand All @@ -44,6 +50,8 @@ public class ConfirmOrderReviewCallbackHandler extends CallbackHandler {

private final FeatureToggleService featureToggleService;
private final ObjectMapper objectMapper;
private final UserService userService;
private final Time time;
private static final String HEADER_CONFIRMATION = "# The order review has been completed";
private static final String BODY_CONFIRMATION_NO_OBLIGATION = " ";
private static final String BODY_CONFIRMATION_OBLIGATION = "### What happens next \n\n" +
Expand Down Expand Up @@ -134,13 +142,30 @@ private CallbackResponse confirmOrderReview(CallbackParams callbackParams) {
}

if (nonNull(caseData.getObligationData())) {
UserDetails userDetails = userService.getUserDetails(callbackParams.getParams().get(BEARER_TOKEN).toString());
String officerName = userDetails.getFullName();

List<Element<ObligationData>> storedObligationData = Optional.ofNullable(caseData.getStoredObligationData())
List<Element<StoredObligationData>> storedObligationData = Optional.ofNullable(caseData.getStoredObligationData())
.orElse(Collections.emptyList());

List<Element<ObligationData>> combinedData = new ArrayList<>();
List<Element<StoredObligationData>> combinedData = new ArrayList<>();
combinedData.addAll(storedObligationData);
combinedData.addAll(caseData.getObligationData());

caseData.getObligationData().forEach(obligation -> {
StoredObligationData storedObligation = StoredObligationData.builder()
.createdBy(officerName)
.createdOn(time.now())
.obligationDate(obligation.getValue().getObligationDate())
.obligationReason(obligation.getValue().getObligationReason())
.otherObligationReason(obligation.getValue().getOtherObligationReason())
.reasonText(obligation.getValue().getObligationReason().equals(ObligationReason.OTHER)
? ObligationReason.OTHER.getDisplayedValue() + ": " + obligation.getValue().getOtherObligationReason()
: obligation.getValue().getObligationReason().getDisplayedValue())
.obligationAction(obligation.getValue().getObligationAction())
.build();

combinedData.add(element(storedObligation));
});

updatedCaseData.obligationData(null)
.storedObligationData(combinedData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.ExternalTaskData;
import uk.gov.hmcts.reform.civil.model.ObligationData;
import uk.gov.hmcts.reform.civil.model.StoredObligationData;
import uk.gov.hmcts.reform.civil.service.CoreCaseDataService;
import uk.gov.hmcts.reform.civil.service.data.ExternalTaskInput;

Expand Down Expand Up @@ -99,7 +99,7 @@ private String getObligationReasons(CaseData caseData) {
.orElse(Collections.emptyList())
.stream()
.map(element -> {
ObligationData data = element.getValue();
StoredObligationData data = element.getValue();
ObligationReason reason = data.getObligationReason();

if (reason == ObligationReason.OTHER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ public boolean hasNoOngoingBusinessProcess() {
private YesOrNo obligationDatePresent;
private CourtStaffNextSteps courtStaffNextSteps;
private List<Element<ObligationData>> obligationData;
private List<Element<ObligationData>> storedObligationData;
private List<Element<StoredObligationData>> storedObligationData;
private YesOrNo isFinalOrder;

private SendAndReplyOption sendAndReplyOption;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package uk.gov.hmcts.reform.civil.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import uk.gov.hmcts.reform.civil.enums.ObligationReason;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class StoredObligationData {

private String createdBy;
private LocalDateTime createdOn;
private LocalDate obligationDate;
private ObligationReason obligationReason;
private String otherObligationReason;
private String reasonText;
private String obligationAction;
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,61 @@
package uk.gov.hmcts.reform.civil.handler.callback.user;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.mockito.junit.jupiter.MockitoExtension;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.enums.CaseState;
import uk.gov.hmcts.reform.civil.enums.CourtStaffNextSteps;
import uk.gov.hmcts.reform.civil.enums.ObligationReason;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.ObligationData;
import uk.gov.hmcts.reform.civil.model.StoredObligationData;
import uk.gov.hmcts.reform.civil.model.common.Element;
import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;
import uk.gov.hmcts.reform.civil.service.Time;
import uk.gov.hmcts.reform.civil.service.UserService;
import uk.gov.hmcts.reform.idam.client.models.UserDetails;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

import java.time.LocalDate;
import java.util.List;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CONFIRM_ORDER_REVIEW;

@SpringBootTest(classes = {
ConfirmOrderReviewCallbackHandler.class,
JacksonAutoConfiguration.class,
})
@ExtendWith(MockitoExtension.class)
class ConfirmOrderReviewCallbackHandlerTest extends BaseCallbackHandlerTest {

@Autowired
private ConfirmOrderReviewCallbackHandler handler;

@MockBean
@Mock
private FeatureToggleService toggleService;
@Mock
private UserService userService;

private ObjectMapper objectMapper;

private static final String HEADER_CONFIRMATION = "# The order review has been completed";
private static final String BODY_CONFIRMATION_NO_OBLIGATION = "&nbsp;";
Expand All @@ -55,8 +67,15 @@ class ConfirmOrderReviewCallbackHandlerTest extends BaseCallbackHandlerTest {
private static final String TASKS_LEFT_ERROR_3 = "Once you have completed the task you can submit your order review by clicking on the link on your task list.";
private static final String OBLIGATION_DATE_ERROR = "The obligation date must be in the future";

@Mock
private Time time;

@BeforeEach
void caseEventsEnabled() {

objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
handler = new ConfirmOrderReviewCallbackHandler(toggleService, objectMapper, userService, time);
Mockito.when(toggleService.isCaseEventsEnabled()).thenReturn(true);
}

Expand Down Expand Up @@ -138,7 +157,6 @@ class AboutToSubmit {

@Test
void shouldConfirmOrderReview_whenInvoked() {

CaseData caseData = CaseData.builder()
.obligationDatePresent(YesOrNo.YES)
.courtStaffNextSteps(CourtStaffNextSteps.NO_TASKS)
Expand Down Expand Up @@ -180,6 +198,102 @@ void shouldSetAllFinalOrdersIssuedState_whenIsFinalOrder() {

assertThat(response.getState()).isEqualTo(CaseState.All_FINAL_ORDERS_ISSUED.name());
}

@Test
void shouldSetStoredObligationData_whenObligationDataIsPresent() {
LocalDateTime localDateTime = LocalDateTime.of(2024, 01, 01, 10, 10, 10);
Mockito.when(time.now()).thenReturn(localDateTime);
UUID uuid = UUID.fromString("818da749-8920-40c2-a083-722645735e02");
Mockito.when(userService.getUserDetails(any())).thenReturn(UserDetails
.builder()
.forename("John")
.surname("Smith")
.build());
Mockito.when(toggleService.isCaseEventsEnabled()).thenReturn(true);

LocalDate obligationDate = LocalDate.of(2024, 12, 12);
CaseData caseData = CaseData.builder()
.isFinalOrder(YesOrNo.YES)
.obligationData(List.of(Element.<ObligationData>builder()
.id(uuid)
.value(ObligationData.builder()
.obligationReason(ObligationReason.STAY_A_CASE)
.obligationDate(obligationDate)
.obligationAction("Main text")
.build()
)
.build()
)
)
.build();

StoredObligationData expectedData = StoredObligationData
.builder()
.createdBy("John Smith")
.createdOn(time.now())
.obligationDate(obligationDate)
.obligationAction("Main text")
.obligationReason(ObligationReason.STAY_A_CASE)
.reasonText(ObligationReason.STAY_A_CASE
.getDisplayedValue())
.build();

CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
CaseData data = objectMapper.convertValue(response.getData(), CaseData.class);

assertThat(data.getStoredObligationData().get(0).getValue()).isEqualTo(expectedData);
}

@Test
void shouldSetStoredObligationData_whenObligationDataIsPresent_withOtherReason() {
LocalDateTime localDateTime = LocalDateTime.of(2024, 01, 01, 10, 10, 10);
Mockito.when(time.now()).thenReturn(localDateTime);
UUID uuid = UUID.fromString("818da749-8920-40c2-a083-722645735e02");
Mockito.when(userService.getUserDetails(any())).thenReturn(UserDetails
.builder()
.forename("John")
.surname("Smith")
.build());
Mockito.when(toggleService.isCaseEventsEnabled()).thenReturn(true);

LocalDate obligationDate = LocalDate.of(2024, 12, 12);
CaseData caseData = CaseData.builder()
.isFinalOrder(YesOrNo.YES)
.obligationData(List.of(Element.<ObligationData>builder()
.id(uuid)
.value(ObligationData.builder()
.obligationReason(ObligationReason.OTHER)
.otherObligationReason("Reason for othering")
.obligationDate(obligationDate)
.obligationAction("Main text")
.build()
)
.build()
)
)
.build();

StoredObligationData expectedData = StoredObligationData
.builder()
.createdBy("John Smith")
.createdOn(time.now())
.obligationDate(obligationDate)
.obligationAction("Main text")
.obligationReason(ObligationReason.OTHER)
.otherObligationReason("Reason for othering")
.reasonText(ObligationReason.OTHER
.getDisplayedValue() + ": Reason for othering")
.build();

CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
CaseData data = objectMapper.convertValue(response.getData(), CaseData.class);

assertThat(data.getStoredObligationData().get(0).getValue()).isEqualTo(expectedData);
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter;
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.ObligationData;
import uk.gov.hmcts.reform.civil.model.StoredObligationData;
import uk.gov.hmcts.reform.civil.model.common.Element;
import uk.gov.hmcts.reform.civil.sampledata.CaseDetailsBuilder;
import uk.gov.hmcts.reform.civil.service.CoreCaseDataService;
Expand Down Expand Up @@ -81,7 +81,7 @@ void init() {
@Test
void shouldHaveCorrectEventDetails_whenObligationDataIsProvided() {
CaseData caseData = CaseData.builder()
.storedObligationData(List.of(Element.<ObligationData>builder().id(UUID.randomUUID()).value(ObligationData.builder().obligationReason(
.storedObligationData(List.of(Element.<StoredObligationData>builder().id(UUID.randomUUID()).value(StoredObligationData.builder().obligationReason(
ObligationReason.DISMISS_CASE).obligationDate(
null).obligationAction("action").build()).build()))
.businessProcess(
Expand Down
Loading