Skip to content

Commit

Permalink
RIA-8210 Update tribunal decision Rule31- Documents tab post event - …
Browse files Browse the repository at this point in the history
…addressing comments (#2039)

Co-authored-by: JamieClarkeV1 <[email protected]>
  • Loading branch information
jamieclarkeHMCTS and JamieClarkeV1 authored Mar 20, 2024
1 parent 2321edb commit 2ea2c90
Showing 1 changed file with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class UpdateTribunalDecisionHandler implements PreSubmitCallbackHandler<A
private final FeatureToggler featureToggler;

public UpdateTribunalDecisionHandler(
DateProvider dateProvider,
Appender<DecisionAndReasons> decisionAndReasonsAppender,
DocumentReceiver documentReceiver,
DocumentsAppender documentsAppender,
FeatureToggler featureToggler
DateProvider dateProvider,
Appender<DecisionAndReasons> decisionAndReasonsAppender,
DocumentReceiver documentReceiver,
DocumentsAppender documentsAppender,
FeatureToggler featureToggler
) {
this.dateProvider = dateProvider;
this.decisionAndReasonsAppender = decisionAndReasonsAppender;
Expand All @@ -60,7 +60,7 @@ public boolean canHandle(PreSubmitCallbackStage callbackStage, Callback<AsylumCa
requireNonNull(callback, "callback must not be null");

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

public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callbackStage, Callback<AsylumCase> callback) {
Expand All @@ -76,40 +76,49 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb
asylumCase.write(UPDATED_APPEAL_DECISION, StringUtils.capitalize(updateTribunalDecisionValue.getValue().getCode()));

final DecisionAndReasons newDecisionAndReasons =
DecisionAndReasons.builder()
.updatedDecisionDate(dateProvider.now().toString())
.build();
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)) {
.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"));
.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"));
.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);
asylumCase.read(CORRECTED_DECISION_AND_REASONS);
List<IdValue<DecisionAndReasons>> allCorrectedDecisions =
decisionAndReasonsAppender.append(newDecisionAndReasons, maybeExistingDecisionAndReasons.orElse(emptyList()));
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 List<IdValue<DocumentWithMetadata>> existingDecisionAndReasonsDocuments = maybeDecisionAndReasonsDocuments.orElse(Collections.emptyList());


if (decisionAndReasonsDoc.isPresent()) {
DocumentWithMetadata updatedDecisionAndReasonsDocument = documentReceiver.receive(
decisionAndReasonsDoc.get(),
Expand All @@ -127,15 +136,6 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb

asylumCase.write(UPDATE_TRIBUNAL_DECISION_DATE, dateProvider.now().toString());

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);
}
}
} else if (isDecisionRule32(asylumCase)) {

List<DocumentWithMetadata> ftpaSetAsideDocuments = new ArrayList<>();
Expand All @@ -152,7 +152,7 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb
rule32Document,
"",
DocumentTag.FTPA_SET_ASIDE
)
)
);

final Optional<List<IdValue<DocumentWithMetadata>>> maybeFtpaSetAsideDocuments = asylumCase.read(ALL_SET_ASIDE_DOCS);
Expand All @@ -176,18 +176,18 @@ public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callb

private boolean isDecisionRule31(AsylumCase asylumCase) {
return asylumCase.read(UPDATE_TRIBUNAL_DECISION_LIST, UpdateTribunalRules.class)
.map(type -> type.equals(UNDER_RULE_31)).orElse(false);
.map(type -> type.equals(UNDER_RULE_31)).orElse(false);
}

private boolean isDecisionRule32(AsylumCase asylumCase) {
return asylumCase.read(UPDATE_TRIBUNAL_DECISION_LIST, UpdateTribunalRules.class)
.map(type -> type.equals(UNDER_RULE_32)).orElse(false);
.map(type -> type.equals(UNDER_RULE_32)).orElse(false);
}

private void setFtpaReheardCaseFlag(AsylumCase asylumCase) {
boolean isReheardAppealEnabled = featureToggler.getValue("reheard-feature", false);
asylumCase.write(AsylumCaseFieldDefinition.IS_REHEARD_APPEAL_ENABLED,
isReheardAppealEnabled ? YesOrNo.YES : YesOrNo.NO);
isReheardAppealEnabled ? YesOrNo.YES : YesOrNo.NO);

if (isReheardAppealEnabled) {
asylumCase.write(CASE_FLAG_SET_ASIDE_REHEARD_EXISTS, YES);
Expand Down

0 comments on commit 2ea2c90

Please sign in to comment.