From 4f0eeff16b4d15c9bfd6dccb4c68224896450458 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 8 Dec 2025 20:01:05 +0100 Subject: [PATCH] Refine exception message handling for missing transport rates to support nullable end dates. --- .../precalculation/PreCalculationCheckService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/avatic/lcc/service/precalculation/PreCalculationCheckService.java b/src/main/java/de/avatic/lcc/service/precalculation/PreCalculationCheckService.java index f0d3a9f..4099ab2 100644 --- a/src/main/java/de/avatic/lcc/service/precalculation/PreCalculationCheckService.java +++ b/src/main/java/de/avatic/lcc/service/precalculation/PreCalculationCheckService.java @@ -175,16 +175,20 @@ public class PreCalculationCheckService { var rate = matrixRateRepository.getByCountryIds(fromRouteNode.get().getCountryId(), toRouteNode.get().getCountryId(), period.getId()); - if (rate.isEmpty()) - throw new PremiseValidationError("The transport rates for the period " + period.getStartDate().format(DateTimeFormatter.ISO_DATE) + " to " + period.getEndDate().format(DateTimeFormatter.ISO_DATE) + " are insufficient to perform the calculation for route segment" + fromRouteNode.get().getExternalMappingId() + " to " + toRouteNode.get().getExternalMappingId()); + if (rate.isEmpty()) { + var toText = period.getEndDate() == null ? "" : " to " + period.getEndDate().format(DateTimeFormatter.ISO_DATE); + throw new PremiseValidationError("The transport rates for the period " + period.getStartDate().format(DateTimeFormatter.ISO_DATE) + toText + " are insufficient to perform the calculation for route segment" + fromRouteNode.get().getExternalMappingId() + " to " + toRouteNode.get().getExternalMappingId()); + } } if (RateType.CONTAINER == section.getRateType()) { var rate = containerRateRepository.findRoute(fromRouteNode.get().getNodeId(), toRouteNode.get().getNodeId(), period.getId(), section.getTransportType()); - if (rate.isEmpty()) - throw new PremiseValidationError("The transport rates for the period " + period.getStartDate().format(DateTimeFormatter.ISO_DATE) + " to " + period.getEndDate().format(DateTimeFormatter.ISO_DATE) + " are insufficient to perform the calculation for route segment" + fromRouteNode.get().getExternalMappingId() + " to " + toRouteNode.get().getExternalMappingId()); + if (rate.isEmpty()) { + var toText = period.getEndDate() == null ? "" : " to " + period.getEndDate().format(DateTimeFormatter.ISO_DATE); + throw new PremiseValidationError("The transport rates for the period " + period.getStartDate().format(DateTimeFormatter.ISO_DATE) + toText + " are insufficient to perform the calculation for route segment" + fromRouteNode.get().getExternalMappingId() + " to " + toRouteNode.get().getExternalMappingId()); + } }