Added user friendly error messages
This commit is contained in:
parent
0edcfb5258
commit
27166e4b00
1 changed files with 47 additions and 43 deletions
|
|
@ -81,6 +81,7 @@ public class PreCalculationCheckService {
|
|||
doPrecheck(premiseId, set, period, LocalDate.now());
|
||||
}
|
||||
|
||||
|
||||
public void doPrecheck(Integer premiseId, Optional<PropertySet> set, Optional<ValidityPeriod> period, LocalDate date) {
|
||||
var premise = premiseRepository.getPremiseById(premiseId).orElseThrow();
|
||||
|
||||
|
|
@ -95,7 +96,7 @@ public class PreCalculationCheckService {
|
|||
var destinations = destinationRepository.getByPremiseId(premiseId);
|
||||
|
||||
if (destinations == null || destinations.isEmpty()) {
|
||||
throw new PremiseValidationError("No destination defined yet, please add at least one destination.");
|
||||
throw new PremiseValidationError("Please add at least one destination to continue");
|
||||
}
|
||||
|
||||
for (Destination destination : destinations) {
|
||||
|
|
@ -108,17 +109,17 @@ public class PreCalculationCheckService {
|
|||
|
||||
|
||||
if (routes.isEmpty() && destination.getD2d() == false)
|
||||
throw new PremiseValidationError("No standard route available for destination " + node.getName() + ". Please use individual rate or contact your administrator.");
|
||||
throw new PremiseValidationError(String.format("No standard route found for %s - try using an individual rate instead", node.getName()));
|
||||
|
||||
if (routes.stream().noneMatch(Route::getSelected) && destination.getD2d() == false)
|
||||
throw new PremiseValidationError("No route selected for destination " + node.getName());
|
||||
throw new PremiseValidationError(String.format("Please select a route for %s", node.getName()));
|
||||
|
||||
if (destination.getD2d() && (destination.getRateD2d() == null || destination.getRateD2d().compareTo(BigDecimal.ZERO) == 0)) {
|
||||
throw new PremiseValidationError("Door-2-door rate not entered or zero.");
|
||||
throw new PremiseValidationError("Please enter a door-to-door rate greater than zero");
|
||||
}
|
||||
|
||||
if (destination.getD2d() && (destination.getLeadTimeD2d() == null || destination.getLeadTimeD2d() == 0)) {
|
||||
throw new PremiseValidationError("Door-2-door lead time not entered or zero.");
|
||||
throw new PremiseValidationError("Please enter a door-to-door lead time");
|
||||
}
|
||||
|
||||
periodCheck(period.orElse(null), set.orElse(null), date);
|
||||
|
|
@ -133,16 +134,16 @@ public class PreCalculationCheckService {
|
|||
private void periodCheck(ValidityPeriod period, PropertySet set, LocalDate calculationDate) {
|
||||
|
||||
if (set == null)
|
||||
throw new PremiseValidationError("There are no system properties for the given date. Please contact your administrator.");
|
||||
throw new PremiseValidationError("No system data available for this date - please contact your administrator");
|
||||
|
||||
if (period == null)
|
||||
throw new PremiseValidationError("There are no rates for the given date. Please contact your administrator.");
|
||||
throw new PremiseValidationError("No rates available for this date - please contact your administrator");
|
||||
|
||||
if (ValidityPeriodState.VALID != period.getState() && ValidityPeriodState.EXPIRED != period.getState())
|
||||
throw new PremiseValidationError("There are no valid rates for the given date. Please contact your administrator.");
|
||||
throw new PremiseValidationError("Rates for this date aren't valid yet - please contact your administrator");
|
||||
|
||||
if (ValidityPeriodState.VALID != set.getState() && ValidityPeriodState.EXPIRED != period.getState())
|
||||
throw new PremiseValidationError("There are no valid system properties for the given date. Please contact your administrator.");
|
||||
throw new PremiseValidationError("System properties for this date aren't valid yet - please contact your administrator");
|
||||
|
||||
|
||||
if (calculationDate == null) {
|
||||
|
|
@ -151,12 +152,12 @@ public class PreCalculationCheckService {
|
|||
var renewals = period.getRenewals();
|
||||
|
||||
if (validDays.isEmpty())
|
||||
throw new PremiseValidationError("There are no valid days property. Please contact your administrator");
|
||||
throw new PremiseValidationError("Missing configuration - please contact your administrator");
|
||||
|
||||
var validDaysInt = Integer.parseInt(validDays.get().getCurrentValue());
|
||||
|
||||
if (!period.getStartDate().plusDays((((long) validDaysInt * renewals) + validDaysInt)).isAfter(LocalDateTime.now()))
|
||||
throw new PremiseValidationError("There are no valid rates for the given date. Please contact your administrator.");
|
||||
throw new PremiseValidationError("Rates for this date aren't valid yet - please contact your administrator");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -168,7 +169,7 @@ public class PreCalculationCheckService {
|
|||
var toRouteNode = routeNodeRepository.getToNodeBySectionId(section.getId());
|
||||
|
||||
if (fromRouteNode.isEmpty() || toRouteNode.isEmpty())
|
||||
throw new PremiseValidationError("Error in route. Please contact your administrator.");
|
||||
throw new PremiseValidationError("Route configuration issue - please contact your administrator");
|
||||
|
||||
if (RateType.MATRIX == section.getRateType()) {
|
||||
var rate = matrixRateRepository.getByCountryIds(fromRouteNode.get().getCountryId(), toRouteNode.get().getCountryId(), period.getId());
|
||||
|
|
@ -184,8 +185,11 @@ public class PreCalculationCheckService {
|
|||
|
||||
private void constructRouteSectionError(LocalDate calculationDate, RouteNode fromRouteNode, RouteNode toRouteNode, boolean empty) {
|
||||
if (empty) {
|
||||
var dateStr = calculationDate == null ? "" : String.format("on given date %s", calculationDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")));
|
||||
var errStr = String.format("Missing transport rate for route section %s to %s %s. Please contact your admin.", fromRouteNode.getExternalMappingId(), toRouteNode.getExternalMappingId(), dateStr);
|
||||
var dateStr = calculationDate == null ? "" : String.format("on %s", calculationDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")));
|
||||
var errStr = String.format("Transport rate missing for %s to %s %s - please contact your administrator",
|
||||
fromRouteNode.getExternalMappingId(),
|
||||
toRouteNode.getExternalMappingId(),
|
||||
dateStr);
|
||||
throw new PremiseValidationError(errStr);
|
||||
}
|
||||
}
|
||||
|
|
@ -193,39 +197,39 @@ public class PreCalculationCheckService {
|
|||
private void destinationCheck(Destination destination, Node node) {
|
||||
|
||||
if (destination.getAnnualAmount() == null || destination.getAnnualAmount() == 0)
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": annual quantity must be greater than zero.");
|
||||
throw new PremiseValidationError(String.format("Annual quantity for %s must be greater than zero", node.getName()));
|
||||
|
||||
if (destination.getD2d() == null)
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": Door-2-Door flag is missing. Please contact administrator.");
|
||||
throw new PremiseValidationError(String.format("Something's missing for %s - please contact your administrator", node.getName()));
|
||||
|
||||
if (destination.getD2d() == true) {
|
||||
if (destination.getRateD2d() == null || destination.getRateD2d().compareTo(BigDecimal.ZERO) == 0) {
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": Door-2-door rate not entered or zero.");
|
||||
throw new PremiseValidationError(String.format("Door-to-door rate for %s needs to be greater than zero", node.getName()));
|
||||
}
|
||||
|
||||
if (destination.getLeadTimeD2d() == null || destination.getLeadTimeD2d() == 0) {
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": Door-2-Door lead time not entered or zero.");
|
||||
throw new PremiseValidationError(String.format("Please set a lead time for door-to-door delivery to %s", node.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
if (destination.getCountryId() == null || destination.getCountryId() == 0) {
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": destination country ID not set. Please contact your administrator.");
|
||||
throw new PremiseValidationError(String.format("Configuration issue with %s - please contact your administrator", node.getName()));
|
||||
}
|
||||
|
||||
if (destination.getGeoLat() == null || destination.getGeoLng() == null) {
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": destination geo location not set. Please contact your administrator.");
|
||||
throw new PremiseValidationError(String.format("Location data missing for %s - please contact your administrator", node.getName()));
|
||||
}
|
||||
|
||||
if (destination.getDisposalCost() != null && destination.getDisposalCost().compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": disposal costs are not set or entered value is less than zero.");
|
||||
throw new PremiseValidationError(String.format("Disposal costs for %s can't be negative", node.getName()));
|
||||
}
|
||||
|
||||
if (destination.getHandlingCost() != null && destination.getHandlingCost().compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": handling costs are not set or entered value is less than zero.");
|
||||
throw new PremiseValidationError(String.format("Handling costs for %s can't be negative", node.getName()));
|
||||
}
|
||||
|
||||
if (destination.getRepackingCost() != null && destination.getRepackingCost().compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new PremiseValidationError("In destination " + node.getName() + ": repackaging costs are not set or entered value is less than zero.");
|
||||
throw new PremiseValidationError(String.format("Repackaging costs for %s can't be negative", node.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -233,22 +237,22 @@ public class PreCalculationCheckService {
|
|||
private void supplierCheck(Premise premise) {
|
||||
|
||||
if (premise.getSupplierNodeId() == null && premise.getUserSupplierNodeId() == null)
|
||||
throw new PremiseValidationError("Supplier node not set. Please contact administrator");
|
||||
throw new PremiseValidationError("Supplier information is missing - please contact your administrator");
|
||||
|
||||
}
|
||||
|
||||
private void priceCheck(Premise premise) {
|
||||
|
||||
if (premise.getMaterialCost() == null || premise.getMaterialCost().compareTo(BigDecimal.ZERO) == 0) {
|
||||
throw new PremiseValidationError("MEK_A not entered or zero.");
|
||||
throw new PremiseValidationError("Please enter a material cost (MEK_A) greater than zero");
|
||||
}
|
||||
|
||||
if (premise.getOverseaShare() == null) {
|
||||
throw new PremiseValidationError("Oversea share not entered.");
|
||||
throw new PremiseValidationError("Please enter the overseas share");
|
||||
}
|
||||
|
||||
if (premise.getFcaEnabled() == null) {
|
||||
throw new PremiseValidationError("FCA fee not set. Please contact administrator");
|
||||
throw new PremiseValidationError("FCA configuration missing - please contact your administrator");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -256,43 +260,43 @@ public class PreCalculationCheckService {
|
|||
private void packagingCheck(Premise premise) {
|
||||
|
||||
if (premise.getHuMixable() == null) {
|
||||
throw new PremiseValidationError("Mixable not set. Please contact administrator.");
|
||||
throw new PremiseValidationError("Packaging configuration incomplete - please contact your administrator");
|
||||
}
|
||||
|
||||
if (premise.getHuStackable() == null) {
|
||||
throw new PremiseValidationError("Stackable not set. Please contact administrator.");
|
||||
throw new PremiseValidationError("Packaging configuration incomplete - please contact your administrator");
|
||||
}
|
||||
|
||||
if (premise.getHuStackable() == false && premise.getHuMixable() == true) {
|
||||
throw new PremiseValidationError("Stackable cannot be false, when mixable is true.");
|
||||
throw new PremiseValidationError("If packaging is mixable, it must also be stackable");
|
||||
}
|
||||
|
||||
if (premise.getIndividualHuLength() == null || premise.getIndividualHuLength() == 0) {
|
||||
throw new PremiseValidationError("Packaging length not entered or zero.");
|
||||
throw new PremiseValidationError("Please enter packaging length");
|
||||
}
|
||||
|
||||
if (premise.getIndividualHuWidth() == null || premise.getIndividualHuWidth() == 0) {
|
||||
throw new PremiseValidationError("Packaging width not entered or zero.");
|
||||
throw new PremiseValidationError("Please enter packaging width");
|
||||
}
|
||||
|
||||
if (premise.getIndividualHuHeight() == null || premise.getIndividualHuHeight() == 0) {
|
||||
throw new PremiseValidationError("Packaging height not entered or zero.");
|
||||
throw new PremiseValidationError("Please enter packaging height");
|
||||
}
|
||||
|
||||
if (premise.getIndividualHuWeight() == null || premise.getIndividualHuWeight() == 0) {
|
||||
throw new PremiseValidationError("Packaging weight not entered or zero");
|
||||
throw new PremiseValidationError("Please enter packaging weight");
|
||||
}
|
||||
|
||||
if (premise.getHuUnitCount() == null || premise.getHuUnitCount() == 0) {
|
||||
throw new PremiseValidationError("Packaging unit count not entered or zero.");
|
||||
throw new PremiseValidationError("Please enter the number of units per package");
|
||||
}
|
||||
|
||||
if (premise.getHuDisplayedWeightUnit() == null) {
|
||||
throw new PremiseValidationError("Packaging weight unit not set. Please contact administrator.");
|
||||
throw new PremiseValidationError("Weight unit configuration missing - please contact your administrator");
|
||||
}
|
||||
|
||||
if (premise.getHuDisplayedDimensionUnit() == null) {
|
||||
throw new PremiseValidationError("Packaging dimension unit not set. Please contact administrator.");
|
||||
throw new PremiseValidationError("Dimension unit configuration missing - please contact your administrator");
|
||||
}
|
||||
|
||||
var hu = dimensionTransformer.toDimensionEntity(premise).withTolerance(DIMENSION_TOLERANCE);
|
||||
|
|
@ -301,21 +305,21 @@ public class PreCalculationCheckService {
|
|||
Optional<Integer> feuLoad = propertyService.getProperty(SystemPropertyMappingId.TEU_LOAD);
|
||||
|
||||
if (teuLoad.isEmpty() || feuLoad.isEmpty())
|
||||
throw new PremiseValidationError("System properties not properly configured. Please contact your administrator.");
|
||||
throw new PremiseValidationError("System configuration incomplete - please contact your administrator");
|
||||
|
||||
if (WeightUnit.KG.convertFromG(hu.getWeight()) > teuLoad.get() && hu.getWeight() > feuLoad.get())
|
||||
throw new PremiseValidationError("HU weight exceeds maximum container weight load (" + Math.max(teuLoad.get(), feuLoad.get()) + " kg). Review entered weight and selected weight unit [g, kg, t].");
|
||||
throw new PremiseValidationError(String.format("Package weight exceeds %d kg - please check your weight and unit", Math.max(teuLoad.get(), feuLoad.get())));
|
||||
|
||||
var teuFitsXY = (hu.getLength() < ContainerType.TEU.getLength() && hu.getWidth() < ContainerType.TEU.getWidth());
|
||||
var teuFitsYX = (hu.getWidth() < ContainerType.TEU.getLength() && hu.getLength() < ContainerType.TEU.getWidth());
|
||||
|
||||
if (!teuFitsYX && !teuFitsXY) {
|
||||
throw new PremiseValidationError("HU dimensions too large. Review entered length, width, height and selected dimension unit [mm, cm, m].");
|
||||
throw new PremiseValidationError("Package dimensions are too large - please check your measurements and unit");
|
||||
}
|
||||
|
||||
|
||||
if ((hu.getLength() * hu.getWidth()) < 20000) {
|
||||
throw new PremiseValidationError("HU dimensions too small. Review entered length, width, height and selected dimension unit [mm, cm, m].");
|
||||
throw new PremiseValidationError("Package dimensions are too small - please check your measurements and unit");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -332,8 +336,8 @@ public class PreCalculationCheckService {
|
|||
// }
|
||||
|
||||
if (premise.getTariffRate() == null) {
|
||||
throw new PremiseValidationError("Tariff rate not entered.");
|
||||
throw new PremiseValidationError("Please enter a tariff rate");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue