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 @@ -32,85 +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(
uc11_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(
uc11_carrier_confirmBookingCompleted()
.then(shipper_GetBooking(COMPLETED)))),
uc11_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)
.then (uc9_shipper_cancelBookingAmendment()
.then(shipper_GetBooking(
PENDING_AMENDMENT,
CANCELLED)))))),
uc7_shipper_submitBookingAmendment()
.then(
shipper_GetBooking(CONFIRMED, AMENDMENT_RECEIVED)
.thenEither(
uc8a_carrier_approveBookingAmendment()
.then(shipper_GetBooking(
CONFIRMED, CONFIRMED)),
uc8b_carrier_declineBookingAmendment()
.then(shipper_GetBooking(
CONFIRMED, DECLINED)),
uc9_shipper_cancelBookingAmendment()
.then(shipper_GetBooking(
CONFIRMED, CANCELLED)),
uc10_carrier_declineBooking()
.then(shipper_GetBooking(
DECLINED, DECLINED))
)),
uc10_carrier_declineBooking()
.then(shipper_GetBooking(DECLINED)),
uc12_shipper_cancelBooking()
.then(shipper_GetBooking(CANCELLED)))),
uc4_carrier_rejectBookingRequest().then(shipper_GetBooking(REJECTED)),
uc12_shipper_cancelBooking().then(shipper_GetBooking(CANCELLED)),
uc2_carrier_requestUpdateToBookingRequest()
.then(shipper_GetBooking(PENDING_UPDATE)),
uc3_shipper_submitUpdatedBookingRequest()
.then(shipper_GetBooking(PENDING_UPDATE_CONFIRMATION)),
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);
}

Expand All @@ -121,79 +42,96 @@ 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),
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)));
uc11_shipper_cancelBooking().thenAllPathsFrom(CANCELLED)));
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(
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().thenHappyPathFrom(CONFIRMED),
uc8b_carrier_declineBookingAmendment().thenHappyPathFrom(CONFIRMED),
uc9_shipper_cancelBookingAmendment().thenHappyPathFrom(originalBookingState),
uc10_carrier_declineBooking().thenHappyPathFrom(DECLINED),
uc12_shipper_cancelBooking().thenHappyPathFrom(CANCELLED)));
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(
uc12_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace this line with:

Suggested change
uc12_carrier_confirmBookingCompleted().thenHappyPathFrom(COMPLETED),
noAction().thenHappyPathFrom(CONFIRMED),

The noAction() is a stepping stone for enabling the .thenHappyPathFrom call.

uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT)
)
);
case AMENDMENT_CANCELLED, AMENDMENT_DECLINED -> then(
shipper_GetBooking(originalBookingState,bookingState)
.then(
uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT)
)
);
};
Copy link
Collaborator

@nt-gt nt-gt Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From AMENDMENT_CANCELLED and AMENDMENT_DECLINED the possible actions depend on the original booking state.

I think this case can be simplified into:

Suggested change
case AMENDMENT_CANCELLED, AMENDMENT_DECLINED -> then(
shipper_GetBooking(originalBookingState,bookingState)
.then(
uc6_carrier_requestUpdateToConfirmedBooking().thenHappyPathFrom(PENDING_AMENDMENT)
)
);
};
case AMENDMENT_CANCELLED, AMENDMENT_DECLINED -> then(
shipper_GetBooking(originalBookingState,bookingState)
.thenHappyPathFrom(originalBookingState));

}

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(
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(
"This happyPath from this state requires a context state");
};
}

Expand Down Expand Up @@ -265,8 +203,6 @@ private static BookingScenarioListBuilder uc1_shipper_SubmitBookingRequest(Booki
variant));
}



private static BookingScenarioListBuilder carrierStateChange(
CarrierNotificationUseCase constructor) {
BookingComponentFactory componentFactory = threadLocalComponentFactory.get();
Expand Down Expand Up @@ -314,10 +250,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 Expand Up @@ -363,17 +295,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,
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
),
ApiHeaderCheck.createNotificationCheck(
BookingRole::isCarrier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand All @@ -42,14 +41,16 @@ public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
var dsp = getDspSupplier().get();
return Stream.of(
new UrlPathCheck(
BookingRole::isCarrier, getMatchedExchangeUuid(), "/v2/booking-notifications"),
new ResponseStatusCheck(
BookingRole::isShipper, getMatchedExchangeUuid(), expectedStatus),
new CarrierBookingNotificationDataPayloadRequestConformanceCheck(
getMatchedExchangeUuid(),
BookingState.COMPLETED
BookingState.COMPLETED,
dsp.amendedBookingStatus() != null ? BookingState.AMENDMENT_CONFIRMED : null
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look correct. It should be possible to end with a AMENDEDMENT that was declined/cancelled when reaching the UC12_Carrier_ConfirmBookingCompletedAction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we are not calling UC12 for amendment Declined or cancelled. https://miro.com/app/board/uXjVND1csI8=/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a confirmed booking never has a grey state, then having line 53 is incorrect.
If a confirmed booking can have a grey state, then it could have any of the grey states AMENDMENT CONFIRMED, AMENDMENT DECLINED or AMENDMENT CANCELLED.

Either way, the code is inconsistent by saying that if there is an amended status, it must be AMENDMENT CONFIRMED.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this one is still "unanswered". I suspect it is because the scenarios do not cover the case of (as an example): ... -> UC5 -> UC7 -> UC9 -> UC12

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

We call the UC8A and then go to UC12.. Hence I put that AmendedBookingStatus check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get ur point. The amendedBookingStatus shouldnt be checked in the UC12. 👍 because the flow of confirmed amendment itself complete after UC8A . am I right ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I would expect the amendedBookingStatus in UC12 should match the value of dsp.amendedBookingStatus().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the miro board, UC12 shouldnt be having any AMENDMENT status.

Copy link
Collaborator

@nt-gt nt-gt Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify that assertion with Flavia. Sometimes the states can inherit the amendment/updated state even though it is not visible in the Miro board. (In eBL, after UC4a, the RECEIVED state is actually RECEIVED + UPDATE CONFIRMED even though the UPDATE CONFIRMED is not visible).

When discussing the scenario with Flavia, be sure to show an exceptional case where you could end up in UC12 with an amended state.

Example: ... -> UC5 -> UC7 -> UC8a -> UC12

I hope she agrees with you, because then we can just "reset" the amendment state + content when doing UC12 and simplify the check here. But as said, please confirm with the PO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with internally, at UC12 we dont need to check the final AmendmentStatus for Booking.

ApiHeaderCheck.createNotificationCheck(
BookingRole::isCarrier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
getNotificationChecks(
expectedApiVersion,
notificationSchemaValidator,
BookingState.PENDING_UPDATE_CONFIRMATION,
BookingState.UPDATE_RECEIVED,
null));
}
};
Expand Down
Loading
Loading