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-15613 Order Review Obligation Changes #5919

Open
wants to merge 10 commits into
base: feat/CIV-15265
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ManageStayCallbackHandler extends CallbackHandler {
@Override
protected Map<String, Callback> callbacks() {
return Map.of(
callbackKey(ABOUT_TO_START), this::emptyCallbackResponse,
callbackKey(ABOUT_TO_START), this::handleAboutToStart,
callbackKey(ABOUT_TO_SUBMIT), this::handleAboutToSubmit,
callbackKey(SUBMITTED), this::handleSubmitted
);
Expand All @@ -68,6 +68,17 @@ private CallbackResponse handleSubmitted(CallbackParams params) {
return featureToggleService.isCaseEventsEnabled() ? addConfirmationScreen(params) : emptyCallbackResponse(params);
}

private CallbackResponse handleAboutToStart(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();

caseDataBuilder.manageStayOption(null);

return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(mapper))
.build();
}

private CallbackResponse manageStay(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
import uk.gov.hmcts.reform.civil.callback.CallbackHandler;
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.CaseData;
import uk.gov.hmcts.reform.civil.model.ObligationData;
import uk.gov.hmcts.reform.civil.model.ObligationWAFlag;
import uk.gov.hmcts.reform.civil.model.common.Element;
import uk.gov.hmcts.reform.civil.service.FeatureToggleService;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

import static java.util.Objects.isNull;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.ORDER_REVIEW_OBLIGATION_CHECK;

Expand All @@ -41,28 +45,40 @@ protected Map<String, Callback> callbacks() {
}

private CallbackResponse orderReviewObligationCheck(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData().toBuilder()
.build();

CaseData caseData = callbackParams.getCaseData();
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d MMMM yyyy");

caseData.setObligationWAFlag(null);

caseData.getStoredObligationData().stream()
.map(Element::getValue)
.filter(data -> !data.getObligationDate().isAfter(currentDate) && YesOrNo.NO.equals(data.getObligationWATaskRaised()))
.forEach(data -> {
data.setObligationWATaskRaised(YesOrNo.YES);
// TODO: add logic here to trigger WA tasks for obligations that are due
});

CaseData.CaseDataBuilder<?, ?> updatedCaseData = caseData.toBuilder();
.findFirst()
.ifPresent(data -> {
ObligationWAFlag.ObligationWAFlagBuilder obligationWAFlagBuilder = ObligationWAFlag.builder();
boolean isLiftAStay = ObligationReason.LIFT_A_STAY.equals(data.getObligationReason());
boolean isDismissCase = ObligationReason.DISMISS_CASE.equals(data.getObligationReason());
boolean isCaseDismissed = CaseState.CASE_DISMISSED.equals(caseData.getCcdState());
String manageStayOption = caseData.getManageStayOption();

List<Element<ObligationData>> storedObligationDataList = caseData.getStoredObligationData();
if ((!isLiftAStay && !isDismissCase) || (isLiftAStay && isNull(manageStayOption))
|| (isDismissCase && !isCaseDismissed)) {
obligationWAFlagBuilder.currentDate(currentDate.format(formatter))
.obligationReason(data.getObligationReason().name())
.obligationReasonDisplayValue(data.getObligationReason().getDisplayedValue());
}

updatedCaseData.storedObligationData(storedObligationDataList);
data.setObligationWATaskRaised(YesOrNo.YES);
caseData.setObligationWAFlag(obligationWAFlagBuilder.build());
});

return AboutToStartOrSubmitCallbackResponse.builder()
.data(updatedCaseData.build().toMap(mapper))
.data(caseData.toBuilder()
.storedObligationData(caseData.getStoredObligationData())
.obligationWAFlag(caseData.getObligationWAFlag())
.build().toMap(mapper))
.build();

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ public boolean hasNoOngoingBusinessProcess() {
private String messageHistory;
private DynamicList messagesToReplyTo;
private List<Element<Message>> messages;
private ObligationWAFlag obligationWAFlag;

/**
* There are several fields that can hold the I2P of applicant1 depending
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.gov.hmcts.reform.civil.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

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

private String obligationReason;
private String obligationReasonDisplayValue;
private String currentDate;
}
Loading
Loading