Skip to content

Commit

Permalink
RIA-9527: Fix ManageFeeUpdateMidEvent conditions on case FEE_REMISSIO…
Browse files Browse the repository at this point in the history
…N_CHANGED (#2333)
  • Loading branch information
ikirsanov authored Aug 28, 2024
1 parent 9fe4dc4 commit 7dcbb67
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay.BEFORE_HEARING_DATE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay.ON_HEARING_DATE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption.WILL_PAY_FOR_APPEAL;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlagType.AUDIO_VIDEO_EVIDENCE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlagType.FOREIGN_NATIONAL_OFFENDER;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlagType.LACKING_CAPACITY;
Expand All @@ -29,6 +30,8 @@
import uk.gov.hmcts.reform.iacaseapi.domain.entities.DynamicList;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingAdjournmentDay;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.HearingCentre;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.StrategicCaseFlag;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CaseDetails;
Expand Down Expand Up @@ -333,4 +336,10 @@ public static boolean isRemissionExists(Optional<RemissionType> remissionType) {
return remissionType.isPresent()
&& remissionType.get() != RemissionType.NO_REMISSION;
}

public static boolean isRemissionExistsAip(Optional<RemissionOption> remissionOption, Optional<HelpWithFeesOption> helpWithFeesOption, boolean isDlrmFeeRemissionFlag) {
return isDlrmFeeRemissionFlag
&& ((remissionOption.isPresent() && remissionOption.get() != RemissionOption.NO_REMISSION)
|| (helpWithFeesOption.isPresent() && helpWithFeesOption.get() != WILL_PAY_FOR_APPEAL));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_COMPLETED_STAGES;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_REASON;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FEE_UPDATE_STATUS;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HELP_WITH_FEES_OPTION;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.LATE_REMISSION_TYPE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.NEW_FEE_AMOUNT;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_DECISION;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_OPTION;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_TYPE;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision.APPROVED;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision.PARTIALLY_APPROVED;
import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isAipJourney;
import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExists;
import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExistsAip;

import java.math.BigDecimal;
import java.util.Arrays;
Expand All @@ -20,7 +24,9 @@
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.FeeUpdateReason;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.CheckValues;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
Expand Down Expand Up @@ -91,7 +97,12 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
Optional<RemissionType> remissionType = asylumCase.read(REMISSION_TYPE, RemissionType.class);
Optional<RemissionType> lateRemissionType = asylumCase.read(LATE_REMISSION_TYPE, RemissionType.class);

if (!isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType)) {
final boolean isDlrmFeeRemissionFlag = featureToggler.getValue("dlrm-fee-remission-feature-flag", false);
Optional<RemissionOption> remissionOption = asylumCase.read(REMISSION_OPTION, RemissionOption.class);
Optional<HelpWithFeesOption> helpWithFeesOption = asylumCase.read(HELP_WITH_FEES_OPTION, HelpWithFeesOption.class);

if ((!isAipJourney(asylumCase) && !isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType))
|| (isAipJourney(asylumCase) && !isRemissionExistsAip(remissionOption, helpWithFeesOption, isDlrmFeeRemissionFlag))) {

callbackResponse.addError(
"You cannot choose this option because there is no remission request associated with this appeal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption.WILL_PAY_FOR_APPEAL;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionOption.NO_REMISSION;
import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExists;
import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExistsAip;

import java.util.Arrays;
import java.util.Optional;
Expand Down Expand Up @@ -42,8 +41,8 @@ public boolean canHandle(
requireNonNull(callback, "callback must not be null");

return callbackStage == PreSubmitCallbackStage.ABOUT_TO_START
&& callback.getEvent() == Event.RECORD_REMISSION_DECISION
&& featureToggler.getValue("remissions-feature", false);
&& callback.getEvent() == Event.RECORD_REMISSION_DECISION
&& featureToggler.getValue("remissions-feature", false);
}

public PreSubmitCallbackResponse<AsylumCase> handle(
Expand All @@ -70,6 +69,8 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
case EU:
case PA:
case AG:
final boolean isDlrmFeeRemissionFlag = featureToggler.getValue("dlrm-fee-remission-feature-flag", false);

Optional<PaymentStatus> paymentStatus = asylumCase.read(PAYMENT_STATUS, PaymentStatus.class);

Optional<RemissionType> remissionType = asylumCase.read(REMISSION_TYPE, RemissionType.class);
Expand All @@ -81,7 +82,7 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
Optional<RemissionDecision> remissionDecision =
asylumCase.read(REMISSION_DECISION, RemissionDecision.class);

if (!isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType) && !isRemissionExistsAip(remissionOptionAip, helpWithFeesOptionAip)) {
if (!isRemissionExists(remissionType) && !isRemissionExists(lateRemissionType) && !isRemissionExistsAip(remissionOptionAip, helpWithFeesOptionAip, isDlrmFeeRemissionFlag)) {

callbackResponse.addError("You cannot record a remission decision because a remission has not been requested for this appeal");

Expand All @@ -90,7 +91,7 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
callbackResponse.addError("The fee for this appeal has already been paid.");

} else if (remissionDecision.isPresent()
&& Arrays.asList(APPROVED, PARTIALLY_APPROVED, REJECTED).contains(remissionDecision.get())) {
&& Arrays.asList(APPROVED, PARTIALLY_APPROVED, REJECTED).contains(remissionDecision.get())) {

callbackResponse.addError("The remission decision for this appeal has already been recorded.");

Expand All @@ -113,21 +114,13 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
return callbackResponse;
}

private boolean isRemissionExistsAip(Optional<RemissionOption> remissionOption, Optional<HelpWithFeesOption> helpWithFeesOption) {
boolean isDlrmFeeRemission = featureToggler.getValue("dlrm-fee-remission-feature-flag", false);

return (remissionOption.isPresent() && remissionOption.get() != NO_REMISSION)
|| (helpWithFeesOption.isPresent() && helpWithFeesOption.get() != WILL_PAY_FOR_APPEAL)
&& isDlrmFeeRemission;
}

private boolean isRemissionAmountLeftPaid(
Optional<RemissionDecision> remissionDecision, Optional<PaymentStatus> paymentStatus
) {

return remissionDecision.isPresent()
&& Arrays.asList(PARTIALLY_APPROVED, REJECTED).contains(remissionDecision.get())
&& paymentStatus.isPresent()
&& Arrays.asList(PaymentStatus.PAID).contains(paymentStatus.get());
&& Arrays.asList(PARTIALLY_APPROVED, REJECTED).contains(remissionDecision.get())
&& paymentStatus.isPresent()
&& Arrays.asList(PaymentStatus.PAID).contains(paymentStatus.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AppealType.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption.WILL_PAY_FOR_APPEAL;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionType.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExists;
import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExistsAip;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -101,7 +101,8 @@ private void checkRemissionConditions(AppealType appealType, AsylumCase asylumCa
if (isAipJourney) {
Optional<RemissionOption> remissionOption = asylumCase.read(REMISSION_OPTION, RemissionOption.class);
Optional<HelpWithFeesOption> helpWithFeesOption = asylumCase.read(HELP_WITH_FEES_OPTION, HelpWithFeesOption.class);
if (!isRemissionExistsAip(remissionOption, helpWithFeesOption)) {
final boolean isDlrmFeeRemissionFlag = featureToggler.getValue("dlrm-fee-remission-feature-flag", false);
if (!isRemissionExistsAip(remissionOption, helpWithFeesOption, isDlrmFeeRemissionFlag)) {
callbackResponse.addError(NOT_AVAILABLE_LABEL);
}
} else {
Expand Down Expand Up @@ -166,14 +167,6 @@ private void checkPaymentConditions(AppealType appealType, AsylumCase asylumCase
}
}

private boolean isRemissionExistsAip(Optional<RemissionOption> remissionOption, Optional<HelpWithFeesOption> helpWithFeesOption) {
boolean isDlrmFeeRemission = featureToggler.getValue("dlrm-fee-remission-feature-flag", false);

return (remissionOption.isPresent() && remissionOption.get() != RemissionOption.NO_REMISSION)
|| (helpWithFeesOption.isPresent() && helpWithFeesOption.get() != WILL_PAY_FOR_APPEAL)
&& isDlrmFeeRemission;
}

private boolean awaitingRemissionDecision(AsylumCase asylumCase) {
Optional<RemissionType> lateRemissionType = asylumCase.read(LATE_REMISSION_TYPE, RemissionType.class);
Optional<RemissionType> remissionType = asylumCase.read(REMISSION_TYPE, RemissionType.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.HelpWithFeesOption.WILL_PAY_FOR_APPEAL;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.*;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.APPEAL_STARTED;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.APPEAL_STARTED_BY_ADMIN;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.APPEAL_SUBMITTED;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.State.PENDING_PAYMENT;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.FAILED;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.PAID;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.PAYMENT_PENDING;
import static uk.gov.hmcts.reform.iacaseapi.domain.handlers.HandlerUtils.isRemissionExistsAip;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -125,19 +123,12 @@ private static PreSubmitCallbackResponse<AsylumCase> decideAppealState(AppealTyp
}
}

private boolean isRemissionExistsAip(Optional<RemissionOption> remissionOption, Optional<HelpWithFeesOption> helpWithFeesOption) {
boolean isDlrmFeeRemission = featureToggler.getValue("dlrm-fee-remission-feature-flag", false);

return (remissionOption.isPresent() && remissionOption.get() != RemissionOption.NO_REMISSION)
|| (helpWithFeesOption.isPresent() && helpWithFeesOption.get() != WILL_PAY_FOR_APPEAL)
&& isDlrmFeeRemission;
}

private PreSubmitCallbackResponse<AsylumCase> handleDlrmFeeRemission(Callback<AsylumCase> callback, State currentState, boolean isPayLaterAppeal, boolean isPaymentStatusPaid) {
final boolean isDlrmFeeRemissionFlag = featureToggler.getValue("dlrm-fee-remission-feature-flag", false);
AsylumCase asylumCase = callback.getCaseDetails().getCaseData();
Optional<RemissionOption> remissionOption = asylumCase.read(REMISSION_OPTION, RemissionOption.class);
Optional<HelpWithFeesOption> helpWithFeesOption = asylumCase.read(HELP_WITH_FEES_OPTION, HelpWithFeesOption.class);
State state = isRemissionExistsAip(remissionOption, helpWithFeesOption)
State state = isRemissionExistsAip(remissionOption, helpWithFeesOption, isDlrmFeeRemissionFlag)
&& !isPayLaterAppeal && !isPaymentStatusPaid ? PENDING_PAYMENT : APPEAL_SUBMITTED;
if (isValidPayLaterPaymentEvent(callback, currentState, isPayLaterAppeal)) {
state = currentState;
Expand Down
Loading

0 comments on commit 7dcbb67

Please sign in to comment.