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

RIA-8064 - Telephony Payment - Payment reminder - Remission LR #2104

Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,9 @@ public enum AsylumCaseFieldDefinition {
FEE_UPDATE_TRIBUNAL_ACTION(
"feeUpdateTribunalAction", new TypeReference<FeeTribunalAction>(){}),

AUTOMATIC_REMISSION_REMINDER_LEGAL_REP(
"automaticRemissionReminderLegalRep", new TypeReference<String>(){}),

;

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public enum Event {
PIP_ACTIVATION("pipActivation"),
UPDATE_S94B_STATUS("updateS94bStatus"),
UPDATE_TRIBUNAL_DECISION("updateTribunalDecision"),
RECORD_REMISSION_REMINDER("recordRemissionReminder"),

@JsonEnumDefaultValue
UNKNOWN("unknown");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;

import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.REMISSION_DECISION;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.iacaseapi.domain.DateProvider;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.RemissionDecision;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.DispatchPriority;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.iacaseapi.domain.service.Scheduler;
import uk.gov.hmcts.reform.iacaseapi.infrastructure.clients.model.TimedEvent;

@Component
public class AutomaticPaymentReminderRemissionLegalRepTrigger implements PreSubmitCallbackHandler<AsylumCase> {
private final DateProvider dateProvider;
private final Scheduler scheduler;
@Value("${legalRepresentativeRemissionReminder.dueInMinutes}")
int schedule7DaysInMinutes;

public AutomaticPaymentReminderRemissionLegalRepTrigger(
DateProvider dateProvider,
Scheduler scheduler
) {
this.dateProvider = dateProvider;
this.scheduler = scheduler;
}

@Override
public DispatchPriority getDispatchPriority() {
return DispatchPriority.LATE;
}

public boolean canHandle(
PreSubmitCallbackStage callbackStage,
Callback<AsylumCase> callback
) {
requireNonNull(callbackStage, "callbackStage must not be null");
requireNonNull(callback, "callback must not be null");

return callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT
&& callback.getEvent() == Event.RECORD_REMISSION_DECISION;
}

public PreSubmitCallbackResponse<AsylumCase> handle(
PreSubmitCallbackStage callbackStage,
Callback<AsylumCase> callback
) {
if (!canHandle(callbackStage, callback)) {
throw new IllegalStateException("Cannot handle callback");
}

AsylumCase asylumCase = callback.getCaseDetails().getCaseData();

if (isRejectedOrPartiallyApproved(asylumCase)) {
ZonedDateTime scheduledDate = ZonedDateTime.of(dateProvider.nowWithTime(), ZoneId.systemDefault()).plusMinutes(schedule7DaysInMinutes);

TimedEvent timedEvent = scheduler.schedule(
new TimedEvent(
"",
Event.RECORD_REMISSION_REMINDER,
scheduledDate,
"IA",
"Asylum",
callback.getCaseDetails().getId()
)
);
asylumCase.write(AsylumCaseFieldDefinition.AUTOMATIC_REMISSION_REMINDER_LEGAL_REP, timedEvent.getId());
}
return new PreSubmitCallbackResponse<>(asylumCase);
}

private boolean isRejectedOrPartiallyApproved(AsylumCase asylumCase) {
return asylumCase.read(REMISSION_DECISION, RemissionDecision.class)
.map(decision -> decision == RemissionDecision.REJECTED || decision == RemissionDecision.PARTIALLY_APPROVED)
.orElse(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;

import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.AUTOMATIC_REMISSION_REMINDER_LEGAL_REP;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.PAYMENT_STATUS;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus.*;

import java.time.ZoneId;
import java.time.ZonedDateTime;

import java.util.Optional;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.iacaseapi.domain.DateProvider;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.DispatchPriority;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.PaymentStatus;
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.iacaseapi.domain.service.Scheduler;
import uk.gov.hmcts.reform.iacaseapi.infrastructure.clients.model.TimedEvent;

@Component
public class CancelAutomaticPaymentReminderRemissionLegalRepTrigger implements PreSubmitCallbackHandler<AsylumCase> {

private final boolean timedEventServiceEnabled;
private final DateProvider dateProvider;
private final Scheduler scheduler;

public CancelAutomaticPaymentReminderRemissionLegalRepTrigger(
@Value("${featureFlag.timedEventServiceEnabled}") boolean timedEventServiceEnabled,
DateProvider dateProvider,
Scheduler scheduler
) {
this.timedEventServiceEnabled = timedEventServiceEnabled;
this.dateProvider = dateProvider;
this.scheduler = scheduler;
}

@Override
public DispatchPriority getDispatchPriority() {
return DispatchPriority.LATE;
}

public boolean canHandle(
PreSubmitCallbackStage callbackStage,
Callback<AsylumCase> callback
) {
requireNonNull(callbackStage, "callbackStage must not be null");
requireNonNull(callback, "callback must not be null");

return timedEventServiceEnabled
&& callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT
&& callback.getEvent() == Event.RECORD_REMISSION_DECISION;
}

public PreSubmitCallbackResponse<AsylumCase> handle(
PreSubmitCallbackStage callbackStage,
Callback<AsylumCase> callback
) {
if (!canHandle(callbackStage, callback)) {
throw new IllegalStateException("Cannot handle callback");
}

AsylumCase asylumCase =
callback
.getCaseDetails()
.getCaseData();

Optional<String> timeEventId = asylumCase.read(AUTOMATIC_REMISSION_REMINDER_LEGAL_REP);

if (timeEventId.isPresent()) {
Optional<PaymentStatus> paymentStatus = asylumCase.read(PAYMENT_STATUS, PaymentStatus.class);
boolean isPaymentStatusPaid = paymentStatus.isPresent() && paymentStatus.get() == PAID;

if (isPaymentStatusPaid) {
int scheduleDelayInMinutes = 52560000;
ZonedDateTime scheduledDate = ZonedDateTime.of(dateProvider.nowWithTime(), ZoneId.systemDefault()).plusMinutes(scheduleDelayInMinutes);

scheduler.schedule(
new TimedEvent(
timeEventId.get(),
Event.RECORD_REMISSION_REMINDER,
scheduledDate,
"IA",
"Asylum",
callback.getCaseDetails().getId()
)
);
}
}

return new PreSubmitCallbackResponse<>(asylumCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ private List<Event> getEventsToHandle(Callback<AsylumCase> callback) {
Event.CREATE_CASE_LINK,
Event.MAINTAIN_CASE_LINKS,
Event.DECIDE_FTPA_APPLICATION,
Event.UPDATE_TRIBUNAL_DECISION
Event.UPDATE_TRIBUNAL_DECISION,
Event.RECORD_REMISSION_REMINDER
);
if (!isSaveAndContinueEnabled) {
eventsToHandle.add(Event.BUILD_CASE);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ requestRespondentEvidence.dueInDays: ${REQUEST_RESPONDENT_EVIDENCE_DUE_IN_DAYS:1
requestRespondentReview.dueInDays: ${REQUEST_RESPONDENT_REVIEW_DUE_IN_DAYS:14}
appellantReasonsForAppeal.dueInDays: ${APPELLANT_REASONS_FOR_APPEAL_DUE_IN_DAYS:28}
paymentAfterRemissionRejection.dueInMinutes: ${PAYMENT_AFTER_REMISSION_REJECTION_DUE_IN_MINUTES:20160}
legalRepresentativeRemissionReminder.dueInMinutes: ${LEGAL_REP_REMISSION_REMINDER_DUE_IN_MINUTES:10080}
paymentEaHuNoRemission.dueInMinutes: ${PAYMENT_EA_HU_NO_REMISSION_DUE_IN_MINUTES:20160}

core_case_data_api_url_template: "/caseworkers/{uid}/jurisdictions/{jid}/case-types/{ctid}/cases"
Expand Down Expand Up @@ -307,6 +308,7 @@ security:
- "createCaseLink"
- "maintainCaseLinks"
- "createFlag"
- "recordRemissionReminder"
caseworker-ia-homeofficeapc:
- "uploadHomeOfficeBundle"
- "uploadAdditionalEvidenceHomeOffice"
Expand Down Expand Up @@ -385,6 +387,7 @@ security:
- "rollbackPaymentTimeoutToPaymentPending"
- "updatePaymentStatus"
- "endAppealAutomatically"
- "recordRemissionReminder"

### dependency configuration
ccdGatewayUrl: ${CCD_GW_URL:http://localhost:3453}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ void has_correct_values() {
assertEquals("maintainCaseLinks", Event.MAINTAIN_CASE_LINKS.toString());
assertEquals("decideFtpaApplication", Event.DECIDE_FTPA_APPLICATION.toString());
assertEquals("updateTribunalDecision", Event.UPDATE_TRIBUNAL_DECISION.toString());
assertEquals("recordRemissionReminder", Event.RECORD_REMISSION_REMINDER.toString());
}

@Test
void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() {
assertEquals(119, Event.values().length);
assertEquals(120, Event.values().length);
}
}
Loading
Loading