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-8210 Update tribunal decision Rule31- Documents tab - addressing fix #2040

Merged
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
Expand Up @@ -7,12 +7,10 @@
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.ALL_SET_ASIDE_DOCS;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.UpdateTribunalRules.UNDER_RULE_31;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.UpdateTribunalRules.UNDER_RULE_32;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo.NO;
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo.YES;

import java.util.ArrayList;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Optional;
import java.util.List;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -80,12 +78,13 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb
.updatedDecisionDate(dateProvider.now().toString())
.build();

Optional<Document> maybeDecisionAndReasonSingleDocument = asylumCase
.read(DECISION_AND_REASON_DOCS_UPLOAD, Document.class);

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"));
Document correctedDecisionAndReasonsDoc = maybeDecisionAndReasonSingleDocument.orElseThrow(() -> new IllegalStateException("decisionAndReasonDocsUpload is not present"));

String summariseChanges = asylumCase
.read(SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT, String.class)
Expand All @@ -94,34 +93,13 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb
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);

final Optional<Document> decisionAndReasonsDoc = asylumCase.read(DECISION_AND_REASON_DOCS_UPLOAD, Document.class);

YesOrNo isDecisionAndReasonDocumentBeingUpdated = asylumCase.read(AsylumCaseFieldDefinition.UPDATE_TRIBUNAL_DECISION_AND_REASONS_FINAL_CHECK, YesOrNo.class)
.orElse(NO);

if (isDecisionAndReasonDocumentBeingUpdated.equals(NO)) {
if (decisionAndReasonsDoc.isPresent()) {
asylumCase.clear(DECISION_AND_REASON_DOCS_UPLOAD);
asylumCase.clear(SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT);
}
}

final Optional<List<IdValue<DocumentWithMetadata>>> maybeDecisionAndReasonsDocuments = asylumCase.read(FINAL_DECISION_AND_REASONS_DOCUMENTS);
final Optional<List<IdValue<DocumentWithMetadata>>> maybeDecisionAndReasonsDocuments = asylumCase.read(FINAL_DECISION_AND_REASONS_DOCUMENTS);

final List<IdValue<DocumentWithMetadata>> existingDecisionAndReasonsDocuments = maybeDecisionAndReasonsDocuments.orElse(Collections.emptyList());
final List<IdValue<DocumentWithMetadata>> existingDecisionAndReasonsDocuments = maybeDecisionAndReasonsDocuments.orElse(Collections.emptyList());

if (decisionAndReasonsDoc.isPresent()) {
DocumentWithMetadata updatedDecisionAndReasonsDocument = documentReceiver.receive(
decisionAndReasonsDoc.get(),
correctedDecisionAndReasonsDoc,
"",
DocumentTag.UPDATED_FINAL_DECISION_AND_REASONS_PDF
);
Expand All @@ -132,8 +110,22 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb
);

asylumCase.write(FINAL_DECISION_AND_REASONS_DOCUMENTS, newUpdateTribunalDecisionDocs);

} else {

if (maybeDecisionAndReasonSingleDocument.isPresent()) {
asylumCase.clear(DECISION_AND_REASON_DOCS_UPLOAD);
asylumCase.clear(SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT);

}
}

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);
asylumCase.write(UPDATE_TRIBUNAL_DECISION_DATE, dateProvider.now().toString());

} else if (isDecisionRule32(asylumCase)) {
Expand All @@ -142,7 +134,7 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb

final Document rule32Document =
asylumCase
.read(RULE_32_NOTICE_DOCUMENT,Document.class)
.read(RULE_32_NOTICE_DOCUMENT, Document.class)
.orElseThrow(
() -> new IllegalStateException("Rule 32 notice document is not present"));

Expand Down Expand Up @@ -194,4 +186,5 @@ private void setFtpaReheardCaseFlag(AsylumCase asylumCase) {
asylumCase.write(STITCHING_STATUS,"");
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.time.LocalDate;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -125,16 +124,6 @@ void should_write_updated_appeal_decision_dismissed() {
when(asylumCase.read(TYPES_OF_UPDATE_TRIBUNAL_DECISION, DynamicList.class))
.thenReturn(Optional.of(dynamicList));

when(asylumCase.read(DECISION_AND_REASON_DOCS_UPLOAD, Document.class)).thenReturn(Optional.of(decisionAndReasonsDocument));

LocalDate currentDate = LocalDate.now();
when(dateProvider.now()).thenReturn(currentDate);

final YesOrNo isDecisionAndReasonDocumentBeingUpdated = asylumCase.read(AsylumCaseFieldDefinition.UPDATE_TRIBUNAL_DECISION_AND_REASONS_FINAL_CHECK, YesOrNo.class)
.orElse(NO);

decisionsAndReasonDoc = "someTestDoc";

PreSubmitCallbackResponse<AsylumCase> callbackResponse =
updateTribunalDecisionHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback);

Expand All @@ -145,13 +134,6 @@ void should_write_updated_appeal_decision_dismissed() {
assertNotNull(callbackResponse);
assertEquals(asylumCase, callbackResponse.getData());

if (isDecisionAndReasonDocumentBeingUpdated.equals(NO) && decisionsAndReasonDoc != null) {
asylumCase.clear(DECISION_AND_REASON_DOCS_UPLOAD);
asylumCase.clear(SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT);

verify(asylumCase, times(1)).write(UPDATED_APPEAL_DECISION, "Dismissed");
verify(asylumCase, times(1)).write(UPDATE_TRIBUNAL_DECISION_DATE, currentDate.toString());
}
verify(asylumCase, times(1)).write(UPDATED_APPEAL_DECISION, "Dismissed");
verify(asylumCase, times(1)).write(CORRECTED_DECISION_AND_REASONS, allAppendedDecisionAndReasosn);
assertThat(capturedDecision.getUpdatedDecisionDate()).isEqualTo(now.toString());
Expand All @@ -165,35 +147,21 @@ void should_write_updated_appeal_decision_allowed() {
);
when(asylumCase.read(TYPES_OF_UPDATE_TRIBUNAL_DECISION, DynamicList.class))
.thenReturn(Optional.of(dynamicList));
when(asylumCase.read(DECISION_AND_REASON_DOCS_UPLOAD, Document.class)).thenReturn(Optional.of(decisionAndReasonsDocument));

LocalDate currentDate = LocalDate.now();
when(dateProvider.now()).thenReturn(currentDate);

final YesOrNo isDecisionAndReasonDocumentBeingUpdated = asylumCase.read(AsylumCaseFieldDefinition.UPDATE_TRIBUNAL_DECISION_AND_REASONS_FINAL_CHECK, YesOrNo.class)
.orElse(NO);

decisionsAndReasonDoc = "someTestDoc";

PreSubmitCallbackResponse<AsylumCase> callbackResponse =
updateTribunalDecisionHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback);

if (isDecisionAndReasonDocumentBeingUpdated.equals(NO) && decisionsAndReasonDoc != null) {
asylumCase.clear(DECISION_AND_REASON_DOCS_UPLOAD);
asylumCase.clear(SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT);

verify(decisionAndReasonsAppender, times(1))
.append(newDecisionCaptor.capture(), existingDecisionsCaptor.capture());
verify(decisionAndReasonsAppender, times(1))
.append(newDecisionCaptor.capture(), existingDecisionsCaptor.capture());

final DecisionAndReasons capturedDecision = newDecisionCaptor.getValue();
assertNotNull(callbackResponse);
assertEquals(asylumCase, callbackResponse.getData());
final DecisionAndReasons capturedDecision = newDecisionCaptor.getValue();
assertNotNull(callbackResponse);
assertEquals(asylumCase, callbackResponse.getData());

verify(asylumCase, times(1)).write(UPDATED_APPEAL_DECISION, "Allowed");
verify(asylumCase, times(1)).write(CORRECTED_DECISION_AND_REASONS, allAppendedDecisionAndReasosn);
verify(asylumCase, times(1)).write(UPDATE_TRIBUNAL_DECISION_DATE, currentDate.toString());
assertThat(capturedDecision.getUpdatedDecisionDate()).isEqualTo(now.toString());
}
verify(asylumCase, times(1)).write(UPDATED_APPEAL_DECISION, "Allowed");
verify(asylumCase, times(1)).write(CORRECTED_DECISION_AND_REASONS, allAppendedDecisionAndReasosn);
verify(asylumCase, times(1)).write(UPDATE_TRIBUNAL_DECISION_DATE, now.toString());
assertThat(capturedDecision.getUpdatedDecisionDate()).isEqualTo(now.toString());
}

@Test
Expand Down Expand Up @@ -229,7 +197,6 @@ void should_write_updated_decision_document_if_has_corrected_document() {
assertThat(capturedDecision.getSummariseChanges()).isEqualTo(summarisedChanges);
}


@Test
void should_write_set_aside_documents_if_is_r32() {

Expand Down Expand Up @@ -412,7 +379,7 @@ void should_not_allow_null_arguments() {
}

@Test
void should_append_update_tribunal_decision_document() {
void should_append_update_tribunal_decision_document_if_yes() {
List<DocumentWithMetadata> decisionsAndReasonsDocumentsWithMetadata =
Arrays.asList(decisionsAndReasonsDocumentWithMetadata);

Expand All @@ -422,13 +389,12 @@ void should_append_update_tribunal_decision_document() {
);

final List<IdValue<DocumentWithMetadata>> finalDecisionAndReasonsDocuments = new ArrayList<>();

when(asylumCase.read(TYPES_OF_UPDATE_TRIBUNAL_DECISION, DynamicList.class))
.thenReturn(Optional.of(dynamicList));

when(callback.getCaseDetails()).thenReturn(caseDetails);
when(caseDetails.getCaseData()).thenReturn(asylumCase);
when(callback.getEvent()).thenReturn(Event.UPDATE_TRIBUNAL_DECISION);
when(asylumCase.read(UPDATE_TRIBUNAL_DECISION_AND_REASONS_FINAL_CHECK, YesOrNo.class))
.thenReturn(Optional.of(YesOrNo.YES));
when(asylumCase.read(SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT, String.class))
.thenReturn(Optional.of(summarisedChanges));
when(asylumCase.read(DECISION_AND_REASON_DOCS_UPLOAD, Document.class))
.thenReturn(Optional.of(correctedDecisionDocument));
when(asylumCase.read(FINAL_DECISION_AND_REASONS_DOCUMENTS))
Expand All @@ -449,8 +415,30 @@ void should_append_update_tribunal_decision_document() {
verify(documentReceiver).receive(correctedDecisionDocument, "", DocumentTag.UPDATED_FINAL_DECISION_AND_REASONS_PDF);
verify(documentsAppender).append(finalDecisionAndReasonsDocuments, Arrays.asList(decisionsAndReasonsDocumentWithMetadata));


verify(asylumCase, times(1)).read(DECISION_AND_REASON_DOCS_UPLOAD, Document.class);
verify(asylumCase).write(FINAL_DECISION_AND_REASONS_DOCUMENTS, newUpdateTribunalDecisionDocs);
}

@Test
void should_not_append_update_tribunal_decision_document_if_no() {

final DynamicList dynamicList = new DynamicList(
new Value("allowed", "Yes, change decision to Allowed"),
newArrayList()
);

when(asylumCase.read(TYPES_OF_UPDATE_TRIBUNAL_DECISION, DynamicList.class))
.thenReturn(Optional.of(dynamicList));
when(asylumCase.read(UPDATE_TRIBUNAL_DECISION_AND_REASONS_FINAL_CHECK, YesOrNo.class))
.thenReturn(Optional.of(NO));
when(asylumCase.read(DECISION_AND_REASON_DOCS_UPLOAD, Document.class))
.thenReturn(Optional.of(correctedDecisionDocument));

PreSubmitCallbackResponse<AsylumCase> callbackResponse =
updateTribunalDecisionHandler.handle(PreSubmitCallbackStage.ABOUT_TO_SUBMIT, callback);

assertNotNull(callbackResponse);

verify(asylumCase).clear(DECISION_AND_REASON_DOCS_UPLOAD);
verify(asylumCase).clear(SUMMARISE_TRIBUNAL_DECISION_AND_REASONS_DOCUMENT);
}
}
Loading