Skip to content

Commit

Permalink
RIA-TASK Fix sonnar issues (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelMartinRojas authored Oct 23, 2024
1 parent 020a821 commit eb75ccb
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@ public PreSubmitCallbackResponse<AsylumCase> handle(

//prevent the existing case with previous selected remote hearing when the ref data feature is on with different hearing centre
//IS_REMOTE_HEARING is used for the case ref data
if ((!isCaseUsingLocationRefData && listCaseHearingCentre.equals(HearingCentre.REMOTE_HEARING))
|| (isCaseUsingLocationRefData && isRemoteHearing(asylumCase))) {
hearingNotice = remoteHearingNoticeDocumentCreator.create(caseDetails);
} else {
boolean isAda = asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class).orElse(NO) == YES;
hearingNotice = isAda ? adaHearingNoticeDocumentCreator.create(caseDetails) : hearingNoticeDocumentCreator.create(caseDetails);
}
hearingNotice = getHearingNotice(isCaseUsingLocationRefData, listCaseHearingCentre, asylumCase, caseDetails);
if ((asylumCase.read(AsylumCaseDefinition.IS_REHEARD_APPEAL_ENABLED, YesOrNo.class).equals(Optional.of(YES))
&& (asylumCase.read(CASE_FLAG_SET_ASIDE_REHEARD_EXISTS, YesOrNo.class).map(flag -> flag.equals(YES)).orElse(false)))) {

Expand Down Expand Up @@ -148,6 +142,18 @@ public PreSubmitCallbackResponse<AsylumCase> handle(
return new PreSubmitCallbackResponse<>(asylumCase);
}

private Document getHearingNotice(boolean isCaseUsingLocationRefData, HearingCentre listCaseHearingCentre, AsylumCase asylumCase, CaseDetails<AsylumCase> caseDetails) {
Document hearingNotice;
if ((!isCaseUsingLocationRefData && listCaseHearingCentre.equals(HearingCentre.REMOTE_HEARING))
|| (isCaseUsingLocationRefData && isRemoteHearing(asylumCase))) {
hearingNotice = remoteHearingNoticeDocumentCreator.create(caseDetails);
} else {
boolean isAda = asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class).orElse(NO) == YES;
hearingNotice = isAda ? adaHearingNoticeDocumentCreator.create(caseDetails) : hearingNoticeDocumentCreator.create(caseDetails);
}
return hearingNotice;
}

private void appendReheardHearingDocuments(AsylumCase asylumCase, Document hearingNotice) {
DocumentWithMetadata documentWithMetadata =
documentReceiver.receive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class AppealSubmissionDocFieldMapper {
public static final String CIRCUMSTANCES_OF_THE_APPELLANT_S_OUT_OF_COUNTRY_APPEAL_TITLE = "Circumstances of the appellant's out of country appeal";
public static final String THE_APPELLANT_IS_APPEALING_AN_ENTRY_CLEARANCE_DECISION = "The appellant is appealing an entry clearance decision";
public static final String THE_APPELLANT_HAD_TO_LEAVE_THE_UK_IN_ORDER_TO_APPEAL = "The appellant had to leave the UK in order to appeal";
public static final String OUT_OF_COUNTRY_DECISION_TYPE_TITLE = "outOfCountryDecisionTypeTitle";
public static final String OUT_OF_COUNTRY_DECISION_TYPE_TEXT = "outOfCountryDecisionType";
private final StringProvider stringProvider;

public AppealSubmissionDocFieldMapper(
Expand Down Expand Up @@ -79,58 +81,7 @@ public Map<String, Object> mapFieldValues(
fieldValues.put("hasSponsor", YesOrNo.NO);
fieldValues.put("appealOutOfCountry", asylumCase.read(APPEAL_OUT_OF_COUNTRY, YesOrNo.class).orElse(YesOrNo.NO));

if (asylumCase.read(APPEAL_OUT_OF_COUNTRY, YesOrNo.class).orElse(YesOrNo.NO) == YesOrNo.YES) {

Optional<OutOfCountryDecisionType> maybeOutOfCountryDecisionType = asylumCase.read(OUT_OF_COUNTRY_DECISION_TYPE, OutOfCountryDecisionType.class);
Optional<OutOfCountryCircumstances> maybeOutOfCountryCircumstances = asylumCase.read(OOC_APPEAL_ADMIN_J, OutOfCountryCircumstances.class);

if (maybeOutOfCountryCircumstances.isPresent() && isInternalCase(asylumCase) && !isAppellantInUk(asylumCase)) {
OutOfCountryCircumstances outOfCountryCircumstances = maybeOutOfCountryCircumstances.get();
if (outOfCountryCircumstances.equals(ENTRY_CLEARANCE_DECISION)) {
fieldValues.put("outOfCountryDecisionTypeTitle", CIRCUMSTANCES_OF_THE_APPELLANT_S_OUT_OF_COUNTRY_APPEAL_TITLE);
fieldValues.put("outOfCountryDecisionType", THE_APPELLANT_IS_APPEALING_AN_ENTRY_CLEARANCE_DECISION);
} else if (outOfCountryCircumstances.equals(LEAVE_UK)) {
fieldValues.put("outOfCountryDecisionTypeTitle", CIRCUMSTANCES_OF_THE_APPELLANT_S_OUT_OF_COUNTRY_APPEAL_TITLE);
fieldValues.put("outOfCountryDecisionType", THE_APPELLANT_HAD_TO_LEAVE_THE_UK_IN_ORDER_TO_APPEAL);
}
} else if (maybeOutOfCountryDecisionType.isPresent()) {
fieldValues.put("outOfCountryDecisionTypeTitle", "Out of country decision type");

OutOfCountryDecisionType decisionType = maybeOutOfCountryDecisionType.get();
fieldValues.put("outOfCountryDecisionType", maybeOutOfCountryDecisionType.get().getDescription());
fieldValues.put("decisionLetterReceived", YesOrNo.YES);

if (decisionType == OutOfCountryDecisionType.REFUSAL_OF_HUMAN_RIGHTS || decisionType == OutOfCountryDecisionType.REFUSE_PERMIT) {
fieldValues.put("gwfReferenceNumber", asylumCase.read(GWF_REFERENCE_NUMBER, String.class).orElse(null));
fieldValues.put("dateEntryClearanceDecision", formatDateForRendering(asylumCase.read(DATE_ENTRY_CLEARANCE_DECISION, String.class).orElse(null), DOCUMENT_DATE_FORMAT));
fieldValues.put("decisionLetterReceived", YesOrNo.NO);

} else if (decisionType == OutOfCountryDecisionType.REFUSAL_OF_PROTECTION) {
fieldValues.put("dateClientLeaveUk", formatDateForRendering(asylumCase.read(DATE_CLIENT_LEAVE_UK, String.class).orElse(null), DOCUMENT_DATE_FORMAT));
fieldValues.put("didClientLeaveUk", YesOrNo.YES);
}
}

if (asylumCase.read(HAS_CORRESPONDENCE_ADDRESS, YesOrNo.class).orElse(YesOrNo.NO) == YesOrNo.YES) {
fieldValues.put("appellantOutOfCountryAddress", asylumCase.read(APPELLANT_OUT_OF_COUNTRY_ADDRESS, String.class).orElse(""));
}

Optional<YesOrNo> hasSponsor = asylumCase.read(HAS_SPONSOR, YesOrNo.class);
if (hasSponsor.isPresent() && hasSponsor.get().equals(YesOrNo.YES)) {
fieldValues.put("hasSponsor", YesOrNo.YES);
fieldValues.put("sponsorGivenNames", asylumCase.read(SPONSOR_GIVEN_NAMES, String.class).orElse(null));
fieldValues.put("sponsorFamilyName", asylumCase.read(SPONSOR_FAMILY_NAME, String.class).orElse(null));
fieldValues.put("sponsorAddress", asylumCase.read(SPONSOR_ADDRESS_FOR_DISPLAY, String.class).orElse(null));
Optional<ContactPreference> sponsorContactPreference = asylumCase.read(SPONSOR_CONTACT_PREFERENCE, ContactPreference.class);
if (sponsorContactPreference.isPresent()
&& sponsorContactPreference.get().toString().equals(ContactPreference.WANTS_EMAIL.toString())) {
fieldValues.put("wantsSponsorEmail", YesOrNo.YES);
fieldValues.put("sponsorEmail", asylumCase.read(SPONSOR_EMAIL, String.class).orElse(null));
} else {
fieldValues.put("sponsorMobileNumber", asylumCase.read(SPONSOR_MOBILE_NUMBER, String.class).orElse(null));
}
}
}
addAppealOocFields(asylumCase, fieldValues);

Optional<AsylumAppealType> optionalAppealType = asylumCase.read(APPEAL_TYPE, AsylumAppealType.class);

Expand Down Expand Up @@ -194,6 +145,23 @@ public Map<String, Object> mapFieldValues(
Optional<List<IdValue<Map<String, String>>>> otherAppeals = asylumCase
.read(OTHER_APPEALS);

populateOtherAppeals(fieldValues, otherAppeals, asylumCase);

fieldValues.put("applicationOutOfTimeExplanation", asylumCase.read(APPLICATION_OUT_OF_TIME_EXPLANATION, String.class).orElse(""));
fieldValues.put("submissionOutOfTime", asylumCase.read(SUBMISSION_OUT_OF_TIME, YesOrNo.class).orElse(YesOrNo.NO));
fieldValues.put(
"applicationOutOfTimeDocumentName",
asylumCase.read(APPLICATION_OUT_OF_TIME_DOCUMENT, Document.class)
.map(Document::getDocumentFilename)
.orElse("")
);

fieldValues.put("isAdmin", asylumCase.read(IS_ADMIN, YesOrNo.class).orElse(YesOrNo.NO));

return fieldValues;
}

private static void populateOtherAppeals(Map<String, Object> fieldValues, Optional<List<IdValue<Map<String, String>>>> otherAppeals, AsylumCase asylumCase) {
fieldValues.put(
"otherAppeals",
otherAppeals
Expand All @@ -210,19 +178,69 @@ public Map<String, Object> mapFieldValues(
} else {
fieldValues.put("hasOtherAppeals", YesOrNo.NO);
}
}

fieldValues.put("applicationOutOfTimeExplanation", asylumCase.read(APPLICATION_OUT_OF_TIME_EXPLANATION, String.class).orElse(""));
fieldValues.put("submissionOutOfTime", asylumCase.read(SUBMISSION_OUT_OF_TIME, YesOrNo.class).orElse(YesOrNo.NO));
fieldValues.put(
"applicationOutOfTimeDocumentName",
asylumCase.read(APPLICATION_OUT_OF_TIME_DOCUMENT, Document.class)
.map(Document::getDocumentFilename)
.orElse("")
);
private static void addAppealOocFields(AsylumCase asylumCase, Map<String, Object> fieldValues) {
if (asylumCase.read(APPEAL_OUT_OF_COUNTRY, YesOrNo.class).orElse(YesOrNo.NO) == YesOrNo.YES) {

fieldValues.put("isAdmin", asylumCase.read(IS_ADMIN, YesOrNo.class).orElse(YesOrNo.NO));
Optional<OutOfCountryDecisionType> maybeOutOfCountryDecisionType = asylumCase.read(OUT_OF_COUNTRY_DECISION_TYPE, OutOfCountryDecisionType.class);
Optional<OutOfCountryCircumstances> maybeOutOfCountryCircumstances = asylumCase.read(OOC_APPEAL_ADMIN_J, OutOfCountryCircumstances.class);

return fieldValues;
if (maybeOutOfCountryCircumstances.isPresent() && isInternalCase(asylumCase) && !isAppellantInUk(asylumCase)) {
populateOutOfCircumstancesInternalCase(fieldValues, maybeOutOfCountryCircumstances);
} else if (maybeOutOfCountryDecisionType.isPresent()) {
fieldValues.put(OUT_OF_COUNTRY_DECISION_TYPE_TITLE, "Out of country decision type");

OutOfCountryDecisionType decisionType = maybeOutOfCountryDecisionType.get();
fieldValues.put(OUT_OF_COUNTRY_DECISION_TYPE_TEXT, maybeOutOfCountryDecisionType.get().getDescription());
fieldValues.put("decisionLetterReceived", YesOrNo.YES);

if (decisionType == OutOfCountryDecisionType.REFUSAL_OF_HUMAN_RIGHTS || decisionType == OutOfCountryDecisionType.REFUSE_PERMIT) {
fieldValues.put("gwfReferenceNumber", asylumCase.read(GWF_REFERENCE_NUMBER, String.class).orElse(null));
fieldValues.put("dateEntryClearanceDecision", formatDateForRendering(asylumCase.read(DATE_ENTRY_CLEARANCE_DECISION, String.class).orElse(null), DOCUMENT_DATE_FORMAT));
fieldValues.put("decisionLetterReceived", YesOrNo.NO);

} else if (decisionType == OutOfCountryDecisionType.REFUSAL_OF_PROTECTION) {
fieldValues.put("dateClientLeaveUk", formatDateForRendering(asylumCase.read(DATE_CLIENT_LEAVE_UK, String.class).orElse(null), DOCUMENT_DATE_FORMAT));
fieldValues.put("didClientLeaveUk", YesOrNo.YES);
}
}

if (asylumCase.read(HAS_CORRESPONDENCE_ADDRESS, YesOrNo.class).orElse(YesOrNo.NO) == YesOrNo.YES) {
fieldValues.put("appellantOutOfCountryAddress", asylumCase.read(APPELLANT_OUT_OF_COUNTRY_ADDRESS, String.class).orElse(""));
}

populateSponsorFields(asylumCase, fieldValues);
}
}

private static void populateOutOfCircumstancesInternalCase(Map<String, Object> fieldValues, Optional<OutOfCountryCircumstances> maybeOutOfCountryCircumstances) {
OutOfCountryCircumstances outOfCountryCircumstances = maybeOutOfCountryCircumstances.get();
if (outOfCountryCircumstances.equals(ENTRY_CLEARANCE_DECISION)) {
fieldValues.put(OUT_OF_COUNTRY_DECISION_TYPE_TITLE, CIRCUMSTANCES_OF_THE_APPELLANT_S_OUT_OF_COUNTRY_APPEAL_TITLE);
fieldValues.put(OUT_OF_COUNTRY_DECISION_TYPE_TEXT, THE_APPELLANT_IS_APPEALING_AN_ENTRY_CLEARANCE_DECISION);
} else if (outOfCountryCircumstances.equals(LEAVE_UK)) {
fieldValues.put(OUT_OF_COUNTRY_DECISION_TYPE_TITLE, CIRCUMSTANCES_OF_THE_APPELLANT_S_OUT_OF_COUNTRY_APPEAL_TITLE);
fieldValues.put(OUT_OF_COUNTRY_DECISION_TYPE_TEXT, THE_APPELLANT_HAD_TO_LEAVE_THE_UK_IN_ORDER_TO_APPEAL);
}
}

private static void populateSponsorFields(AsylumCase asylumCase, Map<String, Object> fieldValues) {
Optional<YesOrNo> hasSponsor = asylumCase.read(HAS_SPONSOR, YesOrNo.class);
if (hasSponsor.isPresent() && hasSponsor.get().equals(YesOrNo.YES)) {
fieldValues.put("hasSponsor", YesOrNo.YES);
fieldValues.put("sponsorGivenNames", asylumCase.read(SPONSOR_GIVEN_NAMES, String.class).orElse(null));
fieldValues.put("sponsorFamilyName", asylumCase.read(SPONSOR_FAMILY_NAME, String.class).orElse(null));
fieldValues.put("sponsorAddress", asylumCase.read(SPONSOR_ADDRESS_FOR_DISPLAY, String.class).orElse(null));
Optional<ContactPreference> sponsorContactPreference = asylumCase.read(SPONSOR_CONTACT_PREFERENCE, ContactPreference.class);
if (sponsorContactPreference.isPresent()
&& sponsorContactPreference.get().toString().equals(ContactPreference.WANTS_EMAIL.toString())) {
fieldValues.put("wantsSponsorEmail", YesOrNo.YES);
fieldValues.put("sponsorEmail", asylumCase.read(SPONSOR_EMAIL, String.class).orElse(null));
} else {
fieldValues.put("sponsorMobileNumber", asylumCase.read(SPONSOR_MOBILE_NUMBER, String.class).orElse(null));
}
}
}

private void populateDetainedFields(AsylumCase asylumCase, Map<String, Object> fieldValues) {
Expand Down

0 comments on commit eb75ccb

Please sign in to comment.