Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dt 740 #27

Merged
merged 12 commits into from
Dec 18, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -112,12 +112,12 @@ 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 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),
Expand Down Expand Up @@ -153,27 +153,37 @@ 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),
uc12_shipper_cancelBooking().thenHappyPathFrom(CANCELLED)));
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),
nt-gt marked this conversation as resolved.
Show resolved Hide resolved
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, REJECTED -> then(noAction());
case CONFIRMED -> then(uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED));
case CONFIRMED, AMENDMENT_CONFIRMED -> then(uc11_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED));
case PENDING_AMENDMENT -> then(
uc7_shipper_submitBookingAmendment().thenHappyPathFrom(AMENDMENT_RECEIVED));
case AMENDMENT_RECEIVED -> then(
Expand All @@ -183,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");
};
}

Expand Down Expand Up @@ -300,10 +312,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
new CarrierBookingNotificationDataPayloadRequestConformanceCheck(
getMatchedExchangeUuid(),
BookingState.DECLINED,
dsp.amendedBookingStatus() != null ? BookingState.DECLINED : null
dsp.amendedBookingStatus() != null ? BookingState.AMENDMENT_DECLINED : null
),
new ApiHeaderCheck(
BookingRole::isCarrier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
new CarrierBookingNotificationDataPayloadRequestConformanceCheck(
getMatchedExchangeUuid(),
acceptAmendment ? BookingState.CONFIRMED : bookingStatus,
acceptAmendment ? BookingState.CONFIRMED : BookingState.DECLINED
acceptAmendment ? BookingState.AMENDMENT_CONFIRMED : BookingState.AMENDMENT_DECLINED
),
new ApiHeaderCheck(
BookingRole::isCarrier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ abstract class AbstractCarrierPayloadConformanceCheck extends PayloadContentConf
protected static final Set<BookingState> REASON_STATES = Set.of(
BookingState.DECLINED,
BookingState.REJECTED,
BookingState.CANCELLED
BookingState.CANCELLED,
BookingState.AMENDMENT_CANCELLED,
BookingState.AMENDMENT_DECLINED
);

protected static final Set<BookingState> BOOKING_STATES_WHERE_CBR_IS_OPTIONAL = Set.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ public enum BookingState {
CANCELLED,
CONFIRMED,
PENDING_AMENDMENT,
AMENDMENT_RECEIVED,
DECLINED,
AMENDMENT_RECEIVED,
AMENDMENT_CONFIRMED,
AMENDMENT_DECLINED,
AMENDMENT_CANCELLED,
COMPLETED,
;

Expand Down
Loading