From 6838f00ee2083a24d3104615321d7cd2b1bfd732 Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Tue, 5 Dec 2023 18:18:03 +0100 Subject: [PATCH 01/10] Dt-740 first set changes --- .../booking/BookingScenarioListBuilder.java | 18 +++++++++--------- .../UC10_Carrier_DeclineBookingAction.java | 2 +- .../UC8_Carrier_ProcessAmendmentAction.java | 2 +- .../model/PersistableCarrierBooking.java | 10 +++++----- .../standards/booking/party/BookingState.java | 5 ++++- 5 files changed, 20 insertions(+), 17 deletions(-) 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..75d801cf 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 @@ -64,23 +64,23 @@ public static BookingScenarioListBuilder buildTree( .then (uc9_shipper_cancelBookingAmendment() .then(shipper_GetBooking( PENDING_AMENDMENT, - CANCELLED)))))), + AMENDMENT_CANCELLED)))))), uc7_shipper_submitBookingAmendment() .then( shipper_GetBooking(CONFIRMED, AMENDMENT_RECEIVED) .thenEither( uc8a_carrier_approveBookingAmendment() .then(shipper_GetBooking( - CONFIRMED, CONFIRMED)), + CONFIRMED, AMENDMENT_CONFIRMED)), uc8b_carrier_declineBookingAmendment() .then(shipper_GetBooking( - CONFIRMED, DECLINED)), + CONFIRMED, AMENDMENT_DECLINED)), uc9_shipper_cancelBookingAmendment() .then(shipper_GetBooking( - CONFIRMED, CANCELLED)), + CONFIRMED, AMENDMENT_CANCELLED)), uc10_carrier_declineBooking() .then(shipper_GetBooking( - DECLINED, DECLINED)) + DECLINED, AMENDMENT_DECLINED)) )), uc10_carrier_declineBooking() .then(shipper_GetBooking(DECLINED)), @@ -112,8 +112,8 @@ private BookingScenarioListBuilder thenAllPathsFrom(BookingState bookingState) { private BookingScenarioListBuilder thenAllPathsFrom( BookingState bookingState, BookingState originalBookingState) { return switch (bookingState) { - case CANCELLED, COMPLETED, DECLINED, REJECTED -> then(shipper_GetBooking(bookingState)); - case CONFIRMED -> then( + case CANCELLED, COMPLETED, DECLINED, REJECTED, AMENDMENT_DECLINED, AMENDMENT_CANCELLED -> then(shipper_GetBooking(bookingState)); + case CONFIRMED,AMENDMENT_CONFIRMED -> then( shipper_GetBooking(bookingState) .thenEither( uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED), @@ -172,8 +172,8 @@ private BookingScenarioListBuilder thenAllPathsFrom( private BookingScenarioListBuilder thenHappyPathFrom(BookingState bookingState) { return switch (bookingState) { - case CANCELLED, COMPLETED, DECLINED, REJECTED -> then(noAction()); - case CONFIRMED -> then(uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED)); + case CANCELLED, COMPLETED, DECLINED, AMENDMENT_DECLINED,AMENDMENT_CANCELLED, REJECTED -> then(noAction()); + case CONFIRMED, AMENDMENT_CONFIRMED -> then(uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED)); case PENDING_AMENDMENT -> then( uc7_shipper_submitBookingAmendment().thenHappyPathFrom(AMENDMENT_RECEIVED)); case AMENDMENT_RECEIVED -> then( diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC10_Carrier_DeclineBookingAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC10_Carrier_DeclineBookingAction.java index 56d8ac75..7e9c3956 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC10_Carrier_DeclineBookingAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC10_Carrier_DeclineBookingAction.java @@ -50,7 +50,7 @@ protected Stream createSubChecks() { new CarrierBookingNotificationDataPayloadRequestConformanceCheck( getMatchedExchangeUuid(), BookingState.DECLINED, - dsp.amendedBookingStatus() != null ? BookingState.DECLINED : null + dsp.amendedBookingStatus() != null ? BookingState.AMENDMENT_DECLINED : null ), new ApiHeaderCheck( BookingRole::isCarrier, diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC8_Carrier_ProcessAmendmentAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC8_Carrier_ProcessAmendmentAction.java index 9b7aea49..49cbf964 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC8_Carrier_ProcessAmendmentAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC8_Carrier_ProcessAmendmentAction.java @@ -60,7 +60,7 @@ protected Stream createSubChecks() { new CarrierBookingNotificationDataPayloadRequestConformanceCheck( getMatchedExchangeUuid(), acceptAmendment ? BookingState.CONFIRMED : bookingStatus, - acceptAmendment ? BookingState.CONFIRMED : BookingState.DECLINED + acceptAmendment ? BookingState.AMENDMENT_CONFIRMED : BookingState.AMENDMENT_DECLINED ), new ApiHeaderCheck( BookingRole::isCarrier, diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java index d1e8afb9..f9b8a0f8 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java @@ -105,7 +105,7 @@ public void performSimpleStatusChange(String reference, BookingState newState) { public void confirmBookingAmendment(String reference, String reason) { checkState(reference, getBookingState(), s -> s == AMENDMENT_RECEIVED); changeState(BOOKING_STATUS, CONFIRMED); - changeState(AMENDED_BOOKING_STATUS, CONFIRMED); + changeState(AMENDED_BOOKING_STATUS, AMENDMENT_CONFIRMED); mutateBookingAndAmendment(this::ensureConfirmedBookingHasCarrierFields); setReason(reason); } @@ -142,14 +142,14 @@ public void declineBooking(String reference, String reason) { checkState(reference, getBookingState(), prerequisites); changeState(BOOKING_STATUS, DECLINED); if (getAmendedBooking().isPresent()) { - changeState(AMENDED_BOOKING_STATUS, DECLINED); + changeState(AMENDED_BOOKING_STATUS, AMENDMENT_DECLINED); } setReason(reason); } public void declineBookingAmendment(String reference, String reason) { checkState(reference, getBookingState(), s -> s == AMENDMENT_RECEIVED); - changeState(AMENDED_BOOKING_STATUS, DECLINED); + changeState(AMENDED_BOOKING_STATUS, AMENDMENT_DECLINED); setReason(reason); } @@ -189,14 +189,14 @@ public void cancelEntireBooking(String bookingReference, String reason) { mutateBookingAndAmendment((bookingContent, isAmendedContent) -> { bookingContent.put("reason", cancelReason); if (isAmendedContent) { - bookingContent.put(AMENDED_BOOKING_STATUS, CANCELLED.wireName()); + bookingContent.put(AMENDED_BOOKING_STATUS, AMENDMENT_CANCELLED.wireName()); } }); } public void cancelBookingAmendment(String bookingReference, String reason) { checkState(bookingReference, getBookingState(), s -> s == AMENDMENT_RECEIVED); - changeState(AMENDED_BOOKING_STATUS, CANCELLED); + changeState(AMENDED_BOOKING_STATUS, AMENDMENT_CANCELLED); if (reason == null || reason.isBlank()) { reason = "Amendment cancelled by shipper (no reason given)"; } diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingState.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingState.java index fdc4825c..4967e0b7 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingState.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingState.java @@ -9,8 +9,11 @@ public enum BookingState { CANCELLED, CONFIRMED, PENDING_AMENDMENT, - AMENDMENT_RECEIVED, DECLINED, + AMENDMENT_RECEIVED, + AMENDMENT_CONFIRMED, + AMENDMENT_DECLINED, + AMENDMENT_CANCELLED, COMPLETED, ; From 0d9eb00cfd2d1ec7c11adb1468efd793fd7f010c Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:02:17 +0100 Subject: [PATCH 02/10] DT-716 --- .../checks/AbstractCarrierPayloadConformanceCheck.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/AbstractCarrierPayloadConformanceCheck.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/AbstractCarrierPayloadConformanceCheck.java index 8ac23e2c..e81efb13 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/AbstractCarrierPayloadConformanceCheck.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/AbstractCarrierPayloadConformanceCheck.java @@ -28,7 +28,9 @@ abstract class AbstractCarrierPayloadConformanceCheck extends PayloadContentConf protected static final Set REASON_STATES = Set.of( BookingState.DECLINED, BookingState.REJECTED, - BookingState.CANCELLED + BookingState.CANCELLED, + BookingState.AMENDMENT_CANCELLED, + BookingState.AMENDMENT_DECLINED ); protected static final Set BOOKING_STATES_WHERE_CBR_IS_OPTIONAL = Set.of( From 3f7c40ec729a41a32b1e2a625e95369183169d1d Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:53:22 +0100 Subject: [PATCH 03/10] Dt-740 --- .../booking/BookingScenarioListBuilder.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) 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 75d801cf..1fe51a13 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 @@ -112,12 +112,12 @@ private BookingScenarioListBuilder thenAllPathsFrom(BookingState bookingState) { private BookingScenarioListBuilder thenAllPathsFrom( BookingState bookingState, BookingState originalBookingState) { return switch (bookingState) { - case CANCELLED, COMPLETED, DECLINED, REJECTED, AMENDMENT_DECLINED, AMENDMENT_CANCELLED -> then(shipper_GetBooking(bookingState)); - case CONFIRMED,AMENDMENT_CONFIRMED -> then( + case CANCELLED, COMPLETED, DECLINED, REJECTED -> then(shipper_GetBooking(bookingState)); + case CONFIRMED -> then( shipper_GetBooking(bookingState) .thenEither( uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED), - uc6_carrier_requestBookingAmendment().thenAllPathsFrom(PENDING_AMENDMENT), + uc6_carrier_requestUpdateToConfirmedBooking().thenAllPathsFrom(PENDING_AMENDMENT), uc7_shipper_submitBookingAmendment() .thenAllPathsFrom(AMENDMENT_RECEIVED, CONFIRMED), uc10_carrier_declineBooking().thenAllPathsFrom(DECLINED), @@ -153,7 +153,7 @@ private BookingScenarioListBuilder thenAllPathsFrom( case PENDING_AMENDMENT -> then( shipper_GetBooking(bookingState) .thenEither( - uc6_carrier_requestBookingAmendment().thenHappyPathFrom(PENDING_AMENDMENT), + uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT), uc7_shipper_submitBookingAmendment() .thenAllPathsFrom(AMENDMENT_RECEIVED, PENDING_AMENDMENT), uc10_carrier_declineBooking().thenHappyPathFrom(DECLINED), @@ -161,18 +161,28 @@ private BookingScenarioListBuilder thenAllPathsFrom( case AMENDMENT_RECEIVED -> then( shipper_GetBooking(bookingState) .thenEither( - uc6_carrier_requestBookingAmendment().thenHappyPathFrom(PENDING_AMENDMENT), - uc8a_carrier_approveBookingAmendment().thenHappyPathFrom(CONFIRMED), - uc8b_carrier_declineBookingAmendment().thenHappyPathFrom(CONFIRMED), - uc9_shipper_cancelBookingAmendment().thenHappyPathFrom(originalBookingState), + uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT), + uc8a_carrier_approveBookingAmendment().thenAllPathsFrom(AMENDMENT_CONFIRMED,CONFIRMED), + uc8b_carrier_declineBookingAmendment().thenAllPathsFrom(AMENDMENT_DECLINED,CONFIRMED), + uc9_shipper_cancelBookingAmendment().thenAllPathsFrom(AMENDMENT_CANCELLED,CONFIRMED), uc10_carrier_declineBooking().thenHappyPathFrom(DECLINED), uc12_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); + case AMENDMENT_CANCELLED -> then( + shipper_GetBooking(originalBookingState) + .thenEither( + uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED), + uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT))); + case AMENDMENT_DECLINED, AMENDMENT_CONFIRMED -> then( + shipper_GetBooking(originalBookingState) + .then( + uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED) + )); }; } private BookingScenarioListBuilder thenHappyPathFrom(BookingState bookingState) { return switch (bookingState) { - case CANCELLED, COMPLETED, DECLINED, AMENDMENT_DECLINED,AMENDMENT_CANCELLED, REJECTED -> then(noAction()); + case CANCELLED, COMPLETED, DECLINED, AMENDMENT_DECLINED, AMENDMENT_CANCELLED, REJECTED -> then(noAction()); case CONFIRMED, AMENDMENT_CONFIRMED -> then(uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED)); case PENDING_AMENDMENT -> then( uc7_shipper_submitBookingAmendment().thenHappyPathFrom(AMENDMENT_RECEIVED)); @@ -300,10 +310,6 @@ private static BookingScenarioListBuilder uc6_carrier_requestUpdateToConfirmedBo return carrierStateChange(UC6_Carrier_RequestUpdateToConfirmedBookingAction::new); } - private static BookingScenarioListBuilder uc6_carrier_requestBookingAmendment() { - return tbdCarrierAction(); - } - private static BookingScenarioListBuilder uc7_shipper_submitBookingAmendment() { BookingComponentFactory componentFactory = threadLocalComponentFactory.get(); String carrierPartyName = threadLocalCarrierPartyName.get(); From 5c5827160e932da3b24ea5e9854feca37af86b76 Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:05:41 +0100 Subject: [PATCH 04/10] Dt-740 --- .../standards/booking/BookingScenarioListBuilder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 1fe51a13..4f2f9598 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 @@ -182,7 +182,7 @@ private BookingScenarioListBuilder thenAllPathsFrom( private BookingScenarioListBuilder thenHappyPathFrom(BookingState bookingState) { return switch (bookingState) { - case CANCELLED, COMPLETED, DECLINED, AMENDMENT_DECLINED, AMENDMENT_CANCELLED, REJECTED -> then(noAction()); + case CANCELLED, COMPLETED, DECLINED, REJECTED -> then(noAction()); case CONFIRMED, AMENDMENT_CONFIRMED -> then(uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED)); case PENDING_AMENDMENT -> then( uc7_shipper_submitBookingAmendment().thenHappyPathFrom(AMENDMENT_RECEIVED)); @@ -193,6 +193,8 @@ private BookingScenarioListBuilder thenHappyPathFrom(BookingState bookingState) case PENDING_UPDATE_CONFIRMATION, RECEIVED -> then( uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED)); case START -> then(uc1_shipper_SubmitBookingRequest().thenHappyPathFrom(RECEIVED)); + case AMENDMENT_DECLINED, AMENDMENT_CANCELLED -> throw new AssertionError( + "This happyPath from this state requires a context state"); }; } From ae5a6e489609e6ae7649c1ec1c9de577161ea572 Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Wed, 13 Dec 2023 12:39:41 +0100 Subject: [PATCH 05/10] DT-740 and DT-737 --- .../booking/BookingScenarioListBuilder.java | 110 ++++++++++-------- ...11_Shipper_CancelEntireBookingAction.java} | 8 +- ...arrier_ConfirmBookingCompletedAction.java} | 13 ++- ...per_SubmitUpdatedBookingRequestAction.java | 2 +- ...bstractCarrierPayloadConformanceCheck.java | 2 +- .../model/PersistableCarrierBooking.java | 33 +++--- .../standards/booking/party/BookingState.java | 2 +- .../standards/booking/party/Carrier.java | 20 +++- .../standards/booking/party/Shipper.java | 2 +- 9 files changed, 107 insertions(+), 85 deletions(-) rename booking/src/main/java/org/dcsa/conformance/standards/booking/action/{UC12_Shipper_CancelEntireBookingAction.java => UC11_Shipper_CancelEntireBookingAction.java} (95%) rename booking/src/main/java/org/dcsa/conformance/standards/booking/action/{UC11_Carrier_ConfirmBookingCompletedAction.java => UC12_Carrier_ConfirmBookingCompletedAction.java} (87%) 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 a567e442..db43de84 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 @@ -43,7 +43,7 @@ public static BookingScenarioListBuilder buildTree( .then( shipper_GetBooking(CONFIRMED) .then( - uc11_carrier_confirmBookingCompleted() + uc12_carrier_confirmBookingCompleted() .then(shipper_GetBooking(COMPLETED)))))), uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR) .then( @@ -57,9 +57,9 @@ public static BookingScenarioListBuilder buildTree( .then( shipper_GetBooking(CONFIRMED) .then( - uc11_carrier_confirmBookingCompleted() + uc12_carrier_confirmBookingCompleted() .then(shipper_GetBooking(COMPLETED)))), - uc11_carrier_confirmBookingCompleted() + uc12_carrier_confirmBookingCompleted() .then(shipper_GetBooking(COMPLETED)), uc6_carrier_requestUpdateToConfirmedBooking() .then( @@ -70,10 +70,19 @@ public static BookingScenarioListBuilder buildTree( shipper_GetBooking( PENDING_AMENDMENT, AMENDMENT_RECEIVED) - .then (uc9_shipper_cancelBookingAmendment() + .thenEither (uc9_shipper_cancelBookingAmendment() .then(shipper_GetBooking( PENDING_AMENDMENT, - AMENDMENT_CANCELLED)))))), + AMENDMENT_CANCELLED)), + uc8b_carrier_declineBookingAmendment().then( + shipper_GetBooking( + PENDING_AMENDMENT, AMENDMENT_DECLINED) + .then( + uc6_carrier_requestUpdateToConfirmedBooking() + .thenHappyPathFrom(PENDING_AMENDMENT) + ) + ) + )))), uc7_shipper_submitBookingAmendment() .then( shipper_GetBooking(CONFIRMED, AMENDMENT_RECEIVED) @@ -93,14 +102,14 @@ public static BookingScenarioListBuilder buildTree( )), uc10_carrier_declineBooking() .then(shipper_GetBooking(DECLINED)), - uc12_shipper_cancelBooking() + uc11_shipper_cancelBooking() .then(shipper_GetBooking(CANCELLED)))), uc4_carrier_rejectBookingRequest().then(shipper_GetBooking(REJECTED)), - uc12_shipper_cancelBooking().then(shipper_GetBooking(CANCELLED)), + uc11_shipper_cancelBooking().then(shipper_GetBooking(CANCELLED)), uc2_carrier_requestUpdateToBookingRequest() .then(shipper_GetBooking(PENDING_UPDATE)), uc3_shipper_submitUpdatedBookingRequest() - .then(shipper_GetBooking(PENDING_UPDATE_CONFIRMATION)), + .then(shipper_GetBooking(UPDATE_RECEIVED)), shipper_GetAmendedBooking404().then( uc5_carrier_confirmBookingRequest().then( shipper_GetAmendedBooking404().then(uc7_shipper_submitBookingAmendment() @@ -126,82 +135,85 @@ private BookingScenarioListBuilder thenAllPathsFrom( shipper_GetBooking(bookingState) .thenEither( uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED), - uc6_carrier_requestBookingAmendment().thenAllPathsFrom(PENDING_AMENDMENT), + uc6_carrier_requestUpdateToConfirmedBooking().thenAllPathsFrom(PENDING_AMENDMENT), uc7_shipper_submitBookingAmendment() .thenAllPathsFrom(AMENDMENT_RECEIVED, CONFIRMED), uc10_carrier_declineBooking().thenAllPathsFrom(DECLINED), - uc11_carrier_confirmBookingCompleted().thenAllPathsFrom(COMPLETED), - uc12_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); + uc12_carrier_confirmBookingCompleted().thenAllPathsFrom(COMPLETED), + uc11_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); case PENDING_UPDATE -> then( shipper_GetBooking(bookingState) .thenEither( uc2_carrier_requestUpdateToBookingRequest().thenHappyPathFrom(PENDING_UPDATE), uc3_shipper_submitUpdatedBookingRequest() - .thenHappyPathFrom(PENDING_UPDATE_CONFIRMATION), + .thenHappyPathFrom(UPDATE_RECEIVED), uc4_carrier_rejectBookingRequest().thenHappyPathFrom(REJECTED), - uc12_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); - case PENDING_UPDATE_CONFIRMATION -> then( + uc11_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); + case UPDATE_RECEIVED -> then( shipper_GetBooking(bookingState) .thenEither( uc2_carrier_requestUpdateToBookingRequest().thenHappyPathFrom(PENDING_UPDATE), uc3_shipper_submitUpdatedBookingRequest() - .thenHappyPathFrom(PENDING_UPDATE_CONFIRMATION), + .thenHappyPathFrom(UPDATE_RECEIVED), uc4_carrier_rejectBookingRequest().thenHappyPathFrom(REJECTED), uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED), - uc12_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); + uc11_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); case RECEIVED -> then( shipper_GetBooking(bookingState) .thenEither( uc2_carrier_requestUpdateToBookingRequest().thenAllPathsFrom(PENDING_UPDATE), uc3_shipper_submitUpdatedBookingRequest() - .thenAllPathsFrom(PENDING_UPDATE_CONFIRMATION), + .thenAllPathsFrom(UPDATE_RECEIVED), uc4_carrier_rejectBookingRequest().thenAllPathsFrom(REJECTED), uc5_carrier_confirmBookingRequest().thenAllPathsFrom(CONFIRMED), - uc12_shipper_cancelBooking().thenAllPathsFrom(CANCELLED))); - case START -> thenEither( - uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR).thenAllPathsFrom(RECEIVED), - uc1_shipper_SubmitBookingRequest(BookingVariant.REEFER).thenHappyPathFrom(RECEIVED)); + uc11_shipper_cancelBooking().thenAllPathsFrom(CANCELLED))); + case START -> then(uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR).thenAllPathsFrom(RECEIVED)); case PENDING_AMENDMENT -> then( shipper_GetBooking(bookingState) .thenEither( - uc6_carrier_requestBookingAmendment().thenHappyPathFrom(PENDING_AMENDMENT), + uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT), uc7_shipper_submitBookingAmendment() .thenAllPathsFrom(AMENDMENT_RECEIVED, PENDING_AMENDMENT), uc10_carrier_declineBooking().thenHappyPathFrom(DECLINED), - uc12_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); + uc11_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); case AMENDMENT_RECEIVED -> then( - shipper_GetBooking(bookingState) - .thenEither( - uc6_carrier_requestBookingAmendment().thenHappyPathFrom(PENDING_AMENDMENT), - uc8a_carrier_approveBookingAmendment().thenAllPathsFrom(AMENDMENT_CONFIRMED,CONFIRMED), - uc8b_carrier_declineBookingAmendment().thenAllPathsFrom(AMENDMENT_DECLINED,CONFIRMED), - uc9_shipper_cancelBookingAmendment().thenAllPathsFrom(AMENDMENT_CANCELLED,CONFIRMED), - uc10_carrier_declineBooking().thenHappyPathFrom(DECLINED), - uc12_shipper_cancelBooking().thenHappyPathFrom(CANCELLED))); - case AMENDMENT_CANCELLED -> then( - shipper_GetBooking(originalBookingState) + shipper_GetBooking(originalBookingState,AMENDMENT_RECEIVED) + .thenEither( + uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT), + uc8a_carrier_approveBookingAmendment().thenAllPathsFrom(AMENDMENT_CONFIRMED,originalBookingState), + uc8b_carrier_declineBookingAmendment().thenAllPathsFrom(AMENDMENT_DECLINED,originalBookingState), + uc9_shipper_cancelBookingAmendment().thenAllPathsFrom(AMENDMENT_CANCELLED,originalBookingState), + uc10_carrier_declineBooking().thenHappyPathFrom(DECLINED) + ) + ); + case AMENDMENT_CONFIRMED -> then( + shipper_GetBooking(CONFIRMED,bookingState) .thenEither( - uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED), - uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT))); - case AMENDMENT_DECLINED, AMENDMENT_CONFIRMED -> then( - shipper_GetBooking(originalBookingState) - .then( - uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED) - )); + uc12_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED), + uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT) + ) + ); + case AMENDMENT_CANCELLED, AMENDMENT_DECLINED -> then( + shipper_GetBooking(originalBookingState,bookingState) + .thenEither( + uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT) + ) + ); }; } private BookingScenarioListBuilder thenHappyPathFrom(BookingState bookingState) { return switch (bookingState) { case CANCELLED, COMPLETED, DECLINED, REJECTED -> then(noAction()); - case CONFIRMED, AMENDMENT_CONFIRMED -> then(uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED)); + case CONFIRMED, AMENDMENT_CONFIRMED -> then( + uc12_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED)); case PENDING_AMENDMENT -> then( uc7_shipper_submitBookingAmendment().thenHappyPathFrom(AMENDMENT_RECEIVED)); case AMENDMENT_RECEIVED -> then( uc8a_carrier_approveBookingAmendment().thenHappyPathFrom(CONFIRMED)); case PENDING_UPDATE -> then( - uc3_shipper_submitUpdatedBookingRequest().thenHappyPathFrom(PENDING_UPDATE_CONFIRMATION)); - case PENDING_UPDATE_CONFIRMATION, RECEIVED -> then( + uc3_shipper_submitUpdatedBookingRequest().thenHappyPathFrom(UPDATE_RECEIVED)); + case UPDATE_RECEIVED, RECEIVED -> then( uc5_carrier_confirmBookingRequest().thenHappyPathFrom(CONFIRMED)); case START -> then(uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR).thenHappyPathFrom(RECEIVED)); case AMENDMENT_DECLINED, AMENDMENT_CANCELLED -> throw new AssertionError( @@ -324,10 +336,6 @@ private static BookingScenarioListBuilder uc6_carrier_requestUpdateToConfirmedBo return carrierStateChange(UC6_Carrier_RequestUpdateToConfirmedBookingAction::new); } - private static BookingScenarioListBuilder uc6_carrier_requestBookingAmendment() { - return tbdCarrierAction(); - } - private static BookingScenarioListBuilder uc7_shipper_submitBookingAmendment() { BookingComponentFactory componentFactory = threadLocalComponentFactory.get(); String carrierPartyName = threadLocalCarrierPartyName.get(); @@ -373,17 +381,17 @@ private static BookingScenarioListBuilder uc10_carrier_declineBooking() { return carrierStateChange(UC10_Carrier_DeclineBookingAction::new); } - private static BookingScenarioListBuilder uc11_carrier_confirmBookingCompleted() { - return carrierStateChange(UC11_Carrier_ConfirmBookingCompletedAction::new); + private static BookingScenarioListBuilder uc12_carrier_confirmBookingCompleted() { + return carrierStateChange(UC12_Carrier_ConfirmBookingCompletedAction::new); } - private static BookingScenarioListBuilder uc12_shipper_cancelBooking() { + private static BookingScenarioListBuilder uc11_shipper_cancelBooking() { BookingComponentFactory componentFactory = threadLocalComponentFactory.get(); String carrierPartyName = threadLocalCarrierPartyName.get(); String shipperPartyName = threadLocalShipperPartyName.get(); return new BookingScenarioListBuilder( previousAction -> - new UC12_Shipper_CancelEntireBookingAction( + new UC11_Shipper_CancelEntireBookingAction( carrierPartyName, shipperPartyName, (BookingAction) previousAction, diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Shipper_CancelEntireBookingAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC11_Shipper_CancelEntireBookingAction.java similarity index 95% rename from booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Shipper_CancelEntireBookingAction.java rename to booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC11_Shipper_CancelEntireBookingAction.java index 148ae396..19d33fc2 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Shipper_CancelEntireBookingAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC11_Shipper_CancelEntireBookingAction.java @@ -14,24 +14,24 @@ @Getter @Slf4j -public class UC12_Shipper_CancelEntireBookingAction extends StateChangingBookingAction { +public class UC11_Shipper_CancelEntireBookingAction extends StateChangingBookingAction { private final JsonSchemaValidator requestSchemaValidator; private final JsonSchemaValidator responseSchemaValidator; - public UC12_Shipper_CancelEntireBookingAction( + public UC11_Shipper_CancelEntireBookingAction( String carrierPartyName, String shipperPartyName, BookingAction previousAction, JsonSchemaValidator requestSchemaValidator, JsonSchemaValidator responseSchemaValidator) { - super(shipperPartyName, carrierPartyName, previousAction, "UC12", 200); + super(shipperPartyName, carrierPartyName, previousAction, "UC11", 200); this.requestSchemaValidator = requestSchemaValidator; this.responseSchemaValidator = responseSchemaValidator; } @Override public String getHumanReadablePrompt() { - return ("UC12: Cancel an entire booking"); + return ("UC11: Cancel an entire booking"); } @Override diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC11_Carrier_ConfirmBookingCompletedAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Carrier_ConfirmBookingCompletedAction.java similarity index 87% rename from booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC11_Carrier_ConfirmBookingCompletedAction.java rename to booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Carrier_ConfirmBookingCompletedAction.java index 263acc57..c76d980e 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC11_Carrier_ConfirmBookingCompletedAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Carrier_ConfirmBookingCompletedAction.java @@ -6,26 +6,25 @@ import org.dcsa.conformance.core.check.*; import org.dcsa.conformance.core.traffic.HttpMessageType; import org.dcsa.conformance.standards.booking.checks.CarrierBookingNotificationDataPayloadRequestConformanceCheck; -import org.dcsa.conformance.standards.booking.checks.CarrierBookingRefStatusPayloadResponseConformanceCheck; import org.dcsa.conformance.standards.booking.party.BookingRole; import org.dcsa.conformance.standards.booking.party.BookingState; @Getter -public class UC11_Carrier_ConfirmBookingCompletedAction extends StateChangingBookingAction { +public class UC12_Carrier_ConfirmBookingCompletedAction extends StateChangingBookingAction { private final JsonSchemaValidator requestSchemaValidator; - public UC11_Carrier_ConfirmBookingCompletedAction( + public UC12_Carrier_ConfirmBookingCompletedAction( String carrierPartyName, String shipperPartyName, BookingAction previousAction, JsonSchemaValidator requestSchemaValidator) { - super(carrierPartyName, shipperPartyName, previousAction, "UC11", 204); + super(carrierPartyName, shipperPartyName, previousAction, "UC12", 204); this.requestSchemaValidator = requestSchemaValidator; } @Override public String getHumanReadablePrompt() { - return ("UC11: Complete the booking request with CBR %s" + return ("UC12: Complete the booking request with CBR %s" .formatted(getDspSupplier().get().carrierBookingReference())); } @@ -42,6 +41,7 @@ public ConformanceCheck createCheck(String expectedApiVersion) { return new ConformanceCheck(getActionTitle()) { @Override protected Stream createSubChecks() { + var dsp = getDspSupplier().get(); return Stream.of( new UrlPathCheck( BookingRole::isCarrier, getMatchedExchangeUuid(), "/v2/booking-notifications"), @@ -49,7 +49,8 @@ protected Stream createSubChecks() { BookingRole::isShipper, getMatchedExchangeUuid(), expectedStatus), new CarrierBookingNotificationDataPayloadRequestConformanceCheck( getMatchedExchangeUuid(), - BookingState.COMPLETED + BookingState.COMPLETED, + dsp.amendedBookingStatus() != null ? BookingState.AMENDMENT_CONFIRMED : null ), new ApiHeaderCheck( BookingRole::isCarrier, diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC3_Shipper_SubmitUpdatedBookingRequestAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC3_Shipper_SubmitUpdatedBookingRequestAction.java index ccec6548..43d26861 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC3_Shipper_SubmitUpdatedBookingRequestAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC3_Shipper_SubmitUpdatedBookingRequestAction.java @@ -87,7 +87,7 @@ protected Stream createSubChecks() { getNotificationChecks( expectedApiVersion, notificationSchemaValidator, - BookingState.PENDING_UPDATE_CONFIRMATION, + BookingState.UPDATE_RECEIVED, null)); } }; diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/AbstractCarrierPayloadConformanceCheck.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/AbstractCarrierPayloadConformanceCheck.java index e81efb13..3b2893e8 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/AbstractCarrierPayloadConformanceCheck.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/checks/AbstractCarrierPayloadConformanceCheck.java @@ -37,7 +37,7 @@ abstract class AbstractCarrierPayloadConformanceCheck extends PayloadContentConf BookingState.RECEIVED, BookingState.REJECTED, BookingState.PENDING_UPDATE, - BookingState.PENDING_UPDATE_CONFIRMATION, + BookingState.UPDATE_RECEIVED, /* CANCELLED depends on whether cancel happens before CONFIRMED, but the logic does not track prior * states. Therefore, we just assume it is optional in CANCELLED here. */ diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java index b8cf215c..0eaa9a5d 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java @@ -21,10 +21,10 @@ public class PersistableCarrierBooking { private static final Map> PREREQUISITE_STATE_FOR_TARGET_STATE = Map.ofEntries( - Map.entry(CONFIRMED, Set.of(RECEIVED, PENDING_UPDATE_CONFIRMATION, CONFIRMED)::contains), - Map.entry(REJECTED, Set.of(RECEIVED, PENDING_UPDATE, PENDING_UPDATE_CONFIRMATION)::contains), + Map.entry(CONFIRMED, Set.of(RECEIVED, UPDATE_RECEIVED, CONFIRMED)::contains), + Map.entry(REJECTED, Set.of(RECEIVED, PENDING_UPDATE, UPDATE_RECEIVED)::contains), Map.entry(DECLINED, Set.of(CONFIRMED, PENDING_AMENDMENT, AMENDMENT_RECEIVED)::contains), - Map.entry(PENDING_UPDATE, Set.of(RECEIVED, PENDING_UPDATE, PENDING_UPDATE_CONFIRMATION)::contains), + Map.entry(PENDING_UPDATE, Set.of(RECEIVED, PENDING_UPDATE, UPDATE_RECEIVED)::contains), Map.entry(PENDING_AMENDMENT, Set.of(CONFIRMED, PENDING_AMENDMENT)::contains), Map.entry(COMPLETED, Set.of(CONFIRMED)::contains) ); @@ -32,7 +32,7 @@ public class PersistableCarrierBooking { private static final Set NOT_APPLICABLE_FOR_SIMPLE_STATE_CHANGE = Set.of( START, RECEIVED, - PENDING_UPDATE_CONFIRMATION, + UPDATE_RECEIVED, AMENDMENT_RECEIVED, CANCELLED, CONFIRMED, @@ -47,7 +47,7 @@ public class PersistableCarrierBooking { private static final Set MAY_UPDATE_REQUEST_STATES = Set.of( RECEIVED, PENDING_UPDATE, - PENDING_UPDATE_CONFIRMATION + UPDATE_RECEIVED ); private static final String BOOKING_STATUS = "bookingStatus"; @@ -103,7 +103,7 @@ public void performSimpleStatusChange(String reference, BookingState newState) { } public void confirmBookingAmendment(String reference, String reason) { - checkState(reference, getBookingState(), s -> s == AMENDMENT_RECEIVED); + checkState(reference, getBookingAmendedState(), s -> s == AMENDMENT_RECEIVED); changeState(BOOKING_STATUS, CONFIRMED); changeState(AMENDED_BOOKING_STATUS, AMENDMENT_CONFIRMED); mutateBookingAndAmendment(this::ensureConfirmedBookingHasCarrierFields); @@ -118,12 +118,15 @@ public void confirmBooking(String reference, Supplier cbrGenerator, Stri var newCbr = cbrGenerator.get(); mutateBookingAndAmendment(b -> b.put(CARRIER_BOOKING_REFERENCE, newCbr)); } + resetAmendedState(); changeState(BOOKING_STATUS, CONFIRMED); mutateBookingAndAmendment(this::ensureConfirmedBookingHasCarrierFields); setReason(reason); } - + public void resetAmendedState() { + mutateBookingAndAmendment(b -> b.remove(AMENDED_BOOKING_STATUS)); + } private void ensureConfirmedBookingHasCarrierFields(ObjectNode booking) { var clauses = booking.putArray("carrierClauses"); @@ -148,7 +151,7 @@ public void declineBooking(String reference, String reason) { } public void declineBookingAmendment(String reference, String reason) { - checkState(reference, getBookingState(), s -> s == AMENDMENT_RECEIVED); + checkState(reference, getBookingAmendedState(), s -> s == AMENDMENT_RECEIVED); changeState(AMENDED_BOOKING_STATUS, AMENDMENT_DECLINED); setReason(reason); } @@ -195,7 +198,7 @@ public void cancelEntireBooking(String bookingReference, String reason) { } public void cancelBookingAmendment(String bookingReference, String reason) { - checkState(bookingReference, getBookingState(), s -> s == AMENDMENT_RECEIVED); + checkState(bookingReference, getBookingAmendedState(), s -> s == AMENDMENT_RECEIVED); changeState(AMENDED_BOOKING_STATUS, AMENDMENT_CANCELLED); if (reason == null || reason.isBlank()) { reason = "Amendment cancelled by shipper (no reason given)"; @@ -244,7 +247,7 @@ public void putBooking(String bookingReference, ObjectNode newBookingData) { if (isAmendment) { changeState(AMENDED_BOOKING_STATUS, BookingState.AMENDMENT_RECEIVED); } else { - changeState(BOOKING_STATUS, BookingState.PENDING_UPDATE_CONFIRMATION); + changeState(BOOKING_STATUS, BookingState.UPDATE_RECEIVED); } copyMetadataFields(getBooking(), newBookingData); if (isAmendment) { @@ -257,13 +260,15 @@ public void putBooking(String bookingReference, ObjectNode newBookingData) { public BookingState getBookingState() { var booking = getBooking(); - var s = booking.path(AMENDED_BOOKING_STATUS); - if (s.isTextual()) { - return BookingState.fromWireName(s.asText()); - } return BookingState.fromWireName(booking.required(BOOKING_STATUS).asText()); } + public BookingState getBookingAmendedState() { + var booking = getBooking(); + var s = booking.path(AMENDED_BOOKING_STATUS); + return BookingState.fromWireName(s.asText()); + } + public static PersistableCarrierBooking initializeFromBookingRequest(ObjectNode bookingRequest) { String cbrr = UUID.randomUUID().toString(); bookingRequest.put(CARRIER_BOOKING_REQUEST_REFERENCE, cbrr) diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingState.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingState.java index 4967e0b7..02f188aa 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingState.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingState.java @@ -4,7 +4,7 @@ public enum BookingState { START, RECEIVED, PENDING_UPDATE, - PENDING_UPDATE_CONFIRMATION, + UPDATE_RECEIVED, REJECTED, CANCELLED, CONFIRMED, diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java index 1120162f..7c1e2eb4 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java @@ -84,7 +84,7 @@ protected Map, Consumer> getActionP this::requestUpdateToConfirmedBooking), Map.entry(UC8_Carrier_ProcessAmendmentAction.class, this::processBookingAmendment), Map.entry(UC10_Carrier_DeclineBookingAction.class, this::declineBooking), - Map.entry(UC11_Carrier_ConfirmBookingCompletedAction.class, this::confirmBookingCompleted)); + Map.entry(UC12_Carrier_ConfirmBookingCompletedAction.class, this::confirmBookingCompleted)); } private char computeVesselIMONumberCheckDigit(String vesselIMONumberSansCheckDigit) { @@ -197,7 +197,8 @@ private void rejectBookingRequest(JsonNode actionPrompt) { actionPrompt, BookingState.REJECTED, true, - booking -> booking.put("reason", "Rejected as required by the conformance scenario") + booking -> booking.put("reason", "Rejected as required by the conformance scenario"), + false ); addOperatorLogEntry("Rejected the booking request with CBRR '%s'".formatted(cbrr)); } @@ -232,7 +233,8 @@ private void requestUpdateToBookingRequest(JsonNode actionPrompt) { .addObject() .put( "message", - "Please perform the changes requested by the Conformance orchestrator")); + "Please perform the changes requested by the Conformance orchestrator"), + false); addOperatorLogEntry("Requested update to the booking request with CBRR '%s'".formatted(cbrr)); } @@ -255,6 +257,7 @@ private void requestUpdateToConfirmedBooking(JsonNode actionPrompt) { String cbr = actionPrompt.get("cbr").asText(); + processAndEmitNotificationForStateTransition( actionPrompt, BookingState.PENDING_AMENDMENT, @@ -265,7 +268,8 @@ private void requestUpdateToConfirmedBooking(JsonNode actionPrompt) { .addObject() .put( "message", - "Please perform the changes requested by the Conformance orchestrator")); + "Please perform the changes requested by the Conformance orchestrator"), + true); addOperatorLogEntry("Requested update to the booking with CBR '%s'".formatted(cbr)); } @@ -273,7 +277,7 @@ private void processAndEmitNotificationForStateTransition( JsonNode actionPrompt, BookingState targetState) { processAndEmitNotificationForStateTransition( - actionPrompt, targetState, false, null); + actionPrompt, targetState, false, null, false); } private String generateAndAssociateCBR(String cbrr) { @@ -288,7 +292,8 @@ private void processAndEmitNotificationForStateTransition( JsonNode actionPrompt, BookingState targetState, boolean includeCbrr, - Consumer bookingMutator) { + Consumer bookingMutator, + boolean resetAmendedBookingStatus) { String cbrr = actionPrompt.get("cbrr").asText(); var peristableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); peristableCarrierBooking.performSimpleStatusChange(cbrr, targetState); @@ -296,6 +301,9 @@ private void processAndEmitNotificationForStateTransition( if (bookingMutator != null) { bookingMutator.accept(booking); } + if (resetAmendedBookingStatus) { + peristableCarrierBooking.resetAmendedState(); + } peristableCarrierBooking.save(persistentMap); generateAndEmitNotificationFromBooking(actionPrompt, peristableCarrierBooking, includeCbrr); } 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 4afca8a6..e3971056 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 @@ -63,7 +63,7 @@ protected Map, Consumer> getActionP Map.entry(UC3_Shipper_SubmitUpdatedBookingRequestAction.class, this::sendUpdatedBooking), Map.entry(UC7_Shipper_SubmitBookingAmendment.class, this::sendUpdatedConfirmedBooking), Map.entry(UC9_Shipper_CancelBookingAmendment.class, this::sendCancelBookingAmendment), - Map.entry(UC12_Shipper_CancelEntireBookingAction.class, this::sendCancelEntireBooking)); + Map.entry(UC11_Shipper_CancelEntireBookingAction.class, this::sendCancelEntireBooking)); } private void getBookingRequest(JsonNode actionPrompt) { From dd30c314f629f3d1530f703de7669f7799b2ba90 Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Wed, 13 Dec 2023 12:48:11 +0100 Subject: [PATCH 06/10] DT-740 this change was missed during the merge from test to dev. --- .../standards/booking/BookingScenarioListBuilder.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 db43de84..d8704c93 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 @@ -167,7 +167,9 @@ private BookingScenarioListBuilder thenAllPathsFrom( uc4_carrier_rejectBookingRequest().thenAllPathsFrom(REJECTED), uc5_carrier_confirmBookingRequest().thenAllPathsFrom(CONFIRMED), uc11_shipper_cancelBooking().thenAllPathsFrom(CANCELLED))); - case START -> then(uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR).thenAllPathsFrom(RECEIVED)); + case START -> thenEither( + uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR).thenAllPathsFrom(RECEIVED), + uc1_shipper_SubmitBookingRequest(BookingVariant.REEFER).thenHappyPathFrom(RECEIVED)); case PENDING_AMENDMENT -> then( shipper_GetBooking(bookingState) .thenEither( From 8d93f878f1024757b2171a017d7306faa7b656d9 Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:30:58 +0100 Subject: [PATCH 07/10] Dt-740 Changes after the review --- .../booking/BookingScenarioListBuilder.java | 90 +------------------ .../model/PersistableCarrierBooking.java | 26 +++--- .../standards/booking/party/Carrier.java | 9 +- 3 files changed, 20 insertions(+), 105 deletions(-) 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 d8704c93..51d8660a 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 @@ -32,94 +32,6 @@ public static BookingScenarioListBuilder buildTree( threadLocalComponentFactory.set(componentFactory); threadLocalCarrierPartyName.set(carrierPartyName); threadLocalShipperPartyName.set(shipperPartyName); - if (System.currentTimeMillis() > 0) { // FIXME remove this - // This is what's been implemented so far and should still work on PR. - return carrier_SupplyScenarioParameters() - .thenEither( - uc1_shipper_SubmitBookingRequest(BookingVariant.REEFER).then( - shipper_GetBooking(RECEIVED) - .then( - uc5_carrier_confirmBookingRequest() - .then( - shipper_GetBooking(CONFIRMED) - .then( - uc12_carrier_confirmBookingCompleted() - .then(shipper_GetBooking(COMPLETED)))))), - uc1_shipper_SubmitBookingRequest(BookingVariant.REGULAR) - .then( - shipper_GetBooking(RECEIVED) - .thenEither( - uc5_carrier_confirmBookingRequest() - .then( - shipper_GetBooking(CONFIRMED) - .thenEither( - uc5_carrier_confirmBookingRequest() - .then( - shipper_GetBooking(CONFIRMED) - .then( - uc12_carrier_confirmBookingCompleted() - .then(shipper_GetBooking(COMPLETED)))), - uc12_carrier_confirmBookingCompleted() - .then(shipper_GetBooking(COMPLETED)), - uc6_carrier_requestUpdateToConfirmedBooking() - .then( - shipper_GetBooking(PENDING_AMENDMENT) - .then( - uc7_shipper_submitBookingAmendment() - .then( - shipper_GetBooking( - PENDING_AMENDMENT, - AMENDMENT_RECEIVED) - .thenEither (uc9_shipper_cancelBookingAmendment() - .then(shipper_GetBooking( - PENDING_AMENDMENT, - AMENDMENT_CANCELLED)), - uc8b_carrier_declineBookingAmendment().then( - shipper_GetBooking( - PENDING_AMENDMENT, AMENDMENT_DECLINED) - .then( - uc6_carrier_requestUpdateToConfirmedBooking() - .thenHappyPathFrom(PENDING_AMENDMENT) - ) - ) - )))), - uc7_shipper_submitBookingAmendment() - .then( - shipper_GetBooking(CONFIRMED, AMENDMENT_RECEIVED) - .thenEither( - uc8a_carrier_approveBookingAmendment() - .then(shipper_GetBooking( - CONFIRMED, AMENDMENT_CONFIRMED)), - uc8b_carrier_declineBookingAmendment() - .then(shipper_GetBooking( - CONFIRMED, AMENDMENT_DECLINED)), - uc9_shipper_cancelBookingAmendment() - .then(shipper_GetBooking( - CONFIRMED, AMENDMENT_CANCELLED)), - uc10_carrier_declineBooking() - .then(shipper_GetBooking( - DECLINED, AMENDMENT_DECLINED)) - )), - uc10_carrier_declineBooking() - .then(shipper_GetBooking(DECLINED)), - uc11_shipper_cancelBooking() - .then(shipper_GetBooking(CANCELLED)))), - uc4_carrier_rejectBookingRequest().then(shipper_GetBooking(REJECTED)), - uc11_shipper_cancelBooking().then(shipper_GetBooking(CANCELLED)), - uc2_carrier_requestUpdateToBookingRequest() - .then(shipper_GetBooking(PENDING_UPDATE)), - uc3_shipper_submitUpdatedBookingRequest() - .then(shipper_GetBooking(UPDATE_RECEIVED)), - shipper_GetAmendedBooking404().then( - uc5_carrier_confirmBookingRequest().then( - shipper_GetAmendedBooking404().then(uc7_shipper_submitBookingAmendment() - .then( - shipper_GetBooking( - CONFIRMED, - AMENDMENT_RECEIVED, - true - )))))))); - } return carrier_SupplyScenarioParameters().thenAllPathsFrom(START); } @@ -197,7 +109,7 @@ private BookingScenarioListBuilder thenAllPathsFrom( ); case AMENDMENT_CANCELLED, AMENDMENT_DECLINED -> then( shipper_GetBooking(originalBookingState,bookingState) - .thenEither( + .then( uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT) ) ); diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java index 0eaa9a5d..dd8a4f2e 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java @@ -102,8 +102,15 @@ public void performSimpleStatusChange(String reference, BookingState newState) { performSimpleStatusChange(reference, newState, null); } + public void performSimpleStatusChange(String reference, BookingState newState, boolean resetAmendedBookingState) { + if(resetAmendedBookingState) { + resetAmendedBookingState(); + } + performSimpleStatusChange(reference, newState, null); + } + public void confirmBookingAmendment(String reference, String reason) { - checkState(reference, getBookingAmendedState(), s -> s == AMENDMENT_RECEIVED); + checkState(reference, getBookingAmendedState(), s -> s!=null && s == AMENDMENT_RECEIVED); changeState(BOOKING_STATUS, CONFIRMED); changeState(AMENDED_BOOKING_STATUS, AMENDMENT_CONFIRMED); mutateBookingAndAmendment(this::ensureConfirmedBookingHasCarrierFields); @@ -113,18 +120,17 @@ public void confirmBookingAmendment(String reference, String reason) { public void confirmBooking(String reference, Supplier cbrGenerator, String reason) { var prerequisites = PREREQUISITE_STATE_FOR_TARGET_STATE.get(CONFIRMED); - checkState(reference, getBookingState(), prerequisites); + checkState(reference, getOriginalBookingState(), prerequisites); if (this.getCarrierBookingReference() == null) { var newCbr = cbrGenerator.get(); mutateBookingAndAmendment(b -> b.put(CARRIER_BOOKING_REFERENCE, newCbr)); } - resetAmendedState(); changeState(BOOKING_STATUS, CONFIRMED); mutateBookingAndAmendment(this::ensureConfirmedBookingHasCarrierFields); setReason(reason); } - public void resetAmendedState() { + public void resetAmendedBookingState() { mutateBookingAndAmendment(b -> b.remove(AMENDED_BOOKING_STATUS)); } @@ -142,7 +148,7 @@ private void ensureConfirmedBookingHasCarrierFields(ObjectNode booking) { public void declineBooking(String reference, String reason) { var prerequisites = PREREQUISITE_STATE_FOR_TARGET_STATE.get(DECLINED); - checkState(reference, getBookingState(), prerequisites); + checkState(reference, getOriginalBookingState(), prerequisites); changeState(BOOKING_STATUS, DECLINED); if (getAmendedBooking().isPresent()) { changeState(AMENDED_BOOKING_STATUS, AMENDMENT_DECLINED); @@ -177,13 +183,13 @@ public void performSimpleStatusChange(String reference, BookingState newState, S if (prerequisiteState == null) { throw new IllegalArgumentException("Missing dependency check for state " + newState.wireName()); } - checkState(reference, getBookingState(), prerequisiteState); + checkState(reference, getOriginalBookingState(), prerequisiteState); changeState(BOOKING_STATUS, newState); setReason(reason); } public void cancelEntireBooking(String bookingReference, String reason) { - checkState(bookingReference, getBookingState(), s -> s != CANCELLED); + checkState(bookingReference, getOriginalBookingState(), s -> s != CANCELLED); changeState(BOOKING_STATUS, CANCELLED); if (reason == null || reason.isBlank()) { reason = "Entire booking cancelled by shipper (no reason given)"; @@ -234,7 +240,7 @@ private void removeRequestedChanges() { } public void putBooking(String bookingReference, ObjectNode newBookingData) { - var currentState = getBookingState(); + var currentState = getOriginalBookingState(); boolean isAmendment = currentState.equals(BookingState.CONFIRMED) || currentState.equals(BookingState.PENDING_AMENDMENT); @@ -258,7 +264,7 @@ public void putBooking(String bookingReference, ObjectNode newBookingData) { removeRequestedChanges(); } - public BookingState getBookingState() { + public BookingState getOriginalBookingState() { var booking = getBooking(); return BookingState.fromWireName(booking.required(BOOKING_STATUS).asText()); } @@ -266,7 +272,7 @@ public BookingState getBookingState() { public BookingState getBookingAmendedState() { var booking = getBooking(); var s = booking.path(AMENDED_BOOKING_STATUS); - return BookingState.fromWireName(s.asText()); + return !s.asText().isEmpty()? BookingState.fromWireName(s.asText()) : null; } public static PersistableCarrierBooking initializeFromBookingRequest(ObjectNode bookingRequest) { diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java index 7c1e2eb4..6a3b7523 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java @@ -293,17 +293,14 @@ private void processAndEmitNotificationForStateTransition( BookingState targetState, boolean includeCbrr, Consumer bookingMutator, - boolean resetAmendedBookingStatus) { + boolean resetAmendedBookingState) { String cbrr = actionPrompt.get("cbrr").asText(); var peristableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); - peristableCarrierBooking.performSimpleStatusChange(cbrr, targetState); + peristableCarrierBooking.performSimpleStatusChange(cbrr, targetState, resetAmendedBookingState); var booking = peristableCarrierBooking.getBooking(); if (bookingMutator != null) { bookingMutator.accept(booking); } - if (resetAmendedBookingStatus) { - peristableCarrierBooking.resetAmendedState(); - } peristableCarrierBooking.save(persistentMap); generateAndEmitNotificationFromBooking(actionPrompt, peristableCarrierBooking, includeCbrr); } @@ -559,7 +556,7 @@ private ConformanceResponse _handleGetBookingRequest(ConformanceRequest request) new ConformanceMessageBody(body)); addOperatorLogEntry( "Responded to GET booking request '%s' (in state '%s')" - .formatted(bookingReference, persistableCarrierBooking.getBookingState().wireName())); + .formatted(bookingReference, persistableCarrierBooking.getOriginalBookingState().wireName())); return response; } return return404(request); From 7ff31531240c24e71c6871959ba0c9d4a148fc77 Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Fri, 15 Dec 2023 09:55:17 +0100 Subject: [PATCH 08/10] DT-740 --- .../model/PersistableCarrierBooking.java | 66 ++++++++------ .../standards/booking/party/Carrier.java | 89 ++++++------------- 2 files changed, 66 insertions(+), 89 deletions(-) diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java index dd8a4f2e..70cfa37f 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java @@ -98,26 +98,14 @@ private void setAmendedBooking(ObjectNode node) { state.set(AMENDED_BOOKING_DATA_FIELD, node); } - public void performSimpleStatusChange(String reference, BookingState newState) { - performSimpleStatusChange(reference, newState, null); - } - - public void performSimpleStatusChange(String reference, BookingState newState, boolean resetAmendedBookingState) { - if(resetAmendedBookingState) { - resetAmendedBookingState(); - } - performSimpleStatusChange(reference, newState, null); - } - public void confirmBookingAmendment(String reference, String reason) { - checkState(reference, getBookingAmendedState(), s -> s!=null && s == AMENDMENT_RECEIVED); + checkState(reference, getBookingAmendedState(), s -> s == AMENDMENT_RECEIVED); changeState(BOOKING_STATUS, CONFIRMED); changeState(AMENDED_BOOKING_STATUS, AMENDMENT_CONFIRMED); mutateBookingAndAmendment(this::ensureConfirmedBookingHasCarrierFields); setReason(reason); } - public void confirmBooking(String reference, Supplier cbrGenerator, String reason) { var prerequisites = PREREQUISITE_STATE_FOR_TARGET_STATE.get(CONFIRMED); checkState(reference, getOriginalBookingState(), prerequisites); @@ -130,7 +118,8 @@ public void confirmBooking(String reference, Supplier cbrGenerator, Stri setReason(reason); } - public void resetAmendedBookingState() { + private void resetAmendedBookingState() { + state.remove(AMENDED_BOOKING_DATA_FIELD); mutateBookingAndAmendment(b -> b.remove(AMENDED_BOOKING_STATUS)); } @@ -170,22 +159,41 @@ private void setReason(String reason) { } } - /** - * Replace this with a more concrete call (like confirmBooking()) when needed - */ - @Deprecated - public void performSimpleStatusChange(String reference, BookingState newState, String reason) { - // FIXME: Have logic for amendment vs. non-amendment states - if (NOT_APPLICABLE_FOR_SIMPLE_STATE_CHANGE.contains(newState)) { - throw new IllegalArgumentException("This state cannot be set via setCarrierStatus"); + public void requestUpdateToBooking(String reference, Consumer bookingMutator) { + var prerequisites = PREREQUISITE_STATE_FOR_TARGET_STATE.get(PENDING_UPDATE); + checkState(reference, getOriginalBookingState(), prerequisites); + changeState(BOOKING_STATUS, PENDING_UPDATE); + mutateBookingAndAmendment(bookingMutator); + } + + public void rejectBooking(String reference, String rejectReason) { + var prerequisites = PREREQUISITE_STATE_FOR_TARGET_STATE.get(REJECTED); + checkState(reference, getOriginalBookingState(), prerequisites); + changeState(BOOKING_STATUS, REJECTED); + if (rejectReason == null || rejectReason.isBlank()) { + rejectReason = "default message of rejection(reason not provided by carrier)"; } - var prerequisiteState = PREREQUISITE_STATE_FOR_TARGET_STATE.get(newState); - if (prerequisiteState == null) { - throw new IllegalArgumentException("Missing dependency check for state " + newState.wireName()); + final var reason = rejectReason; + mutateBookingAndAmendment((bookingContent, isAmendedContent) -> { + bookingContent.put("reason", reason); + }); + } + + public void confirmBookingCompleted(String reference) { + var prerequisites = PREREQUISITE_STATE_FOR_TARGET_STATE.get(COMPLETED); + checkState(reference, getOriginalBookingState(), prerequisites); + changeState(BOOKING_STATUS, COMPLETED); + } + + public void updateConfirmedBooking(String reference, Consumer bookingMutator,boolean resetAmendedBooking) { + var prerequisites = PREREQUISITE_STATE_FOR_TARGET_STATE.get(PENDING_AMENDMENT); + checkState(reference, getOriginalBookingState(), prerequisites); + changeState(BOOKING_STATUS, PENDING_AMENDMENT); + mutateBookingAndAmendment(bookingMutator); + if (resetAmendedBooking) { + resetAmendedBookingState(); } - checkState(reference, getOriginalBookingState(), prerequisiteState); - changeState(BOOKING_STATUS, newState); - setReason(reason); + setReason(null); } public void cancelEntireBooking(String bookingReference, String reason) { @@ -272,7 +280,7 @@ public BookingState getOriginalBookingState() { public BookingState getBookingAmendedState() { var booking = getBooking(); var s = booking.path(AMENDED_BOOKING_STATUS); - return !s.asText().isEmpty()? BookingState.fromWireName(s.asText()) : null; + return !s.asText("").isEmpty()? BookingState.fromWireName(s.asText()) : null; } public static PersistableCarrierBooking initializeFromBookingRequest(ObjectNode bookingRequest) { diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java index bb009a31..e2ede1ec 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java @@ -192,14 +192,10 @@ private void rejectBookingRequest(JsonNode actionPrompt) { log.info("Carrier.rejectBookingRequest(%s)".formatted(actionPrompt.toPrettyString())); String cbrr = actionPrompt.get("cbrr").asText(); - - processAndEmitNotificationForStateTransition( - actionPrompt, - BookingState.REJECTED, - true, - booking -> booking.put("reason", "Rejected as required by the conformance scenario"), - false - ); + var persistableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); + persistableCarrierBooking.rejectBooking(cbrr,"Rejected as required by the conformance scenario"); + persistableCarrierBooking.save(persistentMap); + generateAndEmitNotificationFromBooking(actionPrompt, persistableCarrierBooking, true); addOperatorLogEntry("Rejected the booking request with CBRR '%s'".formatted(cbrr)); } @@ -220,21 +216,18 @@ private void declineBooking(JsonNode actionPrompt) { private void requestUpdateToBookingRequest(JsonNode actionPrompt) { log.info("Carrier.requestUpdateToBookingRequest(%s)".formatted(actionPrompt.toPrettyString())); - + Consumer bookingMutator = booking -> booking.putArray("requestedChanges") + .addObject() + .put( + "message", + "Please perform the changes requested by the Conformance orchestrator"); String cbrr = actionPrompt.get("cbrr").asText(); + var persistableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); + + persistableCarrierBooking.requestUpdateToBooking(cbrr,bookingMutator); + persistableCarrierBooking.save(persistentMap); + generateAndEmitNotificationFromBooking(actionPrompt, persistableCarrierBooking, true); - processAndEmitNotificationForStateTransition( - actionPrompt, - BookingState.PENDING_UPDATE, - true, - booking -> - booking - .putArray("requestedChanges") - .addObject() - .put( - "message", - "Please perform the changes requested by the Conformance orchestrator"), - false); addOperatorLogEntry("Requested update to the booking request with CBRR '%s'".formatted(cbrr)); } @@ -244,10 +237,11 @@ private void confirmBookingCompleted(JsonNode actionPrompt) { String cbrr = actionPrompt.get("cbrr").asText(); String cbr = cbrrToCbr.get(cbrr); + var persistableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); + persistableCarrierBooking.confirmBookingCompleted(cbrr); + persistableCarrierBooking.save(persistentMap); + generateAndEmitNotificationFromBooking(actionPrompt, persistableCarrierBooking, false); - processAndEmitNotificationForStateTransition( - actionPrompt, - BookingState.COMPLETED); addOperatorLogEntry("Completed the booking request with CBR '%s'".formatted(cbr)); } @@ -255,29 +249,21 @@ private void requestUpdateToConfirmedBooking(JsonNode actionPrompt) { log.info( "Carrier.requestUpdateToConfirmedBooking(%s)".formatted(actionPrompt.toPrettyString())); + String cbrr = actionPrompt.get("cbrr").asText(); String cbr = actionPrompt.get("cbr").asText(); + Consumer bookingMutator = booking -> booking.putArray("requestedChanges") + .addObject() + .put( + "message", + "Please perform the changes requested by the Conformance orchestrator"); - processAndEmitNotificationForStateTransition( - actionPrompt, - BookingState.PENDING_AMENDMENT, - true, - booking -> - booking - .putArray("requestedChanges") - .addObject() - .put( - "message", - "Please perform the changes requested by the Conformance orchestrator"), - true); - addOperatorLogEntry("Requested update to the booking with CBR '%s'".formatted(cbr)); - } + var persistableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); + persistableCarrierBooking.updateConfirmedBooking(cbrr,bookingMutator,true); + persistableCarrierBooking.save(persistentMap); + generateAndEmitNotificationFromBooking(actionPrompt, persistableCarrierBooking, true); - private void processAndEmitNotificationForStateTransition( - JsonNode actionPrompt, - BookingState targetState) { - processAndEmitNotificationForStateTransition( - actionPrompt, targetState, false, null, false); + addOperatorLogEntry("Requested update to the booking with CBR '%s'".formatted(cbr)); } private String generateAndAssociateCBR(String cbrr) { @@ -288,23 +274,6 @@ private String generateAndAssociateCBR(String cbrr) { return cbr; } - private void processAndEmitNotificationForStateTransition( - JsonNode actionPrompt, - BookingState targetState, - boolean includeCbrr, - Consumer bookingMutator, - boolean resetAmendedBookingState) { - String cbrr = actionPrompt.get("cbrr").asText(); - var peristableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); - peristableCarrierBooking.performSimpleStatusChange(cbrr, targetState, resetAmendedBookingState); - var booking = peristableCarrierBooking.getBooking(); - if (bookingMutator != null) { - bookingMutator.accept(booking); - } - peristableCarrierBooking.save(persistentMap); - generateAndEmitNotificationFromBooking(actionPrompt, peristableCarrierBooking, includeCbrr); - } - private void generateAndEmitNotificationFromBooking(JsonNode actionPrompt, PersistableCarrierBooking persistableCarrierBooking, boolean includeCbrr) { var notification = BookingNotification.builder() From dd0b4e2f68a8103e73553b7950a6b193669381cf Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Fri, 15 Dec 2023 09:57:17 +0100 Subject: [PATCH 09/10] DT-740 removed unused constant --- .../booking/model/PersistableCarrierBooking.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java index 70cfa37f..c0bcbbd6 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java @@ -29,16 +29,6 @@ public class PersistableCarrierBooking { Map.entry(COMPLETED, Set.of(CONFIRMED)::contains) ); - private static final Set NOT_APPLICABLE_FOR_SIMPLE_STATE_CHANGE = Set.of( - START, - RECEIVED, - UPDATE_RECEIVED, - AMENDMENT_RECEIVED, - CANCELLED, - CONFIRMED, - DECLINED - ); - private static final Set MAY_AMEND_STATES = Set.of( CONFIRMED, PENDING_AMENDMENT From 7e558965a4f78d16aca751d7e2d24c1146b47d06 Mon Sep 17 00:00:00 2001 From: preetamnpr <128618622+preetamnpr@users.noreply.github.com> Date: Fri, 15 Dec 2023 14:28:29 +0100 Subject: [PATCH 10/10] DT-740 --- .../booking/BookingScenarioListBuilder.java | 8 +++---- ...Carrier_ConfirmBookingCompletedAction.java | 3 +-- .../model/PersistableCarrierBooking.java | 14 ++++++++++- .../standards/booking/party/Carrier.java | 24 +++++++++---------- 4 files changed, 29 insertions(+), 20 deletions(-) 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 51d8660a..66027c0c 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 @@ -103,15 +103,13 @@ private BookingScenarioListBuilder thenAllPathsFrom( case AMENDMENT_CONFIRMED -> then( shipper_GetBooking(CONFIRMED,bookingState) .thenEither( - uc12_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED), - uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT) + noAction().thenHappyPathFrom(CONFIRMED), + noAction().thenHappyPathFrom(PENDING_AMENDMENT) ) ); case AMENDMENT_CANCELLED, AMENDMENT_DECLINED -> then( shipper_GetBooking(originalBookingState,bookingState) - .then( - uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT) - ) + .thenHappyPathFrom(originalBookingState) ); }; } diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Carrier_ConfirmBookingCompletedAction.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Carrier_ConfirmBookingCompletedAction.java index 200d8f49..46df3f02 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Carrier_ConfirmBookingCompletedAction.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/action/UC12_Carrier_ConfirmBookingCompletedAction.java @@ -49,8 +49,7 @@ protected Stream createSubChecks() { BookingRole::isShipper, getMatchedExchangeUuid(), expectedStatus), new CarrierBookingNotificationDataPayloadRequestConformanceCheck( getMatchedExchangeUuid(), - BookingState.COMPLETED, - dsp.amendedBookingStatus() != null ? BookingState.AMENDMENT_CONFIRMED : null + BookingState.COMPLETED ), ApiHeaderCheck.createNotificationCheck( BookingRole::isCarrier, diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java index c0bcbbd6..dfa4da03 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/model/PersistableCarrierBooking.java @@ -169,10 +169,14 @@ public void rejectBooking(String reference, String rejectReason) { }); } - public void confirmBookingCompleted(String reference) { + public void confirmBookingCompleted(String reference, boolean resetAmendedBooking) { var prerequisites = PREREQUISITE_STATE_FOR_TARGET_STATE.get(COMPLETED); checkState(reference, getOriginalBookingState(), prerequisites); changeState(BOOKING_STATUS, COMPLETED); + if (resetAmendedBooking) { + resetAmendedBookingState(); + } + setReason(null); } public void updateConfirmedBooking(String reference, Consumer bookingMutator,boolean resetAmendedBooking) { @@ -239,6 +243,7 @@ private void removeRequestedChanges() { public void putBooking(String bookingReference, ObjectNode newBookingData) { var currentState = getOriginalBookingState(); + var amendedBookingState = getBookingAmendedState(); boolean isAmendment = currentState.equals(BookingState.CONFIRMED) || currentState.equals(BookingState.PENDING_AMENDMENT); @@ -248,6 +253,12 @@ public void putBooking(String bookingReference, ObjectNode newBookingData) { currentState, (isAmendment ? MAY_AMEND_STATES : MAY_UPDATE_REQUEST_STATES)::contains ); + + if(amendedBookingState != null && amendedBookingState.equals(AMENDMENT_RECEIVED)) { + throw new IllegalStateException( + "Booking '%s' is in Amendment state '%s'".formatted(bookingReference, amendedBookingState)); + } + if (isAmendment) { changeState(AMENDED_BOOKING_STATUS, BookingState.AMENDMENT_RECEIVED); } else { @@ -260,6 +271,7 @@ public void putBooking(String bookingReference, ObjectNode newBookingData) { setBooking(newBookingData); } removeRequestedChanges(); + setReason(null); } public BookingState getOriginalBookingState() { diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java index e2ede1ec..d42a7e37 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/Carrier.java @@ -150,8 +150,8 @@ private List generateValidCommodityTypeAndHSCodes() { private void processBookingAmendment(JsonNode actionPrompt) { log.info("Carrier.processBookingAmendment(%s)".formatted(actionPrompt.toPrettyString())); - String cbr = actionPrompt.get("cbr").asText(); - String cbrr = actionPrompt.get("cbrr").asText(); + String cbr = actionPrompt.required("cbr").asText(); + String cbrr = actionPrompt.required("cbrr").asText(); boolean acceptAmendment = actionPrompt.path("acceptAmendment").asBoolean(true); addOperatorLogEntry( "Confirmed the booking amendment for booking with CBR '%s'".formatted(cbr)); @@ -169,7 +169,7 @@ private void processBookingAmendment(JsonNode actionPrompt) { private void confirmBookingRequest(JsonNode actionPrompt) { log.info("Carrier.confirmBookingRequest(%s)".formatted(actionPrompt.toPrettyString())); - String cbrr = actionPrompt.get("cbrr").asText(); + String cbrr = actionPrompt.required("cbrr").asText(); addOperatorLogEntry( "Confirmed the booking request with CBRR '%s'".formatted(cbrr)); @@ -191,7 +191,7 @@ private void confirmBookingRequest(JsonNode actionPrompt) { private void rejectBookingRequest(JsonNode actionPrompt) { log.info("Carrier.rejectBookingRequest(%s)".formatted(actionPrompt.toPrettyString())); - String cbrr = actionPrompt.get("cbrr").asText(); + String cbrr = actionPrompt.required("cbrr").asText(); var persistableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); persistableCarrierBooking.rejectBooking(cbrr,"Rejected as required by the conformance scenario"); persistableCarrierBooking.save(persistentMap); @@ -202,8 +202,8 @@ private void rejectBookingRequest(JsonNode actionPrompt) { private void declineBooking(JsonNode actionPrompt) { log.info("Carrier.declineBooking(%s)".formatted(actionPrompt.toPrettyString())); - String cbr = actionPrompt.get("cbr").asText(); - String cbrr = actionPrompt.get("cbrr").asText(); + String cbr = actionPrompt.required("cbr").asText(); + String cbrr = actionPrompt.required("cbrr").asText(); addOperatorLogEntry( "Confirmed the booking request with CBR '%s'".formatted(cbr)); @@ -221,7 +221,7 @@ private void requestUpdateToBookingRequest(JsonNode actionPrompt) { .put( "message", "Please perform the changes requested by the Conformance orchestrator"); - String cbrr = actionPrompt.get("cbrr").asText(); + String cbrr = actionPrompt.required("cbrr").asText(); var persistableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); persistableCarrierBooking.requestUpdateToBooking(cbrr,bookingMutator); @@ -234,11 +234,11 @@ private void requestUpdateToBookingRequest(JsonNode actionPrompt) { private void confirmBookingCompleted(JsonNode actionPrompt) { log.info("Carrier.confirmBookingCompleted(%s)".formatted(actionPrompt.toPrettyString())); - String cbrr = actionPrompt.get("cbrr").asText(); + String cbrr = actionPrompt.required("cbrr").asText(); String cbr = cbrrToCbr.get(cbrr); var persistableCarrierBooking = PersistableCarrierBooking.fromPersistentStore(persistentMap, cbrr); - persistableCarrierBooking.confirmBookingCompleted(cbrr); + persistableCarrierBooking.confirmBookingCompleted(cbrr, true); persistableCarrierBooking.save(persistentMap); generateAndEmitNotificationFromBooking(actionPrompt, persistableCarrierBooking, false); @@ -249,8 +249,8 @@ private void requestUpdateToConfirmedBooking(JsonNode actionPrompt) { log.info( "Carrier.requestUpdateToConfirmedBooking(%s)".formatted(actionPrompt.toPrettyString())); - String cbrr = actionPrompt.get("cbrr").asText(); - String cbr = actionPrompt.get("cbr").asText(); + String cbrr = actionPrompt.required("cbrr").asText(); + String cbr = actionPrompt.required("cbr").asText(); Consumer bookingMutator = booking -> booking.putArray("requestedChanges") .addObject() @@ -286,7 +286,7 @@ private void generateAndEmitNotificationFromBooking(JsonNode actionPrompt, Persi asyncCounterpartPostNotification("/v2/booking-notifications", notification); } else { asyncOrchestratorPostPartyInput( - OBJECT_MAPPER.createObjectNode().put("actionId", actionPrompt.get("actionId").asText())); + OBJECT_MAPPER.createObjectNode().put("actionId", actionPrompt.required("actionId").asText())); } }