Skip to content

Commit

Permalink
DT-786 addressed the review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
preetamnpr committed Mar 4, 2024
1 parent 2f89dab commit c8c58c5
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public String getHumanReadablePrompt() {
@Override
public JsonNode getJsonForHumanReadablePrompt() {
var csp = switch (scenarioType) {
case REGULAR, REGULAR_SHIPPER_OWNED -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR, REGULAR_SHIPPER_OWNED -> new CarrierScenarioParameters( "SCR-1234-REGULAR",
"Example Carrier Service",
"402E",
"service Name",
"640510",
Expand All @@ -69,7 +70,8 @@ public JsonNode getJsonForHumanReadablePrompt() {
null,
"DKAAR",
"DEBRV");
case REGULAR_2RE1C, REGULAR_2RE2C -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR_2RE1C, REGULAR_2RE2C -> new CarrierScenarioParameters( "SCR-1234-REGULAR-2REC",
"Example Carrier Service",
"402E",
"service Name",
"630260",
Expand All @@ -78,7 +80,8 @@ public JsonNode getJsonForHumanReadablePrompt() {
"Kitchen pots and pans",
"DKAAR",
"DEBRV");
case REGULAR_CHO_DEST -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR_CHO_DEST -> new CarrierScenarioParameters("SCR-1234-REGULAR-CHO-DEST",
"Example Carrier Service",
"402E",
"service Name",
"640510",
Expand All @@ -87,7 +90,8 @@ public JsonNode getJsonForHumanReadablePrompt() {
null,
"DKAAR",
"USGBO");
case REGULAR_CHO_ORIG -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR_CHO_ORIG -> new CarrierScenarioParameters("SCR-1234-REGULAR-CHO-ORIG",
"Example Carrier Service",
"402E",
"service Name",
"640510",
Expand All @@ -96,7 +100,8 @@ public JsonNode getJsonForHumanReadablePrompt() {
null,
"DKAAR",
"DKAAR");
case REGULAR_NON_OPERATING_REEFER -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR_NON_OPERATING_REEFER -> new CarrierScenarioParameters("SCR-1234-NON-OPERATING-REEFER",
"Example Carrier Service",
"402E",
"service Name",
"220291",
Expand All @@ -105,7 +110,8 @@ public JsonNode getJsonForHumanReadablePrompt() {
null,
"DKAAR",
"DEBRV");
case REEFER, REEFER_TEMP_CHANGE -> new CarrierScenarioParameters("Example Carrier Service",
case REEFER, REEFER_TEMP_CHANGE -> new CarrierScenarioParameters( "SCR-1234-REEFER",
"Example Carrier Service",
"402E",
"service Name",
"04052090",
Expand All @@ -114,7 +120,8 @@ public JsonNode getJsonForHumanReadablePrompt() {
null,
"DKAAR",
"DEBRV");
case DG -> new CarrierScenarioParameters("Example Carrier Service",
case DG -> new CarrierScenarioParameters("SCR-1234-DG",
"Example Carrier Service",
"403W",
"TA1",
"293499",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.booking.checks.BookingChecks;
import org.dcsa.conformance.standards.booking.checks.CarrierBookingRefStatusPayloadResponseConformanceCheck;
import org.dcsa.conformance.standards.booking.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;
Expand Down Expand Up @@ -84,7 +85,8 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator));
responseSchemaValidator),
BookingChecks.requestContentChecks(getMatchedExchangeUuid(), getCspSupplier(), getDspSupplier()));
return Stream.concat(
Stream.concat(primaryExchangeChecks,
Stream.of(new CarrierBookingRefStatusPayloadResponseConformanceCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.dcsa.conformance.core.check.*;
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.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;

Expand Down Expand Up @@ -81,7 +82,8 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator));
responseSchemaValidator),
BookingChecks.requestContentChecks(getMatchedExchangeUuid(), getCspSupplier(), getDspSupplier()));
return Stream.concat(
primaryExchangeChecks,
getNotificationChecks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.booking.checks.BookingChecks;
import org.dcsa.conformance.standards.booking.checks.CarrierBookingRefStatusPayloadResponseConformanceCheck;
import org.dcsa.conformance.standards.booking.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;
Expand Down Expand Up @@ -84,7 +85,8 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator));
responseSchemaValidator),
BookingChecks.requestContentChecks(getMatchedExchangeUuid(), getCspSupplier(), getDspSupplier()));
return Stream.concat(
Stream.concat(primaryExchangeChecks,
Stream.of(new CarrierBookingRefStatusPayloadResponseConformanceCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.dcsa.conformance.core.check.*;
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.CarrierBookingRefStatusPayloadResponseConformanceCheck;
import org.dcsa.conformance.standards.booking.party.BookingRole;
import org.dcsa.conformance.standards.booking.party.BookingState;
Expand Down Expand Up @@ -82,7 +83,8 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
BookingRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator));
responseSchemaValidator),
BookingChecks.requestContentChecks(getMatchedExchangeUuid(), getCspSupplier(), getDspSupplier()));
return Stream.concat(
Stream.concat(primaryExchangeChecks,
Stream.of(new CarrierBookingRefStatusPayloadResponseConformanceCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,43 +294,6 @@ private static Consumer<MultiAttributeValidator> allDg(Consumer<MultiAttributeVa
}
);


private static final JsonContentCheck VALIDATE_DOCUMENT_PARTIES = JsonAttribute.customValidator(
"Validate documentParties",
body -> {
var issues = new LinkedHashSet<String>();
var documentParties = body.path("documentParties");
var isToOrder = body.path("isToOrder").asBoolean(false);
var partyFunctions = StreamSupport.stream(documentParties.spliterator(), false)
.map(p -> p.path("partyFunction"))
.filter(JsonNode::isTextual)
.map(n -> n.asText(""))
.collect(Collectors.toSet());

if (isToOrder) {
if (partyFunctions.contains("CN")) {
issues.add("The 'CN' party cannot be used when 'isToOrder' is true (use 'END' instead)");
}
} else {
if (!partyFunctions.contains("CN")) {
issues.add("The 'CN' party is mandatory when 'isToOrder' is false");
}
if (partyFunctions.contains("END")) {
issues.add("The 'END' party cannot be used when 'isToOrder' is false");
}
}

if (!partyFunctions.contains("SCO")) {
if (!body.path("serviceContractReference").isTextual()) {
issues.add("The 'SCO' party is mandatory when 'serviceContractReference' is absent");
}
if (!body.path("contractQuotationReference").isTextual()) {
issues.add("The 'SCO' party is mandatory when 'contractQuotationReference' is absent");
}
}
return issues;
});

private static final Consumer<MultiAttributeValidator> ALL_AMF = (mav) -> mav.submitAllMatching("advanceManifestFilings.*");

private static final JsonContentCheck ADVANCED_MANIFEST_FILING_CODES_UNIQUE = JsonAttribute.allIndividualMatchesMustBeValid(
Expand Down Expand Up @@ -461,23 +424,44 @@ 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(
checks.add(JsonAttribute.customValidator(
"[Scenario] Verify that the correct 'carrierServiceName' is used",
"carrierServiceName",
delayedValue(cspSupplier, CarrierScenarioParameters::carrierServiceName)
(body) -> {
var carrierServiceName = body.path("carrierServiceName");
var issues = new LinkedHashSet<String>();
if(carrierServiceName != null) {
delayedValue(cspSupplier, CarrierScenarioParameters::carrierServiceName );
}
return issues;
}
));
checks.add(JsonAttribute.mustEqual(

checks.add(JsonAttribute.customValidator(
"[Scenario] Verify that the correct 'contractQuotationReference' is used",
"contractQuotationReference",
delayedValue(cspSupplier, CarrierScenarioParameters::contractQuotationReference)
(body) -> {
var contractQuotationReference = body.path("contractQuotationReference");
var issues = new LinkedHashSet<String>();
if(contractQuotationReference != null) {
delayedValue(cspSupplier, CarrierScenarioParameters::contractQuotationReference);
}
return issues;
}
));

checks.add(JsonAttribute.mustEqual(
checks.add(JsonAttribute.customValidator(
"[Scenario] Verify that the correct 'carrierExportVoyageNumber' is used",
"carrierExportVoyageNumber",
delayedValue(cspSupplier, CarrierScenarioParameters::carrierExportVoyageNumber)
(body) -> {
var carrierExportVoyageNumber = body.path("carrierExportVoyageNumber");
var issues = new LinkedHashSet<String>();
if(carrierExportVoyageNumber != null) {
delayedValue(cspSupplier, CarrierScenarioParameters::carrierExportVoyageNumber);
}
return issues;
}
));

checks.add(JsonAttribute.allIndividualMatchesMustBeValid(
"[Scenario] Validate the containers reefer settings",
mav-> mav.submitAllMatching("requestedEquipments.*"),
Expand Down Expand Up @@ -551,7 +535,6 @@ private static void generateScenarioRelatedChecks(List<JsonContentCheck> checks,
COND_CARRIER_VOYAGE_NUMBER,
TLR_CC_T_COMBINATION_VALIDATIONS,
DOCUMENT_PARTY_FUNCTIONS_MUST_BE_UNIQUE,
VALIDATE_DOCUMENT_PARTIES,
UNIVERSAL_SERVICE_REFERENCE,
JsonAttribute.allIndividualMatchesMustBeValid(
"DangerousGoods implies packagingCode or imoPackagingCode",
Expand Down Expand Up @@ -602,7 +585,7 @@ private static void generateScenarioRelatedChecks(List<JsonContentCheck> checks,
var charges = body.path("charges");
var issues = new LinkedHashSet<String>();
for(JsonNode charge : charges) {
var currencyAmount = charge.get("currencyAmount").asDouble();
var currencyAmount = charge.path("currencyAmount").asDouble();
if (BigDecimal.valueOf(currencyAmount).scale() > 2) {
issues.add("Charge amount %s is expected to have 2 decimal precious ".formatted(currencyAmount));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
log.info("Carrier.supplyScenarioParameters(%s)".formatted(actionPrompt.toPrettyString()));
var scenarioType = ScenarioType.valueOf(actionPrompt.required("scenarioType").asText());
CarrierScenarioParameters carrierScenarioParameters = switch (scenarioType) {
case REGULAR, REGULAR_SHIPPER_OWNED -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR, REGULAR_SHIPPER_OWNED -> new CarrierScenarioParameters("SCR-1234-REGULAR",
"Example Carrier Service",
"402E",
"Carrier Service %d".formatted(RANDOM.nextInt(999999)),
"640510",
Expand All @@ -113,7 +114,8 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
null,
"DKAAR",
"DEBRV");
case REGULAR_2RE1C, REGULAR_2RE2C -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR_2RE1C, REGULAR_2RE2C -> new CarrierScenarioParameters("SCR-1234-REGULAR-2REC",
"Example Carrier Service",
"402E",
"Carrier Service %d".formatted(RANDOM.nextInt(999999)),
"630260",
Expand All @@ -122,7 +124,8 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
"Kitchen pots and pans",
"DKAAR",
"DEBRV");
case REGULAR_CHO_DEST -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR_CHO_DEST -> new CarrierScenarioParameters("SCR-1234-REGULAR-CHO-DEST",
"Example Carrier Service",
"402E",
"Carrier Service %d".formatted(RANDOM.nextInt(999999)),
"640510",
Expand All @@ -131,7 +134,8 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
null,
"DKAAR",
"USGBO");
case REGULAR_CHO_ORIG -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR_CHO_ORIG -> new CarrierScenarioParameters("SCR-1234-REGULAR-CHO-ORIG",
"Example Carrier Service",
"402E",
"Carrier Service %d".formatted(RANDOM.nextInt(999999)),
"640510",
Expand All @@ -140,7 +144,8 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
null,
"DKAAR",
"DKAAR");
case REGULAR_NON_OPERATING_REEFER -> new CarrierScenarioParameters("Example Carrier Service",
case REGULAR_NON_OPERATING_REEFER -> new CarrierScenarioParameters("SCR-1234-NON-OPERATING-REEFER",
"Example Carrier Service",
"402E",
"Carrier Service %d".formatted(RANDOM.nextInt(999999)),
"220291",
Expand All @@ -149,7 +154,8 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
null,
"DKAAR",
"DEBRV");
case REEFER, REEFER_TEMP_CHANGE -> new CarrierScenarioParameters("Example Carrier Service",
case REEFER, REEFER_TEMP_CHANGE -> new CarrierScenarioParameters("SCR-1234-REEFER",
"Example Carrier Service",
"402E",
"Carrier Service %d".formatted(RANDOM.nextInt(999999)),
"04052090",
Expand All @@ -158,7 +164,8 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
null,
"DKAAR",
"DEBRV");
case DG -> new CarrierScenarioParameters("Example Carrier Service",
case DG -> new CarrierScenarioParameters("SCR-1234-DG",
"Example Carrier Service",
"403W",
"TA1",
"293499",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ private JsonNode replaceBookingPlaceHolders(JsonNode actionPrompt) {
return JsonToolkit.templateFileToJsonNode(
"/standards/booking/messages/"+ scenarioType.bookingTemplate(apiVersion),
Map.ofEntries(
Map.entry(
"SERVICE_CONTRACT_REFERENCE_PLACEHOLDER",
carrierScenarioParameters.serviceContractReference()),
Map.entry(
"CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
carrierScenarioParameters.contractQuotationReference()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

public record CarrierScenarioParameters(String contractQuotationReference,
public record CarrierScenarioParameters(
String serviceContractReference,
String contractQuotationReference,
String carrierExportVoyageNumber,
String carrierServiceName,
String hsCodes1,
Expand All @@ -17,6 +19,7 @@ public record CarrierScenarioParameters(String contractQuotationReference,
public ObjectNode toJson() {
return new ObjectMapper()
.createObjectNode()
.put("serviceContractReference", serviceContractReference())
.put("contractQuotationReference", contractQuotationReference())
.put("carrierExportVoyageNumber", carrierExportVoyageNumber())
.put("carrierServiceName", carrierServiceName())
Expand All @@ -32,6 +35,7 @@ public static CarrierScenarioParameters fromJson(JsonNode jsonNode) {
ObjectNode cspNode = (ObjectNode) jsonNode;

return new CarrierScenarioParameters(
cspNode.required("serviceContractReference").asText(),
cspNode.required("contractQuotationReference").asText(),
cspNode.required("carrierExportVoyageNumber").asText(),
cspNode.required("carrierServiceName").asText(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-DG",
"serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REEFER-TEMP",
"serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REEFER",
"serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"deliveryTypeAtDestination": "CY",
"cargoMovementTypeAtOrigin": "FCL",
"cargoMovementTypeAtDestination": "FCL",
"serviceContractReference": "SCR-1234-REGULAR-2RE1C",
"serviceContractReference": "SERVICE_CONTRACT_REFERENCE_PLACEHOLDER",
"contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER",
"carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER",
"carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER",
Expand Down
Loading

0 comments on commit c8c58c5

Please sign in to comment.