Skip to content

Commit

Permalink
RIA-TASK - DO NOT MERGE - REF DATA (#944)
Browse files Browse the repository at this point in the history
* RIA-8802 bails notice of hearing displays the correct location information (#880)

* RIA-8802 bails notice of hearing displays the correct location information

* update the imported library and indentation

* RIA-9437 - Fix for missing listCaseHearingCentre error when submitting Prepare decision and reasons event (#943)

* RIA-9437 - Fix for missing listCaseHearingCentre error when submitting Prepare decision and reasons event

* FIx checkstyle

---------

Co-authored-by: DennisHoV1 <106669367+DennisHoV1@users.noreply.github.com>
Co-authored-by: rajeshthuraiyur <48379561+rajeshthuraiyur@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent 05bc9af commit 22673e7
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.InterpreterLanguage;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.NationalityFieldValue;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo;
import uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure.clients.model.refdata.CourtVenue;

public enum BailCaseFieldDefinition {
SENT_BY_CHECKLIST(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo.NO;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo.YES;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isRemoteHearing;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -93,7 +94,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 && asylumCase.read(IS_REMOTE_HEARING, YesOrNo.class).orElse(YesOrNo.NO).equals(YesOrNo.YES))) {
|| (isCaseUsingLocationRefData && isRemoteHearing(asylumCase))) {
hearingNotice = remoteHearingNoticeDocumentCreator.create(caseDetails);
} else {
boolean isAda = asylumCase.read(IS_ACCELERATED_DETAINED_APPEAL, YesOrNo.class).orElse(NO) == YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package uk.gov.hmcts.reform.iacasedocumentsapi.domain.templates;

import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.HearingCentre.DECISION_WITHOUT_HEARING;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.HearingCentre.REMOTE_HEARING;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.formatDateTimeForRendering;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isDecisionWithoutHearingAppeal;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isRemoteHearing;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -40,21 +44,23 @@ public Map<String, Object> mapFieldValues(
CaseDetails<AsylumCase> caseDetails
) {
final AsylumCase asylumCase = caseDetails.getCaseData();
final Map<String, Object> fieldValues = new HashMap<>();

final HearingCentre listedHearingCentre =
asylumCase
.read(LIST_CASE_HEARING_CENTRE, HearingCentre.class)
.orElseThrow(() -> new IllegalStateException("listCaseHearingCentre is not present"));
if (isDecisionWithoutHearingAppeal(asylumCase)) {
assignHearingCentreValue(DECISION_WITHOUT_HEARING, fieldValues);
} else if (isRemoteHearing(asylumCase)) {
assignHearingCentreValue(REMOTE_HEARING, fieldValues);
} else {
final HearingCentre listedHearingCentre =
asylumCase
.read(LIST_CASE_HEARING_CENTRE, HearingCentre.class)
.orElseThrow(() -> new IllegalStateException("listCaseHearingCentre is not present"));

final Map<String, Object> fieldValues = new HashMap<>();
assignHearingCentreValue(listedHearingCentre, fieldValues);
}

fieldValues.put("decisionsandreasons", "[userImage:decisionsandreasons.png]");

fieldValues.put(
"hearingCentre",
stringProvider.get("hearingCentreName", listedHearingCentre.toString()).orElse("")
);

fieldValues.put("appealReferenceNumber", asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class).orElse(""));
fieldValues.put("hearingDate", formatDateTimeForRendering(asylumCase.read(LIST_CASE_HEARING_DATE, String.class).orElse(""), DOCUMENT_DATE_FORMAT));
fieldValues.put("hearingTime", formatDateTimeForRendering(asylumCase.read(LIST_CASE_HEARING_DATE, String.class).orElse(""), DOCUMENT_TIME_FORMAT));
Expand Down Expand Up @@ -85,4 +91,11 @@ public Map<String, Object> mapFieldValues(
return fieldValues;
}

private void assignHearingCentreValue(HearingCentre location, Map<String, Object> fieldValues) {
fieldValues.put(
"hearingCentre",
stringProvider.get("hearingCentreName", location.toString()).orElse("")
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ApplicantDetainedLocation;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.BailCase;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails;
Expand All @@ -40,9 +41,12 @@ public class BailNoticeOfHearingTemplate {
private final StringProvider stringProvider;

public BailNoticeOfHearingTemplate(
CustomerServicesProvider customerServicesProvider, StringProvider stringProvider) {
CustomerServicesProvider customerServicesProvider,
StringProvider stringProvider) {

this.customerServicesProvider = customerServicesProvider;
this.stringProvider = stringProvider;

}

public Map<String, Object> mapFieldValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,13 @@ public static Map<String, String> getDirectionDueDateAndExplanation(AsylumCase a
.build();
}

public static boolean isDecisionWithoutHearingAppeal(AsylumCase asylumCase) {
return asylumCase.read(IS_DECISION_WITHOUT_HEARING, YesOrNo.class)
.map(yesOrNo -> YesOrNo.YES == yesOrNo).orElse(false);
}

public static boolean isRemoteHearing(AsylumCase asylumCase) {
return asylumCase.read(IS_REMOTE_HEARING, YesOrNo.class).orElse(YesOrNo.NO).equals(YesOrNo.YES);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package uk.gov.hmcts.reform.iacasedocumentsapi.infrastructure;

import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.IS_DECISION_WITHOUT_HEARING;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.LIST_CASE_HEARING_CENTRE;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.LIST_CASE_HEARING_DATE;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.utils.AsylumCaseUtils.isDecisionWithoutHearingAppeal;

import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.HearingCentre;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.StringProvider;

@Service
Expand Down Expand Up @@ -70,10 +69,5 @@ public String getHearingCentreUrl(HearingCentre hearingCentre) {
};
}

private boolean isDecisionWithoutHearingAppeal(AsylumCase asylumCase) {
return asylumCase.read(IS_DECISION_WITHOUT_HEARING, YesOrNo.class)
.map(yesOrNo -> YesOrNo.YES == yesOrNo).orElse(false);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCaseDefinition.*;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.HearingCentre.DECISION_WITHOUT_HEARING;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.HearingCentre.MANCHESTER;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.HearingCentre.REMOTE_HEARING;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo.NO;
import static uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo.YES;

import java.time.LocalDate;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.AsylumCase;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.HearingCentre;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.CaseDetails;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.entities.ccd.field.YesOrNo;
import uk.gov.hmcts.reform.iacasedocumentsapi.domain.service.StringProvider;

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class DecisionAndReasonsTemplateTest {

@Mock private StringProvider stringProvider;
Expand Down Expand Up @@ -50,10 +58,18 @@ public void should_return_template_name() {
assertEquals(templateName, decisionAndReasonsTemplate.getName());
}

@Test
public void should_map_case_data_to_template_field_values() {
@ParameterizedTest
@EnumSource(value = HearingCentre.class, names = {"MANCHESTER", "DECISION_WITHOUT_HEARING", "REMOTE_HEARING"})
public void should_map_case_data_to_template_field_values(HearingCentre testCase) {

if (testCase.equals(REMOTE_HEARING)) {
when(asylumCase.read(IS_REMOTE_HEARING, YesOrNo.class)).thenReturn(Optional.of(YES));
} else if (testCase.equals(DECISION_WITHOUT_HEARING)) {
when(asylumCase.read(IS_DECISION_WITHOUT_HEARING, YesOrNo.class)).thenReturn(Optional.of(YES));
} else {
when(asylumCase.read(LIST_CASE_HEARING_CENTRE, HearingCentre.class)).thenReturn(Optional.of(testCase));
}

when(asylumCase.read(LIST_CASE_HEARING_CENTRE, HearingCentre.class)).thenReturn(Optional.of(MANCHESTER));
when(asylumCase.read(APPEAL_REFERENCE_NUMBER, String.class)).thenReturn(Optional.of("some-appeal-ref"));

when(asylumCase.read(LIST_CASE_HEARING_DATE, String.class)).thenReturn(Optional.of("2020-12-25T12:34:56"));
Expand Down Expand Up @@ -81,6 +97,8 @@ public void should_map_case_data_to_template_field_values() {
when(caseDetails.getCaseData()).thenReturn(asylumCase);

when(stringProvider.get("hearingCentreName", "manchester")).thenReturn(Optional.of("Manchester"));
when(stringProvider.get("hearingCentreName", "remoteHearing")).thenReturn(Optional.of("Remote hearing"));
when(stringProvider.get("hearingCentreName", "decisionWithoutHearing")).thenReturn(Optional.of("Decision Without Hearing"));

Map<String, Object> templateFieldValues = decisionAndReasonsTemplate.mapFieldValues(caseDetails);

Expand All @@ -90,7 +108,13 @@ public void should_map_case_data_to_template_field_values() {
assertEquals(templateFieldValues.get("appealReferenceNumber"), "some-appeal-ref");
assertEquals(templateFieldValues.get("hearingDate"), "25122020");
assertEquals(templateFieldValues.get("hearingTime"), "1234");
assertEquals(templateFieldValues.get("hearingCentre"), "Manchester");
if (testCase.equals(REMOTE_HEARING)) {
assertEquals(templateFieldValues.get("hearingCentre"), "Remote hearing");
} else if (testCase.equals(DECISION_WITHOUT_HEARING)) {
assertEquals(templateFieldValues.get("hearingCentre"), "Decision Without Hearing");
} else {
assertEquals(templateFieldValues.get("hearingCentre"), "Manchester");
}

assertEquals(templateFieldValues.get("appellantGivenNames"), "some-given-name");
assertEquals(templateFieldValues.get("appellantFamilyName"), "some-family-name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
@ExtendWith(MockitoExtension.class)
class BailNoticeOfHearingInitialListingTemplateTest {

@Mock private CaseDetails<BailCase> caseDetails;
@Mock private BailCase bailCase;
@Mock private CustomerServicesProvider customerServicesProvider;
@Mock private StringProvider stringProvider;
@Mock
private CaseDetails<BailCase> caseDetails;
@Mock
private BailCase bailCase;
@Mock
private CustomerServicesProvider customerServicesProvider;
@Mock
private StringProvider stringProvider;

private final String applicantGivenNames = "John";
private final String applicantFamilyName = "Smith";
Expand All @@ -51,6 +55,7 @@ class BailNoticeOfHearingInitialListingTemplateTest {
private final String customerServicesPhone = "111122223333";
final String legalRepReference = "legalRepReference";
private CourtVenue hattonCross;

private final String initialListingTemplateName = "TB-IAC-HNO-ENG-Bails-Notice-of-Hearing.docx";

private BailNoticeOfHearingInitialListingTemplate template;
Expand Down Expand Up @@ -187,4 +192,5 @@ void should_get_listing_location_address_from_ccd_with_disabled_ref_data_feature
assertEquals("Nottingham Justice Centre\nCarrington Street\nNottingham\nNG2 1EE",
fieldValuesMap.get("hearingCentreAddress"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ class BailNoticeOfHearingRelistingTemplateTest {
private final String customerServicesEmail = "customer@services.com";
private final String customerServicesPhone = "111122223333";
final String legalRepReference = "legalRepReference";

private final String relistingTemplateName = "TB-IAC-HNO-ENG-bails-notice-of-hearings-relisted.docx";

private CourtVenue newCastle;

private BailNoticeOfHearingRelistingTemplate template;
private Map<String, Object> fieldValuesMap;

Expand All @@ -72,7 +70,6 @@ public void setUp() {
"Y",
"Barras Bridge, Newcastle-Upon-Tyne",
"NE1 8QF");

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,15 @@ void should_throw_if_direction_edit_explanation_not_present() {
.hasMessage("Direction edit explanation is not present");
}

@Test
void should_return_isDecisionWithoutHearingAppeal() {
when(asylumCase.read(IS_DECISION_WITHOUT_HEARING, YesOrNo.class)).thenReturn(Optional.of(YES));
assertTrue(AsylumCaseUtils.isDecisionWithoutHearingAppeal(asylumCase));
}

@Test
void should_return_isRemoteHearing() {
when(asylumCase.read(IS_REMOTE_HEARING, YesOrNo.class)).thenReturn(Optional.of(YES));
assertTrue(AsylumCaseUtils.isRemoteHearing(asylumCase));
}
}

0 comments on commit 22673e7

Please sign in to comment.