Skip to content

Commit

Permalink
DT-786 review comment addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
preetamnpr committed Mar 1, 2024
1 parent 2f55330 commit 2f89dab
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.dcsa.conformance.standards.booking.action;

import java.util.*;
import java.util.function.Function;

import java.util.stream.Stream;

import com.fasterxml.jackson.databind.node.ObjectNode;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.toolkit.JsonToolkit;
import org.dcsa.conformance.core.traffic.ConformanceExchange;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.booking.checks.BookingChecks;
import org.dcsa.conformance.standards.booking.checks.CarrierGetBookingPayloadResponseConformanceCheck;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,38 @@ public static ActionCheck requestContentChecks(UUID matched, Supplier<CarrierSce
private static final JsonContentCheck CHECK_EXPECTED_DEPARTURE_DATE = JsonAttribute.customValidator(
"Check expected departure date can not be past date",
(body) -> {
String providedLocalDate = body.path("expectedDepartureDate").asText("");
String expectedDepartureDate = body.path("expectedDepartureDate").asText("");
var invalidDates = new LinkedHashSet<String>();
LocalDate providedExpectedDepartureDate = LocalDate.parse(providedLocalDate);
if (providedExpectedDepartureDate.isBefore(LocalDate.now())) {
invalidDates.add(providedLocalDate);
if(!expectedDepartureDate.isEmpty()) {
LocalDate expectedDepartureLocalDate = LocalDate.parse(expectedDepartureDate);
if (expectedDepartureLocalDate.isBefore(LocalDate.now())) {
invalidDates.add(expectedDepartureLocalDate.toString());
}
}
return invalidDates.stream()
.map("The expected departure date '%s' can not be paste date"::formatted)
.map("The expected departure date '%s' can not be paste date"::formatted)
.collect(Collectors.toSet());
}
);

private static final JsonContentCheck CHECK_EXPECTED_ARRIVAL_POD = JsonAttribute.customValidator(
"Check expected arrival dates can valid",
"Check expected arrival dates are valid",
(body) -> {
String providedArrivalStartDate = body.path("expectedArrivalAtPlaceOfDeliveryStartDate").asText("");
String providedArrivalEndDate = body.path("expectedArrivalAtPlaceOfDeliveryEndDate").asText("");
var invalidDates = new LinkedHashSet<String>();
LocalDate arrivalStartDate = LocalDate.parse(providedArrivalStartDate);
LocalDate arrivalEndDate = LocalDate.parse(providedArrivalEndDate);
if (arrivalStartDate.isAfter(arrivalEndDate)) {
invalidDates.add(arrivalStartDate.toString());
}
if (arrivalEndDate.isBefore(arrivalStartDate)) {
invalidDates.add(arrivalEndDate.toString());
if (!providedArrivalStartDate.isEmpty() && !providedArrivalEndDate.isEmpty()) {
LocalDate arrivalStartDate = LocalDate.parse(providedArrivalStartDate);
LocalDate arrivalEndDate = LocalDate.parse(providedArrivalEndDate);
if (arrivalStartDate.isAfter(arrivalEndDate)) {
invalidDates.add(arrivalStartDate.toString());
}
if (arrivalEndDate.isBefore(arrivalStartDate)) {
invalidDates.add(arrivalEndDate.toString());
}
}
return invalidDates.stream()
.map("The expected departure date '%s' can not be past date"::formatted)
.map("The expected arrival dates '%s' are valid"::formatted)
.collect(Collectors.toSet());
}
);
Expand Down Expand Up @@ -459,8 +463,8 @@ private static <T, O> Supplier<T> delayedValue(Supplier<O> cspSupplier, Function

private static void generateScenarioRelatedChecks(List<JsonContentCheck> checks, Supplier<CarrierScenarioParameters> cspSupplier, Supplier<DynamicScenarioParameters> dspSupplier) {
checks.add(JsonAttribute.mustEqual(
"[Scenario] Verify that the correct 'serviceContractReference' is used",
"serviceContractReference",
"[Scenario] Verify that the correct 'carrierServiceName' is used",
"carrierServiceName",
delayedValue(cspSupplier, CarrierScenarioParameters::carrierServiceName)
));
checks.add(JsonAttribute.mustEqual(
Expand All @@ -471,7 +475,7 @@ private static void generateScenarioRelatedChecks(List<JsonContentCheck> checks,

checks.add(JsonAttribute.mustEqual(
"[Scenario] Verify that the correct 'carrierExportVoyageNumber' is used",
"contractQuotationReference",
"carrierExportVoyageNumber",
delayedValue(cspSupplier, CarrierScenarioParameters::carrierExportVoyageNumber)
));
checks.add(JsonAttribute.allIndividualMatchesMustBeValid(
Expand All @@ -483,7 +487,7 @@ private static void generateScenarioRelatedChecks(List<JsonContentCheck> checks,
var nonOperatingReeferNode = nodeToValidate.path("isNonOperatingReefer");
var issues = new LinkedHashSet<String>();
switch (scenario) {
case REEFER -> {
case REEFER, REEFER_TEMP_CHANGE -> {
if (!activeReeferNode.isObject()) {
issues.add("The scenario requires '%s' to have an active reefer".formatted(contextPath));
}
Expand Down Expand Up @@ -598,9 +602,9 @@ private static void generateScenarioRelatedChecks(List<JsonContentCheck> checks,
var charges = body.path("charges");
var issues = new LinkedHashSet<String>();
for(JsonNode charge : charges) {
var chargeAmount = charge.get("chargeAmount").asDouble();
if (BigDecimal.valueOf(chargeAmount).scale() > 2) {
issues.add("Charge amount %s is expected to have 2 decimal precious ".formatted(chargeAmount));
var currencyAmount = charge.get("currencyAmount").asDouble();
if (BigDecimal.valueOf(currencyAmount).scale() > 2) {
issues.add("Charge amount %s is expected to have 2 decimal precious ".formatted(currencyAmount));
}
}
return issues;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Segregation Group Code,Segregation Group Description
1,Acids
2,Ammonium Compounds
3,Bromates
4,Chlorates
5,Chlorites
6,Cyanides
7,Heavy metals and their salts
8,Hypochlorites
9,Lead and its compounds
10,Liquid halogenated hydrocarbons
11,Mercury and mercury compounds
12,Nitrites and their mixtures
13,Perchlorates
14,Permanganates
15,Powdered metals
16,Peroxides
17,Azides
18,Alkalis
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-DG",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -77,7 +78,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REEFER-TEMP",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -51,7 +52,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REEFER",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -51,7 +52,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REGULAR-2RE1C",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -59,7 +60,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REGULAR-2RE2C",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -71,7 +72,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "SD",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REGULAR-CHO-DEST",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -46,7 +47,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REGULAR-CHO-ORIG",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -46,7 +47,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REGULAR-NON-OP-REEFER",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -47,7 +48,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REGULAR-SHIPPER-OWNED",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -46,7 +47,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REGULAR",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down Expand Up @@ -46,7 +47,7 @@
}
]
},
"partyFunction": "BA",
"partyFunction": "CN",
"isToBeNotified": false
}
],
Expand Down

0 comments on commit 2f89dab

Please sign in to comment.