From 11b88c016f5565ddc3267d05cd86d261cd8dca2d Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Sat, 9 Dec 2023 00:17:16 +0100 Subject: [PATCH 1/2] Dt-718 changes for reefer --- .../booking/BookingScenarioListBuilder.java | 44 +++++++---- .../action/StateChangingBookingAction.java | 12 ++- ...C1_Shipper_SubmitBookingRequestAction.java | 10 ++- ...ShipperBookingContentConformanceCheck.java | 4 +- .../standards/booking/party/Shipper.java | 11 ++- .../booking-api-v20-reefer-request.json | 74 +++++++++++++++++++ 6 files changed, 128 insertions(+), 27 deletions(-) create mode 100644 booking/src/main/resources/standards/booking/messages/booking-api-v20-reefer-request.json diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/BookingScenarioListBuilder.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/BookingScenarioListBuilder.java index 2f87df2d..b4e441d0 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/BookingScenarioListBuilder.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/BookingScenarioListBuilder.java @@ -17,7 +17,6 @@ public class BookingScenarioListBuilder extends ScenarioListBuilder(); private static final ThreadLocal threadLocalCarrierPartyName = new ThreadLocal<>(); private static final ThreadLocal threadLocalShipperPartyName = new ThreadLocal<>(); - private static final String BOOKING_API = "api"; private static final String BOOKING_NOTIFICATIONS_API = "notification"; private static final String POST_SCHEMA_NAME = "postBooking"; @@ -26,6 +25,7 @@ public class BookingScenarioListBuilder extends ScenarioListBuilder 0) { // FIXME remove this // This is what's been implemented so far and should still work on PR. return carrier_SupplyScenarioParameters() - .then( - uc1_shipper_SubmitBookingRequest() + .thenEither( + uc1_shipper_SubmitBookingRequest(BOOKING_WITH_REEFER).then( + shipper_GetBooking(RECEIVED) + .then( + uc5_carrier_confirmBookingRequest() + .then( + shipper_GetBooking(CONFIRMED) + .then( + uc11_carrier_confirmBookingCompleted() + .then(shipper_GetBooking(COMPLETED)))))), + uc1_shipper_SubmitBookingRequest(null) .then( shipper_GetBooking(RECEIVED) .thenEither( @@ -149,7 +158,9 @@ private BookingScenarioListBuilder thenAllPathsFrom( uc4_carrier_rejectBookingRequest().thenAllPathsFrom(REJECTED), uc5_carrier_confirmBookingRequest().thenAllPathsFrom(CONFIRMED), uc12_shipper_cancelBooking().thenAllPathsFrom(CANCELLED))); - case START -> then(uc1_shipper_SubmitBookingRequest().thenAllPathsFrom(RECEIVED)); + case START -> thenEither( + uc1_shipper_SubmitBookingRequest(null).thenAllPathsFrom(RECEIVED), + uc1_shipper_SubmitBookingRequest(BOOKING_WITH_REEFER).thenHappyPathFrom(RECEIVED)); case PENDING_AMENDMENT -> then( shipper_GetBooking(bookingState) .thenEither( @@ -182,7 +193,7 @@ private BookingScenarioListBuilder thenHappyPathFrom(BookingState bookingState) uc3_shipper_submitUpdatedBookingRequest().thenHappyPathFrom(PENDING_UPDATE_CONFIRMATION)); case PENDING_UPDATE_CONFIRMATION, RECEIVED -> then( uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED)); - case START -> then(uc1_shipper_SubmitBookingRequest().thenHappyPathFrom(RECEIVED)); + case START -> then(uc1_shipper_SubmitBookingRequest(null).thenHappyPathFrom(RECEIVED)); }; } @@ -237,22 +248,25 @@ private static BookingScenarioListBuilder shipper_GetAmendedBooking404() { (BookingAction) previousAction)); } - private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest() { + private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest(String bookingVariant) { BookingComponentFactory componentFactory = threadLocalComponentFactory.get(); String carrierPartyName = threadLocalCarrierPartyName.get(); String shipperPartyName = threadLocalShipperPartyName.get(); return new BookingScenarioListBuilder( - previousAction -> - new UC1_Shipper_SubmitBookingRequestAction( - carrierPartyName, - shipperPartyName, - (BookingAction) previousAction, - componentFactory.getMessageSchemaValidator(BOOKING_API, POST_SCHEMA_NAME), - componentFactory.getMessageSchemaValidator(BOOKING_API, BOOKING_REF_STATUS_SCHEMA), - componentFactory.getMessageSchemaValidator( - BOOKING_NOTIFICATIONS_API, BOOKING_NOTIFICATION_SCHEMA_NAME))); + previousAction -> + new UC1_Shipper_SubmitBookingRequestAction( + carrierPartyName, + shipperPartyName, + (BookingAction) previousAction, + componentFactory.getMessageSchemaValidator(BOOKING_API, POST_SCHEMA_NAME), + componentFactory.getMessageSchemaValidator(BOOKING_API, BOOKING_REF_STATUS_SCHEMA), + componentFactory.getMessageSchemaValidator( + BOOKING_NOTIFICATIONS_API, BOOKING_NOTIFICATION_SCHEMA_NAME), + bookingVariant)); } + + private static BookingScenarioListBuilder carrierStateChange( CarrierNotificationUseCase constructor) { BookingComponentFactory componentFactory = threadLocalComponentFactory.get(); diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/StateChangingBookingAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/StateChangingBookingAction.java index 74089522..bc94f18c 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/StateChangingBookingAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/StateChangingBookingAction.java @@ -3,8 +3,18 @@ import org.dcsa.conformance.core.traffic.ConformanceExchange; public abstract class StateChangingBookingAction extends BookingAction { - public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction, String actionTitle, int expectedStatus) { + + protected final String bookingVariant; + public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction, + String actionTitle, int expectedStatus) { + super(sourcePartyName, targetPartyName, previousAction, actionTitle, expectedStatus); + bookingVariant = null; + } + + public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction, + String actionTitle, int expectedStatus, String bookingVariant) { super(sourcePartyName, targetPartyName, previousAction, actionTitle, expectedStatus); + this.bookingVariant = bookingVariant; } @Override diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC1_Shipper_SubmitBookingRequestAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC1_Shipper_SubmitBookingRequestAction.java index 54247eae..122ae28b 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC1_Shipper_SubmitBookingRequestAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC1_Shipper_SubmitBookingRequestAction.java @@ -2,6 +2,8 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import java.util.stream.Stream; + +import com.fasterxml.jackson.databind.node.TextNode; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.dcsa.conformance.core.check.*; @@ -25,8 +27,9 @@ public UC1_Shipper_SubmitBookingRequestAction( BookingAction previousAction, JsonSchemaValidator requestSchemaValidator, JsonSchemaValidator responseSchemaValidator, - JsonSchemaValidator notificationSchemaValidator) { - super(shipperPartyName, carrierPartyName, previousAction, "UC1", 201); + JsonSchemaValidator notificationSchemaValidator, + String bookingVariant) { + super(shipperPartyName, carrierPartyName, previousAction, "UC1(%s)".formatted( bookingVariant!= null? bookingVariant : "normal"), 201,bookingVariant); this.requestSchemaValidator = requestSchemaValidator; this.responseSchemaValidator = responseSchemaValidator; this.notificationSchemaValidator = notificationSchemaValidator; @@ -34,13 +37,14 @@ public UC1_Shipper_SubmitBookingRequestAction( @Override public String getHumanReadablePrompt() { - return ("UC1: Submit a booking request using the following parameters:"); + return ("UC1: Submit a booking %s request using the following parameters:".formatted( bookingVariant != null? bookingVariant : "normal")); } @Override public ObjectNode asJsonNode() { ObjectNode jsonNode = super.asJsonNode(); jsonNode.set("csp", getCspSupplier().get().toJson()); + jsonNode.set("bookingVariant", new TextNode(bookingVariant)); return jsonNode; } diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/ShipperBookingContentConformanceCheck.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/ShipperBookingContentConformanceCheck.java index 2d7c650b..6524ad48 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/ShipperBookingContentConformanceCheck.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/ShipperBookingContentConformanceCheck.java @@ -58,8 +58,8 @@ protected Set reeferChecks(JsonNode payload) { "the ISOEquipmentCode implies that the container is a reefer container" ); if (node != null && node.isBoolean()) { - var isNOR = node.asBoolean(); - if (isNOR) { + var isNOR = node.booleanValue(); + if (!isNOR) { fieldRequired( requestedEquipment, ACTIVE_REEFER_SETTINGS_FIELD, diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Shipper.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Shipper.java index 9abf2ee4..52dcc8f5 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Shipper.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Shipper.java @@ -23,6 +23,7 @@ public class Shipper extends ConformanceParty { private static final String SERVICE_CONTRACT_REF = "serviceContractReference"; private static final String SERVICE_REF_PUT = "serviceRefPut"; + private static final String FILE_SUFFIX_REEFER = "-reefer"; public Shipper( String apiVersion, PartyConfiguration partyConfiguration, @@ -85,7 +86,6 @@ private void sendBookingRequest(JsonNode actionPrompt) { CarrierScenarioParameters carrierScenarioParameters = CarrierScenarioParameters.fromJson(actionPrompt.get("csp")); - JsonNode jsonRequestBody = replaceBookingPlaceHolders(actionPrompt); asyncCounterpartPost( @@ -111,10 +111,11 @@ private JsonNode replaceBookingPlaceHolders(JsonNode actionPrompt) { CarrierScenarioParameters carrierScenarioParameters = CarrierScenarioParameters.fromJson(actionPrompt.get("csp")); + String bookingVariant = actionPrompt.get("bookingVariant").asText(); - JsonNode jsonRequestBody = - JsonToolkit.templateFileToJsonNode( - "/standards/booking/messages/booking-api-v20-request.json", + String fileSuffix = bookingVariant.equals("reefer") ? FILE_SUFFIX_REEFER: ""; + return JsonToolkit.templateFileToJsonNode( + "/standards/booking/messages/booking-api-v20%s-request.json".formatted(fileSuffix), Map.ofEntries( Map.entry( "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER", @@ -131,8 +132,6 @@ private JsonNode replaceBookingPlaceHolders(JsonNode actionPrompt) { "POL_UNLOCATION_CODE_PLACEHOLDER", carrierScenarioParameters.polUNLocationCode()), Map.entry( "POD_UNLOCATION_CODE_PLACEHOLDER", carrierScenarioParameters.podUNLocationCode()) )); - - return jsonRequestBody; } private void sendCancelEntireBooking(JsonNode actionPrompt) { diff --git a/booking/src/main/resources/standards/booking/messages/booking-api-v20-reefer-request.json b/booking/src/main/resources/standards/booking/messages/booking-api-v20-reefer-request.json new file mode 100644 index 00000000..d567d0ed --- /dev/null +++ b/booking/src/main/resources/standards/booking/messages/booking-api-v20-reefer-request.json @@ -0,0 +1,74 @@ +{ + "receiptTypeAtOrigin": "CY", + "deliveryTypeAtDestination": "CY", + "cargoMovementTypeAtOrigin": "FCL", + "cargoMovementTypeAtDestination": "FCL", + "contractQuotationReference": "CONTRACT_QUOTATION_REFERENCE_PLACEHOLDER", + "carrierExportVoyageNumber": "CARRIER_EXPORT_VOYAGE_NUMBER_PLACEHOLDER", + "carrierServiceName": "CARRIER_SERVICE_NAME_PLACEHOLDER", + "isPartialLoadAllowed": false, + "isExportDeclarationRequired": false, + "isImportLicenseRequired": false, + "communicationChannelCode": "AO", + "isEquipmentSubstitutionAllowed": true, + "requestedEquipments": [ + { + "ISOEquipmentCode": "22RT", + "units": 1, + "isShipperOwned": false, + "commodities": [ + { + "HSCodes": ["COMMODITY_HS_CODE"], + "commodityType": "COMMODITY_TYPE_PLACEHOLDER", + "cargoGrossWeight": 323.32, + "cargoGrossWeightUnit": "KGM" + } + ], + "isNonOperatingReefer": false, + "activeReeferSettings": { + "temperatureSetpoint": -18, + "temperatureUnit": "CEL" + } + } + ], + "documentParties": [ + { + "party": { + "partyName": "DCSA Conformance Toolkit", + "address": { + "name": "Mustermann", + "street": "Strawinskylaan", + "streetNumber": "4117", + "floor": "6", + "postCode": "1077 ZX", + "city": "Amsterdam", + "country": "Netherlands" + }, + "partyContactDetails": [ + { + "name": "Henrik", + "phone": "+31611444666" + } + ] + }, + "partyFunction": "BA", + "isToBeNotified": false + } + ], + "shipmentLocations": [ + { + "location": { + "locationType": "UNLO", + "UNLocationCode": "POL_UNLOCATION_CODE_PLACEHOLDER" + }, + "locationTypeCode": "POL" + }, + { + "location": { + "locationType": "UNLO", + "UNLocationCode": "POD_UNLOCATION_CODE_PLACEHOLDER" + }, + "locationTypeCode": "POD" + } + ] +} From ddecf5f189d485292a62f4b31bc302cf3a3e6c8b Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Mon, 11 Dec 2023 10:46:57 +0100 Subject: [PATCH 2/2] Dt-740 Enum usage for Booking variant. --- .../booking/BookingScenarioListBuilder.java | 16 ++++++++-------- .../action/StateChangingBookingAction.java | 7 ++++--- .../UC1_Shipper_SubmitBookingRequestAction.java | 9 +++++---- .../standards/booking/party/BookingVariant.java | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingVariant.java diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/BookingScenarioListBuilder.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/BookingScenarioListBuilder.java index b4e441d0..f31e8f4a 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/BookingScenarioListBuilder.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/BookingScenarioListBuilder.java @@ -9,6 +9,7 @@ import org.dcsa.conformance.core.scenario.ScenarioListBuilder; import org.dcsa.conformance.standards.booking.action.*; import org.dcsa.conformance.standards.booking.party.BookingState; +import org.dcsa.conformance.standards.booking.party.BookingVariant; @Slf4j public class BookingScenarioListBuilder extends ScenarioListBuilder { @@ -25,7 +26,6 @@ public class BookingScenarioListBuilder extends ScenarioListBuilder thenEither( - uc1_shipper_SubmitBookingRequest(null).thenAllPathsFrom(RECEIVED), - uc1_shipper_SubmitBookingRequest(BOOKING_WITH_REEFER).thenHappyPathFrom(RECEIVED)); + uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR).thenAllPathsFrom(RECEIVED), + uc1_shipper_SubmitBookingRequest(BookingVariant.REEFER).thenHappyPathFrom(RECEIVED)); case PENDING_AMENDMENT -> then( shipper_GetBooking(bookingState) .thenEither( @@ -193,7 +193,7 @@ private BookingScenarioListBuilder thenHappyPathFrom(BookingState bookingState) uc3_shipper_submitUpdatedBookingRequest().thenHappyPathFrom(PENDING_UPDATE_CONFIRMATION)); case PENDING_UPDATE_CONFIRMATION, RECEIVED -> then( uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED)); - case START -> then(uc1_shipper_SubmitBookingRequest(null).thenHappyPathFrom(RECEIVED)); + case START -> then(uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR).thenHappyPathFrom(RECEIVED)); }; } @@ -248,7 +248,7 @@ private static BookingScenarioListBuilder shipper_GetAmendedBooking404() { (BookingAction) previousAction)); } - private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest(String bookingVariant) { + private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest(BookingVariant variant) { BookingComponentFactory componentFactory = threadLocalComponentFactory.get(); String carrierPartyName = threadLocalCarrierPartyName.get(); String shipperPartyName = threadLocalShipperPartyName.get(); @@ -262,7 +262,7 @@ private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest(Strin componentFactory.getMessageSchemaValidator(BOOKING_API, BOOKING_REF_STATUS_SCHEMA), componentFactory.getMessageSchemaValidator( BOOKING_NOTIFICATIONS_API, BOOKING_NOTIFICATION_SCHEMA_NAME), - bookingVariant)); + variant)); } diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/StateChangingBookingAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/StateChangingBookingAction.java index bc94f18c..de1107dc 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/StateChangingBookingAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/StateChangingBookingAction.java @@ -1,18 +1,19 @@ package org.dcsa.conformance.standards.booking.action; import org.dcsa.conformance.core.traffic.ConformanceExchange; +import org.dcsa.conformance.standards.booking.party.BookingVariant; public abstract class StateChangingBookingAction extends BookingAction { - protected final String bookingVariant; + protected final BookingVariant bookingVariant; public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction, String actionTitle, int expectedStatus) { super(sourcePartyName, targetPartyName, previousAction, actionTitle, expectedStatus); - bookingVariant = null; + bookingVariant = BookingVariant.REGULAR; } public StateChangingBookingAction(String sourcePartyName, String targetPartyName, BookingAction previousAction, - String actionTitle, int expectedStatus, String bookingVariant) { + String actionTitle, int expectedStatus, BookingVariant bookingVariant) { super(sourcePartyName, targetPartyName, previousAction, actionTitle, expectedStatus); this.bookingVariant = bookingVariant; } diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC1_Shipper_SubmitBookingRequestAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC1_Shipper_SubmitBookingRequestAction.java index 122ae28b..bc62077b 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC1_Shipper_SubmitBookingRequestAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC1_Shipper_SubmitBookingRequestAction.java @@ -13,6 +13,7 @@ import org.dcsa.conformance.standards.booking.checks.ShipperBookingContentConformanceCheck; import org.dcsa.conformance.standards.booking.party.BookingRole; import org.dcsa.conformance.standards.booking.party.BookingState; +import org.dcsa.conformance.standards.booking.party.BookingVariant; @Getter @Slf4j @@ -28,8 +29,8 @@ public UC1_Shipper_SubmitBookingRequestAction( JsonSchemaValidator requestSchemaValidator, JsonSchemaValidator responseSchemaValidator, JsonSchemaValidator notificationSchemaValidator, - String bookingVariant) { - super(shipperPartyName, carrierPartyName, previousAction, "UC1(%s)".formatted( bookingVariant!= null? bookingVariant : "normal"), 201,bookingVariant); + BookingVariant bookingVariant) { + super(shipperPartyName, carrierPartyName, previousAction, "UC1(%s)".formatted( bookingVariant.getValue()), 201,bookingVariant); this.requestSchemaValidator = requestSchemaValidator; this.responseSchemaValidator = responseSchemaValidator; this.notificationSchemaValidator = notificationSchemaValidator; @@ -37,14 +38,14 @@ public UC1_Shipper_SubmitBookingRequestAction( @Override public String getHumanReadablePrompt() { - return ("UC1: Submit a booking %s request using the following parameters:".formatted( bookingVariant != null? bookingVariant : "normal")); + return ("UC1: Submit a booking %s request using the following parameters:".formatted(bookingVariant.getValue())); } @Override public ObjectNode asJsonNode() { ObjectNode jsonNode = super.asJsonNode(); jsonNode.set("csp", getCspSupplier().get().toJson()); - jsonNode.set("bookingVariant", new TextNode(bookingVariant)); + jsonNode.set("bookingVariant", new TextNode(bookingVariant.getValue())); return jsonNode; } diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingVariant.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingVariant.java new file mode 100644 index 00000000..db14ee42 --- /dev/null +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingVariant.java @@ -0,0 +1,17 @@ +package org.dcsa.conformance.standards.booking.party; + +import lombok.Getter; + +@Getter +public enum BookingVariant { + REGULAR("Regular"), + REEFER("Reefer"), + DG("Dangerous Goods"); + + private final String value; + + BookingVariant(String value) { + this.value = value; + } + +}