Skip to content

Commit

Permalink
DT-739: Update the state transitions to match latest diagram
Browse files Browse the repository at this point in the history
Signed-off-by: Niels Thykier <[email protected]>
  • Loading branch information
nt-gt committed Dec 14, 2023
1 parent da74ada commit d2c6888
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ yield thenEither(
.thenHappyPathFrom(SI_PENDING_UPDATE)),
uc4a_carrier_acceptUpdatedShippingInstructions()
.then(
shipper_GetShippingInstructions(SI_RECEIVED, TD_START)
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_CONFIRMED, TD_START)
.thenHappyPathFrom(SI_RECEIVED)),
uc4d_carrier_declineUpdatedShippingInstructions()
.then(
shipper_GetShippingInstructions(memoryState, SI_DECLINED, TD_START)
shipper_GetShippingInstructions(memoryState, SI_UPDATE_DECLINED, TD_START)
.thenHappyPathFrom(memoryState)),
uc5_shipper_cancelUpdateToShippingInstructions()
.then(
shipper_GetShippingInstructions(memoryState, SI_CANCELLED, TD_START)
shipper_GetShippingInstructions(memoryState, SI_UPDATE_CANCELLED, TD_START)
.thenHappyPathFrom(memoryState)));
}
case SI_PENDING_UPDATE -> then(
Expand All @@ -108,13 +108,24 @@ yield thenEither(
// are considered happy paths.
uc5_shipper_cancelUpdateToShippingInstructions()
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_CANCELLED, TD_START)
shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_CANCELLED, TD_START)
.thenEither(
noAction().thenHappyPathFrom(SI_PENDING_UPDATE),
uc3_shipper_submitUpdatedShippingInstructions().then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, TD_START)
.thenHappyPathFrom(SI_UPDATE_RECEIVED)))))));
case SI_CANCELLED, SI_DECLINED -> throw new AssertionError("Please use the black state rather than " + shippingInstructionsStatus.name());
case SI_UPDATE_CONFIRMED -> thenEither(
noAction().thenHappyPathFrom(SI_UPDATE_CONFIRMED),
// Just to validate that the "Carrier" does not get "stuck"
uc2_carrier_requestUpdateToShippingInstruction()
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, TD_START)
.thenHappyPathFrom(SI_PENDING_UPDATE)),
uc3_shipper_submitUpdatedShippingInstructions()
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, TD_START)
.thenHappyPathFrom(SI_UPDATE_RECEIVED)));
case SI_UPDATE_CANCELLED, SI_UPDATE_DECLINED -> throw new AssertionError("Please use the black state rather than " + shippingInstructionsStatus.name());
case SI_ANY -> throw new AssertionError("Not a real/reachable state");
case SI_COMPLETED -> then(noAction());
};
Expand All @@ -128,7 +139,7 @@ private EblScenarioListBuilder thenHappyPathFrom(
.then(
shipper_GetShippingInstructions(SI_RECEIVED, TD_START)
.thenHappyPathFrom(SI_RECEIVED)));
case SI_RECEIVED -> then(uc6_carrier_publishDraftTransportDocument()
case SI_UPDATE_CONFIRMED, SI_RECEIVED -> then(uc6_carrier_publishDraftTransportDocument()
.then(
shipper_GetShippingInstructions(SI_RECEIVED, TD_DRAFT, true)
.then(shipper_GetTransportDocument(TD_DRAFT)
Expand All @@ -138,11 +149,11 @@ private EblScenarioListBuilder thenHappyPathFrom(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_RECEIVED, TD_START)
.thenHappyPathFrom(SI_UPDATE_RECEIVED)));
case SI_UPDATE_RECEIVED -> then(uc4a_carrier_acceptUpdatedShippingInstructions()
.then(shipper_GetShippingInstructions(SI_RECEIVED, TD_START)
.thenHappyPathFrom(SI_RECEIVED))
.then(shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_CONFIRMED, TD_START)
.thenHappyPathFrom(SI_UPDATE_CONFIRMED))
);
case SI_COMPLETED -> then(noAction());
case SI_CANCELLED, SI_DECLINED -> throw new AssertionError("Please use the black state rather than DECLINED");
case SI_UPDATE_CANCELLED, SI_UPDATE_DECLINED -> throw new AssertionError("Please use the black state rather than DECLINED");
case SI_ANY -> throw new AssertionError("Not a real/reachable state");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
expectedApiVersion,
requestSchemaValidator,
acceptChanges ? ShippingInstructionsStatus.SI_RECEIVED : currentState,
acceptChanges ? null : ShippingInstructionsStatus.SI_DECLINED
acceptChanges ? ShippingInstructionsStatus.SI_UPDATE_CONFIRMED : ShippingInstructionsStatus.SI_UPDATE_DECLINED
));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
EBLChecks.siRefStatusChecks(
getMatchedExchangeUuid(),
siStatus,
ShippingInstructionsStatus.SI_CANCELLED
ShippingInstructionsStatus.SI_UPDATE_CANCELLED
)),
getSINotificationChecks(
expectedApiVersion,
notificationSchemaValidator,
siStatus,
ShippingInstructionsStatus.SI_CANCELLED)));
ShippingInstructionsStatus.SI_UPDATE_CANCELLED)));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private void setReason(String reason) {

public void cancelShippingInstructionsUpdate(String shippingInstructionsReference) {
checkState(shippingInstructionsReference, getShippingInstructionsState(), s -> s == SI_UPDATE_RECEIVED);
changeSIState(UPDATED_SI_STATUS, SI_CANCELLED);
changeSIState(UPDATED_SI_STATUS, SI_UPDATE_CANCELLED);
setReason(null);
}

Expand All @@ -286,10 +286,10 @@ public void acceptUpdatedShippingInstructions(String documentReference) {
checkState(documentReference, getShippingInstructionsState(), s -> s == SI_UPDATE_RECEIVED);
var updated = getUpdatedShippingInstructions().orElseThrow();
setShippingInstructions(updated);
clearUpdatedShippingInstructions();
setReason(null);
mutateShippingInstructionsAndUpdate(siData -> siData.remove("requestedChanges"));
changeSIState(SI_STATUS, SI_RECEIVED);
changeSIState(UPDATED_SI_STATUS, SI_UPDATE_CONFIRMED);
}

public void declineUpdatedShippingInstructions(String documentReference, String reason) {
Expand All @@ -299,7 +299,7 @@ public void declineUpdatedShippingInstructions(String documentReference, String
clearUpdatedShippingInstructions();
setReason(reason);
mutateShippingInstructionsAndUpdate(siData -> siData.remove("requestedChanges"));
changeSIState(UPDATED_SI_STATUS, SI_DECLINED);
changeSIState(UPDATED_SI_STATUS, SI_UPDATE_DECLINED);
}

public void confirmShippingInstructionsComplete(String documentReference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void cancelUpdateToShippingInstructions(JsonNode actionPrompt) {

var documentReference = actionPrompt.required("documentReference").asText();
var approvePayload = new ObjectMapper().createObjectNode()
.put("updatedShippingInstructionsStatus", ShippingInstructionsStatus.SI_CANCELLED.wireName());
.put("updatedShippingInstructionsStatus", ShippingInstructionsStatus.SI_UPDATE_CANCELLED.wireName());

asyncCounterpartPatch(
"/v3/shipping-instructions/%s".formatted(documentReference),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public enum ShippingInstructionsStatus {
SI_RECEIVED("RECEIVED"),
SI_PENDING_UPDATE("PENDING UDPATE"),
SI_UPDATE_RECEIVED("UPDATE RECEIVED"),
SI_CANCELLED("CANCELLED"),
SI_DECLINED("DECLINED"),
SI_UPDATE_CANCELLED("UPDATE CANCELLED"),
SI_UPDATE_DECLINED("UPDATE DECLINED"),
SI_UPDATE_CONFIRMED("UPDATE CONFIRMED"),
SI_COMPLETED("COMPLETED"),
;

Expand Down

0 comments on commit d2c6888

Please sign in to comment.