From 7be68701b5a5d9074df5feafec544cbf38bb16ff Mon Sep 17 00:00:00 2001 From: sankaviv1 <95748224+sankaviv1@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:39:48 +0000 Subject: [PATCH] CIV-11158 Save hearing location in case data (#3524) * CIV-11158 Save hearing location in case data --------- Co-authored-by: Gareth Lancaster <90632240+Gareth40343@users.noreply.github.com> Co-authored-by: Hemanth Potipati Co-authored-by: douglasrice Co-authored-by: Harry H <33700332+HarryH96@users.noreply.github.com> --- .../GenerateHearingNoticeHmcHandler.java | 36 +++++++++++++-- .../hearing/HearingNoticeHmcGenerator.java | 24 ++++------ .../reform/civil/utils/HmcDataUtils.java | 15 +++++++ .../GenerateHearingNoticeHmcHandlerTest.java | 16 ++++++- .../HearingNoticeHmcGeneratorTest.java | 15 ++++--- .../reform/civil/utils/HmcDataUtilsTest.java | 44 +++++++++++++++++++ 6 files changed, 123 insertions(+), 27 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandler.java index 51e1cfaef56..92666ce2608 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandler.java @@ -11,7 +11,11 @@ import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.common.DynamicList; +import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; import uk.gov.hmcts.reform.civil.model.common.Element; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.service.docmosis.hearing.HearingNoticeHmcGenerator; import uk.gov.hmcts.reform.civil.service.hearingnotice.HearingNoticeCamundaService; import uk.gov.hmcts.reform.civil.utils.HearingFeeUtils; @@ -30,6 +34,7 @@ import static uk.gov.hmcts.reform.civil.utils.DateUtils.convertFromUTC; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.getHearingDays; +import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.getLocationRefData; @Service @RequiredArgsConstructor @@ -45,6 +50,7 @@ public class GenerateHearingNoticeHmcHandler extends CallbackHandler { private final HearingsService hearingsService; private final HearingNoticeHmcGenerator hearingNoticeHmcGenerator; private final ObjectMapper objectMapper; + private final LocationRefDataService locationRefDataService; @Override protected Map callbacks() { @@ -65,17 +71,20 @@ private CallbackResponse generateHearingNotice(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); String processInstanceId = caseData.getBusinessProcess().getProcessInstanceId(); + String bearerToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); var camundaVars = camundaService.getProcessVariables(processInstanceId); var hearing = hearingsService.getHearingResponse( - callbackParams.getParams().get(BEARER_TOKEN).toString(), + bearerToken, camundaVars.getHearingId() ); var hearingStartDay = HmcDataUtils.getHearingStartDay(hearing); var hearingStartDate = convertFromUTC(hearingStartDay.getHearingStartDateTime()); + String hearingLocation = getHearingLocation(camundaVars.getHearingId(), hearing, + bearerToken, locationRefDataService); - buildDocument(callbackParams, caseDataBuilder, hearing); + buildDocument(callbackParams, caseDataBuilder, hearing, hearingLocation, camundaVars.getHearingId()); camundaService.setProcessVariables( processInstanceId, @@ -93,16 +102,22 @@ private CallbackResponse generateHearingNotice(CallbackParams callbackParams) { .data(caseDataBuilder .hearingDate(hearingStartDate.toLocalDate()) .hearingDueDate(HearingFeeUtils.calculateHearingDueDate(LocalDate.now(), hearingStartDate.toLocalDate())) + .hearingLocation(DynamicList.builder().value(DynamicListElement.builder() + .label(hearingLocation) + .build()).build()) .build().toMap(objectMapper)) .build(); } - private void buildDocument(CallbackParams callbackParams, CaseData.CaseDataBuilder caseDataBuilder, HearingGetResponse hearing) { + private void buildDocument(CallbackParams callbackParams, CaseData.CaseDataBuilder caseDataBuilder, HearingGetResponse hearing, + String hearingLocation, String hearingId) { CaseData caseData = callbackParams.getCaseData(); List caseDocuments = hearingNoticeHmcGenerator.generate( caseData, hearing, - callbackParams.getParams().get(BEARER_TOKEN).toString() + callbackParams.getParams().get(BEARER_TOKEN).toString(), + hearingLocation, + hearingId ); List> systemGeneratedCaseDocuments = new ArrayList<>(); systemGeneratedCaseDocuments.add(element(caseDocuments.get(0))); @@ -111,4 +126,17 @@ private void buildDocument(CallbackParams callbackParams, CaseData.CaseDataBuild } caseDataBuilder.hearingDocuments(systemGeneratedCaseDocuments); } + + private String getHearingLocation(String hearingId, HearingGetResponse hearing, + String bearerToken, LocationRefDataService locationRefDataService) { + LocationRefData hearingLocation = getLocationRefData( + hearingId, + HmcDataUtils.getHearingStartDay(hearing).getHearingVenueId(), + bearerToken, + locationRefDataService); + if (hearingLocation != null) { + return LocationRefDataService.getDisplayEntry(hearingLocation); + } + return null; + } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGenerator.java index 9cbf7fc5e24..80113bc4d14 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGenerator.java @@ -1,7 +1,6 @@ package uk.gov.hmcts.reform.civil.service.docmosis.hearing; import lombok.RequiredArgsConstructor; -import org.jetbrains.annotations.Nullable; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; @@ -31,6 +30,7 @@ import static java.util.Objects.nonNull; import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.HEARING_NOTICE_HMC; import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.getHearingDaysText; +import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.getLocationRefData; import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.getTotalHearingDurationText; @Service @@ -43,10 +43,10 @@ public class HearingNoticeHmcGenerator implements TemplateDataGenerator generate(CaseData caseData, HearingGetResponse hearing, String authorisation) { + public List generate(CaseData caseData, HearingGetResponse hearing, String authorisation, String hearingLocation, String hearingId) { List caseDocuments = new ArrayList<>(); - HearingNoticeHmc templateData = getHearingNoticeTemplateData(caseData, hearing, authorisation); + HearingNoticeHmc templateData = getHearingNoticeTemplateData(caseData, hearing, authorisation, hearingLocation, hearingId); DocmosisTemplates template = getTemplate(caseData); DocmosisDocument document = documentGeneratorService.generateDocmosisDocument(templateData, template); @@ -61,7 +61,8 @@ public List generate(CaseData caseData, HearingGetResponse hearing return caseDocuments; } - public HearingNoticeHmc getHearingNoticeTemplateData(CaseData caseData, HearingGetResponse hearing, String bearerToken) { + public HearingNoticeHmc getHearingNoticeTemplateData(CaseData caseData, HearingGetResponse hearing, String bearerToken, + String hearingLocation, String hearingId) { var paymentFailed = caseData.getHearingFeePaymentDetails() == null || caseData.getHearingFeePaymentDetails().getStatus().equals(PaymentStatus.FAILED); var feeAmount = paymentFailed @@ -69,15 +70,13 @@ public HearingNoticeHmc getHearingNoticeTemplateData(CaseData caseData, HearingG var hearingDueDate = paymentFailed ? HearingFeeUtils .calculateHearingDueDate(LocalDate.now(), HmcDataUtils.getHearingStartDay(hearing) .getHearingStartDateTime().toLocalDate()) : null; - LocationRefData hearingLocation = getLocationRefData( - HmcDataUtils.getHearingStartDay(hearing).getHearingVenueId(), - bearerToken); + LocationRefData caseManagementLocation = - getLocationRefData(caseData.getCaseManagementLocation().getBaseLocation(), bearerToken); + getLocationRefData(hearingId, caseData.getCaseManagementLocation().getBaseLocation(), bearerToken, locationRefDataService); return HearingNoticeHmc.builder() .hearingSiteName(nonNull(caseManagementLocation) ? caseManagementLocation.getSiteName() : null) - .hearingLocation(LocationRefDataService.getDisplayEntry(hearingLocation)) + .hearingLocation(hearingLocation) .caseNumber(caseData.getCcdCaseReference()) .creationDate(LocalDate.now()) .hearingType(getHearingType(hearing)) @@ -107,13 +106,6 @@ private DocmosisTemplates getTemplate(CaseData caseData) { return HEARING_NOTICE_HMC; } - @Nullable - private LocationRefData getLocationRefData(String venueId, String bearerToken) { - List locations = locationRefDataService.getCourtLocationsForDefaultJudgments(bearerToken); - var matchedLocations = locations.stream().filter(loc -> loc.getEpimmsId().equals(venueId)).toList(); - return matchedLocations.size() > 0 ? matchedLocations.get(0) : null; - } - private String getHearingType(HearingGetResponse hearing) { if (hearing.getHearingDetails().getHearingType().contains("TRI")) { return "trial"; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtils.java index 20de01439ea..ab7cf85cf11 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtils.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.reform.civil.utils; +import org.jetbrains.annotations.Nullable; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.hmc.model.hearing.HearingDaySchedule; import uk.gov.hmcts.reform.hmc.model.hearing.HearingGetResponse; import uk.gov.hmcts.reform.hmc.model.hearings.CaseHearing; @@ -204,4 +207,16 @@ public static boolean includesVideoHearing(HearingsResponse hearings) { && hearings.getCaseHearings().stream() .filter(hearing -> includesVideoHearing(hearing)).count() > 0; } + + @Nullable + public static LocationRefData getLocationRefData(String hearingId, String venueId, + String bearerToken, LocationRefDataService locationRefDataService) { + List locations = locationRefDataService.getCourtLocationsForDefaultJudgments(bearerToken); + var matchedLocations = locations.stream().filter(loc -> loc.getEpimmsId().equals(venueId)).toList(); + if (matchedLocations.size() > 0) { + return matchedLocations.get(0); + } else { + throw new IllegalArgumentException("Hearing location data not available for hearing " + hearingId); + } + } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandlerTest.java index d67db158add..17b08b9e12b 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateHearingNoticeHmcHandlerTest.java @@ -16,6 +16,8 @@ import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.sampledata.CaseDocumentBuilder; import uk.gov.hmcts.reform.civil.service.docmosis.hearing.HearingNoticeHmcGenerator; import uk.gov.hmcts.reform.civil.service.hearingnotice.HearingNoticeCamundaService; @@ -62,6 +64,8 @@ public class GenerateHearingNoticeHmcHandlerTest extends BaseCallbackHandlerTest private HearingNoticeCamundaService camundaService; @MockBean private HearingNoticeHmcGenerator hearingNoticeHmcGenerator; + @MockBean + private LocationRefDataService locationRefDataService; private static Long CASE_ID = 1L; private static String HEARING_ID = "1234"; @@ -108,9 +112,13 @@ public void shouldPopulateCamundaProcessVariables_andReturnExpectedCaseData() { .caseId(CASE_ID) .build(); + List locations = List.of(LocationRefData.builder() + .epimmsId(EPIMS).build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(anyString())) + .thenReturn(locations); when(camundaService.getProcessVariables(PROCESS_INSTANCE_ID)).thenReturn(inputVariables); when(hearingsService.getHearingResponse(anyString(), anyString())).thenReturn(hearing); - when(hearingNoticeHmcGenerator.generate(eq(caseData), eq(hearing), anyString())).thenReturn(List.of(CASE_DOCUMENT)); + when(hearingNoticeHmcGenerator.generate(eq(caseData), eq(hearing), anyString(), anyString(), anyString())).thenReturn(List.of(CASE_DOCUMENT)); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); params.getRequest().setEventId(GENERATE_HEARING_NOTICE_HMC.name()); @@ -168,9 +176,13 @@ public void shouldPopulateCamundaProcessVariables_andReturnExpectedCaseData_BstH .caseId(CASE_ID) .build(); + List locations = List.of(LocationRefData.builder() + .epimmsId(EPIMS).build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(anyString())) + .thenReturn(locations); when(camundaService.getProcessVariables(PROCESS_INSTANCE_ID)).thenReturn(inputVariables); when(hearingsService.getHearingResponse(anyString(), anyString())).thenReturn(hearing); - when(hearingNoticeHmcGenerator.generate(eq(caseData), eq(hearing), anyString())).thenReturn(List.of(CASE_DOCUMENT)); + when(hearingNoticeHmcGenerator.generate(eq(caseData), eq(hearing), anyString(), anyString(), anyString())).thenReturn(List.of(CASE_DOCUMENT)); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); params.getRequest().setEventId(GENERATE_HEARING_NOTICE_HMC.name()); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGeneratorTest.java index c7ab605231c..ebae86ffe38 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGeneratorTest.java @@ -159,7 +159,8 @@ void shouldGenerateHearingNoticeHmc_1v1_whenHearingFeeHasBeenPaid() { .calculatedAmountInPence(new BigDecimal(123)) .build()); - var actual = generator.getHearingNoticeTemplateData(caseData, hearing, BEARER_TOKEN); + var actual = generator.getHearingNoticeTemplateData(caseData, hearing, BEARER_TOKEN, + "SiteName - CourtAddress - Postcode", "hearingId"); var expected = HearingNoticeHmc.builder() .caseNumber(caseData.getCcdCaseReference()) .creationDate(LocalDate.now()) @@ -212,7 +213,8 @@ void shouldGenerateHearingNoticeHmc_1v1_whenHearingFeeHasNotBeenPaid() { .calculatedAmountInPence(new BigDecimal(123)) .build()); - var actual = generator.getHearingNoticeTemplateData(caseData, hearing, BEARER_TOKEN); + var actual = generator.getHearingNoticeTemplateData(caseData, hearing, BEARER_TOKEN, + "SiteName - CourtAddress - Postcode", "hearingId"); var expected = HearingNoticeHmc.builder() .caseNumber(caseData.getCcdCaseReference()) .creationDate(LocalDate.now()) @@ -265,7 +267,8 @@ void shouldGenerateHearingNoticeHmc_1v2DS_whenHearingFeeHasBeenPaid() { .calculatedAmountInPence(new BigDecimal(123)) .build()); - var actual = generator.getHearingNoticeTemplateData(caseData, hearing, BEARER_TOKEN); + var actual = generator.getHearingNoticeTemplateData(caseData, hearing, BEARER_TOKEN, + "SiteName - CourtAddress - Postcode", "hearingId"); var expected = HearingNoticeHmc.builder() .caseNumber(caseData.getCcdCaseReference()) .creationDate(LocalDate.now()) @@ -322,7 +325,8 @@ void shouldGenerateHearingNoticeHmc_2v1_whenHearingFeeHasBeenPaid() { .calculatedAmountInPence(new BigDecimal(123)) .build()); - var actual = generator.getHearingNoticeTemplateData(caseData, hearing, BEARER_TOKEN); + var actual = generator.getHearingNoticeTemplateData(caseData, hearing, BEARER_TOKEN, + "SiteName - CourtAddress - Postcode", "hearingId"); var expected = HearingNoticeHmc.builder() .caseNumber(caseData.getCcdCaseReference()) .creationDate(LocalDate.now()) @@ -377,7 +381,8 @@ void shouldReturnListOfExpectedCaseDocuments() { .calculatedAmountInPence(new BigDecimal(123)) .build()); - var actual = generator.generate(caseData, hearing, BEARER_TOKEN); + var actual = generator.generate(caseData, hearing, BEARER_TOKEN, + "SiteName - CourtAddress - Postcode", "hearingId"); var expected = List.of(CASE_DOCUMENT); verify(documentManagementService) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtilsTest.java index 25c701014df..55f9c09758b 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtilsTest.java @@ -2,6 +2,11 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.hmc.model.hearing.Attendees; import uk.gov.hmcts.reform.hmc.model.hearing.CaseDetailsHearing; import uk.gov.hmcts.reform.hmc.model.hearing.HearingDaySchedule; @@ -20,10 +25,13 @@ import java.util.ArrayList; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.utils.HmcDataUtils.includesVideoHearing; import static uk.gov.hmcts.reform.hmc.model.hearing.HearingSubChannel.INTER; import static uk.gov.hmcts.reform.hmc.model.hearing.HearingSubChannel.VIDCVP; @@ -947,4 +955,40 @@ void shouldReturnTrue_IfVideoHearingsExistOneDayWithinMultipleDays() { assertTrue(actual); } } + + @Nested + @ExtendWith(SpringExtension.class) + class GetHearingLocation { + + @MockBean + private LocationRefDataService locationRefDataService; + + @Test + void shouldReturnLocation_whenInvoked() { + List locations = List.of(LocationRefData.builder().epimmsId("venue").build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments("authToken")) + .thenReturn(locations); + LocationRefData locationRefData = HmcDataUtils.getLocationRefData( + "HER123", + "venue", + "authToken", + locationRefDataService + ); + + assertThat(locationRefData).isEqualTo(LocationRefData.builder().epimmsId("venue").build()); + } + + @Test + void shouldThrowException_whenLocationIsNull() { + when(locationRefDataService.getCourtLocationsForDefaultJudgments("abc")) + .thenReturn(null); + assertThrows( + IllegalArgumentException.class, + () -> HmcDataUtils.getLocationRefData( + "HER123", + "abc", + "authToken", + locationRefDataService)); + } + } }