Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import uk.gov.hmcts.reform.civil.enums.dq.Language;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.caseflags.FlagDetail;
import uk.gov.hmcts.reform.civil.model.common.DynamicList;
import uk.gov.hmcts.reform.civil.model.common.Element;
import uk.gov.hmcts.reform.civil.model.hearingvalues.HearingLocationModel;
import uk.gov.hmcts.reform.civil.model.hearingvalues.HearingWindowModel;
import uk.gov.hmcts.reform.civil.model.hearingvalues.JudiciaryModel;
Expand All @@ -13,6 +16,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -111,18 +115,32 @@ public static List<String> getFacilitiesRequired(CaseData caseData) {
public static String getListingComments(CaseData caseData) {
String comments = getAllActiveFlags(caseData).stream()
.flatMap(flags -> flags.getDetails().stream())
.filter(flag -> flag.getValue() != null && flag.getValue().getFlagCode().equals(AUDIO_VIDEO_EVIDENCE_FLAG))
.map(flag -> String.format(flag.getValue().getFlagComment() == null ? "%s, " : "%s: %s, ", flag.getValue().getName(), flag.getValue().getFlagComment()))
.filter(HearingDetailsMapper::isAudioVideoEvidenceFlag)
.map(HearingDetailsMapper::formatListingComment)
.reduce("", String::concat)
.replaceAll("\n", " ")
.replace("\n", " ")
.replaceAll("\\s+", " ");

if (comments != null && !comments.isEmpty()) {
String refactoredComment = comments.substring(0, comments.length() - 2);
return refactoredComment.length() > 200 ? refactoredComment.substring(0, 200) : refactoredComment;
return normaliseListingComments(comments);
}

private static boolean isAudioVideoEvidenceFlag(Element<FlagDetail> flag) {
return flag.getValue() != null && AUDIO_VIDEO_EVIDENCE_FLAG.equals(flag.getValue().getFlagCode());
}

private static String formatListingComment(Element<FlagDetail> flag) {
return String.format(flag.getValue().getFlagComment() == null ? "%s, " : "%s: %s, ",
flag.getValue().getName(),
flag.getValue().getFlagComment());
}

private static String normaliseListingComments(String comments) {
if (comments.isEmpty()) {
return null;
}

return null;
String refactoredComment = comments.substring(0, comments.length() - 2);
return refactoredComment.length() > 200 ? refactoredComment.substring(0, 200) : refactoredComment;
}

public static String getHearingRequester() {
Expand Down Expand Up @@ -155,23 +173,39 @@ public static List<String> getHearingChannels(String authToken, String hmctsServ
log.info("Hearing method codes are not available for hmctsServiceId {} caseId {}", hmctsServiceId, caseData.getCcdCaseReference());
return null;
}
if (caseData.getSdoR2SmallClaimsHearing() != null && caseData.getSdoR2SmallClaimsHearing().getMethodOfHearing() != null) {
return List.of(hearingMethodCode.get(getDynamicListValue(caseData.getSdoR2SmallClaimsHearing().getMethodOfHearing())));
} else if (caseData.getSdoR2Trial() != null && caseData.getSdoR2Trial().getMethodOfHearing() != null) {
return List.of(hearingMethodCode.get(getDynamicListValue(caseData.getSdoR2Trial().getMethodOfHearing())));
} else if (caseData.getHearingMethodValuesFastTrack() != null) {
return List.of(hearingMethodCode.get(getDynamicListValue(caseData.getHearingMethodValuesFastTrack())));
} else if (caseData.getHearingMethodValuesDisposalHearing() != null) {
return List.of(hearingMethodCode.get(getDynamicListValue(caseData.getHearingMethodValuesDisposalHearing())));
} else if (caseData.getHearingMethodValuesDisposalHearingDJ() != null) {
return List.of(hearingMethodCode.get(getDynamicListValue(caseData.getHearingMethodValuesDisposalHearingDJ())));
} else if (caseData.getHearingMethodValuesTrialHearingDJ() != null) {
return List.of(hearingMethodCode.get(getDynamicListValue(caseData.getHearingMethodValuesTrialHearingDJ())));
} else if (caseData.getHearingMethodValuesSmallClaims() != null) {
return List.of(hearingMethodCode.get(getDynamicListValue(caseData.getHearingMethodValuesSmallClaims())));
} else {
return null;
}
String hearingMethod = resolveHearingMethod(caseData);
return hearingMethod != null ? List.of(hearingMethodCode.get(hearingMethod)) : null;
}

private static String resolveHearingMethod(CaseData caseData) {
return Stream.of(
getSdoR2SmallClaimsHearingMethod(caseData),
getSdoR2TrialHearingMethod(caseData),
getDynamicListValueIfPresent(caseData.getHearingMethodValuesFastTrack()),
getDynamicListValueIfPresent(caseData.getHearingMethodValuesDisposalHearing()),
getDynamicListValueIfPresent(caseData.getHearingMethodValuesDisposalHearingDJ()),
getDynamicListValueIfPresent(caseData.getHearingMethodValuesTrialHearingDJ()),
getDynamicListValueIfPresent(caseData.getHearingMethodValuesSmallClaims())
)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
}

private static String getSdoR2SmallClaimsHearingMethod(CaseData caseData) {
return caseData.getSdoR2SmallClaimsHearing() != null
? getDynamicListValueIfPresent(caseData.getSdoR2SmallClaimsHearing().getMethodOfHearing())
: null;
}

private static String getSdoR2TrialHearingMethod(CaseData caseData) {
return caseData.getSdoR2Trial() != null
? getDynamicListValueIfPresent(caseData.getSdoR2Trial().getMethodOfHearing())
: null;
}

private static String getDynamicListValueIfPresent(DynamicList dynamicList) {
return dynamicList != null ? getDynamicListValue(dynamicList) : null;
}

}
Loading
Loading