From 0254c79db37828e74682a89ff1e04ad5d998d3e8 Mon Sep 17 00:00:00 2001 From: rishikrsharma Date: Wed, 5 Feb 2025 17:33:26 +0000 Subject: [PATCH] DTSCCI-1512: fix npe hearingDuration (#6057) * DTSCCI-1512: fix npe hearingDuration * DTSCCI-1512: fix npe hearingDuration * DTSCCI-1512: fix npe hearingDuration * DTSCCI-1512: fix npe hearingDuration --------- Co-authored-by: pats-john <13101669+pats-john@users.noreply.github.com> --- .../user/TrialReadinessCallbackHandler.java | 4 + .../reform/civil/utils/HearingUtils.java | 81 +++++++------------ .../reform/civil/utils/HmcDataUtils.java | 10 ++- .../HearingNoticeHmcGeneratorTest.java | 19 +++-- .../reform/civil/utils/HearingUtilsTest.java | 9 ++- 5 files changed, 63 insertions(+), 60 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandler.java index e617cdc5088..1a4c90f8732 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/TrialReadinessCallbackHandler.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; @@ -43,6 +44,7 @@ import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isLIPDefendant; import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorOne; +@Slf4j @Service @RequiredArgsConstructor public class TrialReadinessCallbackHandler extends CallbackHandler { @@ -86,6 +88,8 @@ private CallbackResponse populateValues(CallbackParams callbackParams) { var isApplicant = YesOrNo.NO; var isRespondent1 = YesOrNo.NO; var isRespondent2 = YesOrNo.NO; + log.info("TrialReadinessCallbackHandler Hearing duration: {} for caseId {}", caseData.getHearingDuration(), + caseData.getCcdCaseReference()); if (isApplicantSolicitor(userRoles)) { isApplicant = YesOrNo.YES; updatedData.hearingDurationTextApplicant(formatHearingDuration(caseData.getHearingDuration())); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/HearingUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/HearingUtils.java index aea67f03e41..f267da4ce4c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/HearingUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/HearingUtils.java @@ -51,61 +51,40 @@ public static LocalDate addBusinessDays(LocalDate localDate, int days, Set "in person"; + case VIDEO -> "by video conference"; + case TELEPHONE -> "by telephone"; + default -> "not defined"; + }; } public static String formatHearingDuration(HearingDuration hearingDuration) { - switch (hearingDuration) { - case MINUTES_05: - return "5 minutes"; - case MINUTES_10: - return "10 minutes"; - case MINUTES_15: - return "15 minutes"; - case MINUTES_20: - return "20 minutes"; - case MINUTES_25: - return "25 minutes"; - case MINUTES_30: - return "30 minutes"; - case MINUTES_35: - return "35 minutes"; - case MINUTES_40: - return "40 minutes"; - case MINUTES_45: - return "45 minutes"; - case MINUTES_50: - return "50 minutes"; - case MINUTES_55: - return "55 minutes"; - case MINUTES_60: - return "1 hour"; - case MINUTES_90: - return "1 and half hours"; - case MINUTES_120: - return "2 hours"; - case MINUTES_150: - return "2 and half hours"; - case MINUTES_180: - return "3 hours"; - case MINUTES_240: - return "4 hours"; - case DAY_1: - return "1 day"; - case DAY_2: - return "2 days"; - default: - return null; + if (hearingDuration == null) { + return null; } + return switch (hearingDuration) { + case MINUTES_05 -> "5 minutes"; + case MINUTES_10 -> "10 minutes"; + case MINUTES_15 -> "15 minutes"; + case MINUTES_20 -> "20 minutes"; + case MINUTES_25 -> "25 minutes"; + case MINUTES_30 -> "30 minutes"; + case MINUTES_35 -> "35 minutes"; + case MINUTES_40 -> "40 minutes"; + case MINUTES_45 -> "45 minutes"; + case MINUTES_50 -> "50 minutes"; + case MINUTES_55 -> "55 minutes"; + case MINUTES_60 -> "1 hour"; + case MINUTES_90 -> "1 and half hours"; + case MINUTES_120 -> "2 hours"; + case MINUTES_150 -> "2 and half hours"; + case MINUTES_180 -> "3 hours"; + case MINUTES_240 -> "4 hours"; + case DAY_1 -> "1 day"; + case DAY_2 -> "2 days"; + default -> null; + }; } public static String formatHearingFee(Fee hearingFee) { 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 0c84f402c6b..31a84aa9c68 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,6 @@ package uk.gov.hmcts.reform.civil.utils; +import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.Nullable; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; @@ -34,13 +35,13 @@ import static uk.gov.hmcts.reform.hmc.model.hearing.HearingSubChannel.TELCVP; import static uk.gov.hmcts.reform.hmc.model.hearing.HearingSubChannel.VIDCVP; +@Slf4j public class HmcDataUtils { private HmcDataUtils() { // NO OP } - private static final String HEARING = "hearing"; private static final int HOURS_PER_DAY = 6; private static final int MINUTES_PER_HOUR = 60; @@ -190,7 +191,9 @@ public static Integer getTotalHearingDurationInMinutes(HearingGetResponse hearin */ public static String getTotalHearingDurationText(HearingGetResponse hearing) { Integer totalDurationInMinutes = getTotalHearingDurationInMinutes(hearing); + String caseRef = hearing.getCaseDetails() != null ? hearing.getCaseDetails().getCaseRef() : "reference not available"; if (totalDurationInMinutes == null) { + log.info("Total Duration In Minutes from Hmc handler is null for caseId {}", caseRef); return null; } @@ -199,8 +202,9 @@ public static String getTotalHearingDurationText(HearingGetResponse hearing) { int days = (int)Math.floor(totalDurationInHours / HOURS_PER_DAY); int hours = (int)(totalDurationInHours - (days * HOURS_PER_DAY)); int minutes = (int)(totalDurationInMinutes - (totalDurationInHours * MINUTES_PER_HOUR)); - - return daysHoursMinutesFormat(days, hours, minutes); + String hearingDurationText = daysHoursMinutesFormat(days, hours, minutes); + log.info("Total hearing duration from Hmc handler: {} for caseId {}", hearingDurationText, caseRef); + return hearingDurationText; } /** 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 633e1e59507..aae9acee5f6 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 @@ -37,6 +37,7 @@ import uk.gov.hmcts.reform.civil.service.hearings.HearingFeesService; import uk.gov.hmcts.reform.civil.service.referencedata.LocationReferenceDataService; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; +import uk.gov.hmcts.reform.hmc.model.hearing.CaseDetailsHearing; import uk.gov.hmcts.reform.hmc.model.hearing.HearingDaySchedule; import uk.gov.hmcts.reform.hmc.model.hearing.HearingDetails; import uk.gov.hmcts.reform.hmc.model.hearing.HearingGetResponse; @@ -73,11 +74,11 @@ class HearingNoticeHmcGeneratorTest { private HearingGetResponse baseHearing; - private static final String fileName_application = String.format( + private static final String FILE_NAME_APPLICATION = String.format( HEARING_NOTICE_HMC.getDocumentTitle(), REFERENCE_NUMBER); private static final CaseDocument CASE_DOCUMENT = CaseDocumentBuilder.builder() - .documentName(fileName_application) + .documentName(FILE_NAME_APPLICATION) .documentType(HEARING_FORM) .build(); @@ -102,7 +103,7 @@ void setupTest() { .thenReturn(new DocmosisDocument(HEARING_NOTICE_HMC.getDocumentTitle(), bytes)); when(documentManagementService - .uploadDocument(BEARER_TOKEN, new PDF(fileName_application, bytes, HEARING_FORM))) + .uploadDocument(BEARER_TOKEN, new PDF(FILE_NAME_APPLICATION, bytes, HEARING_FORM))) .thenReturn(CASE_DOCUMENT); when(locationRefDataService @@ -156,6 +157,7 @@ void shouldGenerateHearingNoticeHmc_1v1_whenHearingFeeHasBeenPaid(boolean isCase .hearingType("AAA7-TRI") .build() ) + .caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build()) .build(); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() @@ -218,6 +220,7 @@ void shouldOnlyIgnoreFeeDetails_1v1_whenHearingFeeHasBeenPaidThroughHwFAndCPTogg .hearingType("AAA7-TRI") .build() ) + .caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build()) .build(); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() @@ -281,6 +284,7 @@ void shouldGenerateHearingNoticeHmc_1v1_whenHearingFeeHasNotBeenPaid(boolean isC .hearingDetails(HearingDetails.builder() .hearingType("AAA7-TRI") .build()) + .caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build()) .build(); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() @@ -342,6 +346,7 @@ void shouldGenerateHearingNoticeHmc_1v2DS_whenHearingFeeHasBeenPaid(boolean isCa .hearingDetails(HearingDetails.builder() .hearingType("AAA7-DIS") .build()) + .caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build()) .build(); CaseData caseData = CaseDataBuilder.builder().atState1v2DifferentSolicitorClaimDetailsRespondent2NotifiedTimeExtension() @@ -410,6 +415,7 @@ void shouldGenerateHearingNoticeHmc_2v1_whenHearingFeeHasBeenPaid_whenHearingTyp .hearingDetails(HearingDetails.builder() .hearingType(hearingType) .build()) + .caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build()) .build(); CaseData caseData = CaseDataBuilder.builder() @@ -475,6 +481,7 @@ void shouldGenerateHearingNoticeHmc_2v1_whenHearingFeeHasBeenPaid_noSolicitorRef .hearingDetails(HearingDetails.builder() .hearingType("AAA7-DRH") .build()) + .caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build()) .build(); CaseData caseData = CaseDataBuilder.builder() @@ -538,6 +545,7 @@ void shouldReturnListOfExpectedCaseDocuments(boolean isCaseProgressionEnabled) { .hearingDetails(HearingDetails.builder() .hearingType("AAA7-TRI") .build()) + .caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build()) .build(); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() @@ -568,7 +576,7 @@ void shouldReturnListOfExpectedCaseDocuments(boolean isCaseProgressionEnabled) { var expected = List.of(CASE_DOCUMENT); verify(documentManagementService) - .uploadDocument(BEARER_TOKEN, new PDF(fileName_application, bytes, HEARING_FORM)); + .uploadDocument(BEARER_TOKEN, new PDF(FILE_NAME_APPLICATION, bytes, HEARING_FORM)); assertEquals(expected, actual); } @@ -582,6 +590,7 @@ void shouldReturnListOfExpectedCaseDocumentsSpec(boolean isCaseProgressionEnable .hearingDetails(HearingDetails.builder() .hearingType("AAA7-TRI") .build()) + .caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build()) .build(); CaseData caseData = CaseDataBuilder.builder() @@ -613,7 +622,7 @@ void shouldReturnListOfExpectedCaseDocumentsSpec(boolean isCaseProgressionEnable var expected = List.of(CASE_DOCUMENT); verify(documentManagementService) - .uploadDocument(BEARER_TOKEN, new PDF(fileName_application, bytes, HEARING_FORM)); + .uploadDocument(BEARER_TOKEN, new PDF(FILE_NAME_APPLICATION, bytes, HEARING_FORM)); assertEquals(expected, actual); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/HearingUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/HearingUtilsTest.java index 84a30410464..ce364ade22d 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/HearingUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/HearingUtilsTest.java @@ -22,9 +22,10 @@ import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; -public class HearingUtilsTest { +class HearingUtilsTest { @Test void shouldThrowNullException_whenGivenNullDate() { @@ -62,6 +63,12 @@ void shouldReturnHearingDuration_whenGivenAnyHearingDuration(HearingDuration hea assertThat(HearingUtils.formatHearingDuration(hearingDuration)).isNotEmpty(); } + @Test + void shouldReturnHearingDuration_whenGivenAnyHearingDuration_extended() { + HearingDuration hearingDuration = null; + assertNull(HearingUtils.formatHearingDuration(hearingDuration)); + } + @ParameterizedTest @ValueSource(strings = {"000", "50000", "08:00", "8:00", "12:00", "23:00"}) @DisplayName("HearingUtils.getHearingTimeFormatted should not allow invalid values. Valid values"