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-8239 Added rule 31 updated decisions #2001

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,69 @@
{
"description": "RIA-8239 Update Tribunal Decision Rule 31 should append correctedDecisionAndReasons",
"launchDarklyKey": "dlrm-setaside-feature-flag:true",
"request": {
"uri": "/asylum/ccdAboutToSubmit",
"credentials": "Judge",
"input": {
"id": 8239,
"eventId": "updateTribunalDecision",
"state": "ftpaDecided",
"caseData": {
"template": "minimal-appeal-submitted.json",
"replacements": {
"updateTribunalDecisionList": "underRule31",
"updateTribunalDecisionAndReasonsFinalCheck": "Yes",
"isDecisionAllowed": "dismissed",
"typesOfUpdateTribunalDecision": {
"value": {
"code": "allowed",
"label": "Yes, change decision to Allowed"
},
"list_items": [
{
"code": "allowed",
"label": "Yes, change decision to Allowed"
},
{
"code": "dismissed",
"label": "No"
}
]
},
"decisionAndReasonDocsUpload": {
"document_url": "http://document-store/AAA",
"document_binary_url": "http://document-store/AAA/binary",
"document_filename": "PA 12345 2018-Awan-Decision-and-reasons-AMENDED.pdf"
},
"summariseTribunalDecisionAndReasonsDocument": "Document summarised example"
}
}
}
},
"expectation": {
"status": 200,
"errors": [],
"caseData": {
"template": "minimal-appeal-submitted.json",
"replacements": {
"sendDirectionActionAvailable": "No",
"updatedAppealDecision": "Allowed",
"correctedDecisionAndReasons": [
{
"id": "1",
"value": {
"summariseChanges": "Document summarised example",
"updatedDecisionDate": "{$TODAY}",
"documentAndReasonsDocument": {
"document_url": "http://document-store/AAA",
"document_binary_url": "http://document-store/AAA/binary",
"document_filename": "PA 12345 2018-Awan-Decision-and-reasons-AMENDED.pdf"
},
"dateDocumentAndReasonsDocumentUploaded": "{$TODAY}"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,13 @@ public enum AsylumCaseFieldDefinition {
"remissionOption", new TypeReference<RemissionOption>(){}),

HELP_WITH_FEES_OPTION(
"helpWithFeesOption", new TypeReference<HelpWithFeesOption>(){});
"helpWithFeesOption", new TypeReference<HelpWithFeesOption>(){}),

CORRECTED_DECISION_AND_REASONS(
"correctedDecisionAndReasons", new TypeReference<List<IdValue<DecisionAndReasons>>>(){}),

SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT(
"summariseTribunalDecisionAndReasonsDocument", new TypeReference<String>(){});

private final String value;
private final TypeReference typeReference;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package uk.gov.hmcts.reform.iacaseapi.domain.entities;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.Document;

@Getter
@Setter
@Builder
@AllArgsConstructor
public class DecisionAndReasons {

private String updatedDecisionDate;
private String dateCoverLetterDocumentUploaded;
private Document coverLetterDocument;
private String dateDocumentAndReasonsDocumentUploaded;
private Document documentAndReasonsDocument;
private String summariseChanges;

private DecisionAndReasons() {
// noop -- for deserializer
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;

import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.CORRECTED_DECISION_AND_REASONS;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.DECISION_AND_REASON_DOCS_UPLOAD;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.TYPES_OF_UPDATE_TRIBUNAL_DECISION;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.UPDATED_APPEAL_DECISION;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.UPDATE_TRIBUNAL_DECISION_AND_REASONS_FINAL_CHECK;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.UPDATE_TRIBUNAL_DECISION_LIST;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.UpdateTribunalRules.UNDER_RULE_31;

import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
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.DecisionAndReasons;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.DynamicList;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.UpdateTribunalRules;
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.PreSubmitCallbackResponse;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.Document;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.IdValue;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo;
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.iacaseapi.domain.service.Appender;

@Component
public class UpdateTribunalAppealDecisionRule31 implements PreSubmitCallbackHandler<AsylumCase> {

private final DateProvider dateProvider;
private final Appender<DecisionAndReasons> decisionAndReasonsAppender;

public UpdateTribunalAppealDecisionRule31(DateProvider dateProvider,
Appender<DecisionAndReasons> decisionAndReasonsAppender) {
this.dateProvider = dateProvider;
this.decisionAndReasonsAppender = decisionAndReasonsAppender;
}

public boolean canHandle(PreSubmitCallbackStage callbackStage, Callback<AsylumCase> callback) {
requireNonNull(callbackStage, "callbackStage must not be null");
requireNonNull(callback, "callback must not be null");
Expand All @@ -39,6 +61,34 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb
.orElseThrow(() -> new IllegalStateException("typesOfUpdateTribunalDecision is not present"));

asylumCase.write(UPDATED_APPEAL_DECISION, StringUtils.capitalize(updateTribunalDecisionValue.getValue().getCode()));

final DecisionAndReasons newDecisionAndReasons =
DecisionAndReasons.builder()
.updatedDecisionDate(dateProvider.now().toString())
.build();

if (asylumCase.read(UPDATE_TRIBUNAL_DECISION_AND_REASONS_FINAL_CHECK, YesOrNo.class)
.map(flag -> flag.equals(YesOrNo.YES)).orElse(false)) {

Document correctedDecisionAndReasonsDoc = asylumCase
.read(DECISION_AND_REASON_DOCS_UPLOAD, Document.class)
.orElseThrow(() -> new IllegalStateException("decisionAndReasonDocsUpload is not present"));

String summariseChanges = asylumCase
.read(SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT, String.class)
.orElseThrow(() -> new IllegalStateException("summariseTribunalDecisionAndReasonsDocument is not present"));

newDecisionAndReasons.setDocumentAndReasonsDocument(correctedDecisionAndReasonsDoc);
newDecisionAndReasons.setDateDocumentAndReasonsDocumentUploaded(dateProvider.now().toString());
newDecisionAndReasons.setSummariseChanges(summariseChanges);
}

Optional<List<IdValue<DecisionAndReasons>>> maybeExistingDecisionAndReasons =
asylumCase.read(CORRECTED_DECISION_AND_REASONS);
List<IdValue<DecisionAndReasons>> allCorrectedDecisions =
decisionAndReasonsAppender.append(newDecisionAndReasons, maybeExistingDecisionAndReasons.orElse(emptyList()));

asylumCase.write(CORRECTED_DECISION_AND_REASONS, allCorrectedDecisions);
}
return new PreSubmitCallbackResponse<>(asylumCase);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package uk.gov.hmcts.reform.iacaseapi.domain.entities;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.Document;

class DecisionAndReasonsTest {

private final String updatedDecisionDate = "some-date";
private final String dateCoverLetterDocumentUploaded = "some-date";
private final Document coverLetterDocument = mock(Document.class);
private final String dateDocumentAndReasonsDocumentUploaded = "some-other-date";
private final String summariseChanges = "summarise-example";
private final Document documentAndReasonsDocument = mock(Document.class);

private DecisionAndReasons decisionAndReasons;

@BeforeEach
public void setUp() {
decisionAndReasons = new DecisionAndReasons(
updatedDecisionDate,
dateCoverLetterDocumentUploaded,
coverLetterDocument,
dateDocumentAndReasonsDocumentUploaded,
documentAndReasonsDocument,
summariseChanges);
}

@Test
void should_hold_onto_values() {

assertThat(decisionAndReasons.getUpdatedDecisionDate()).isEqualTo(updatedDecisionDate);
assertThat(decisionAndReasons.getDateCoverLetterDocumentUploaded()).isEqualTo(dateCoverLetterDocumentUploaded);
assertThat(decisionAndReasons.getCoverLetterDocument()).isEqualTo(coverLetterDocument);
assertThat(decisionAndReasons.getDateDocumentAndReasonsDocumentUploaded()).isEqualTo(dateDocumentAndReasonsDocumentUploaded);
assertThat(decisionAndReasons.getDocumentAndReasonsDocument()).isEqualTo(documentAndReasonsDocument);
assertThat(decisionAndReasons.getSummariseChanges()).isEqualTo(summariseChanges);
}
}
Loading
Loading