Skip to content

Commit

Permalink
DTSCCI-1512: fix npe hearingDuration (#6057)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
rishikrsharma and pats-john authored Feb 5, 2025
1 parent 9c743d2 commit 0254c79
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()));
Expand Down
81 changes: 30 additions & 51 deletions src/main/java/uk/gov/hmcts/reform/civil/utils/HearingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,61 +51,40 @@ public static LocalDate addBusinessDays(LocalDate localDate, int days, Set<Local
}

public static String getHearingType(CaseData caseData) {
switch (caseData.getChannel()) {
case IN_PERSON:
return "in person";
case VIDEO:
return "by video conference";
case TELEPHONE:
return "by telephone";
default:
return "not defined";
}
return switch (caseData.getChannel()) {
case IN_PERSON -> "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) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/uk/gov/hmcts/reform/civil/utils/HmcDataUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -218,6 +220,7 @@ void shouldOnlyIgnoreFeeDetails_1v1_whenHearingFeeHasBeenPaidThroughHwFAndCPTogg
.hearingType("AAA7-TRI")
.build()
)
.caseDetails(CaseDetailsHearing.builder().caseRef("1234567812345678").build())
.build();

CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
Expand All @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0254c79

Please sign in to comment.