Skip to content

Commit

Permalink
DT-1540: Migrate to 202 responses in the eBL API
Browse files Browse the repository at this point in the history
  • Loading branch information
nt-gt committed Sep 19, 2024
1 parent dbc514d commit 394400c
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EblScenarioListBuilder extends ScenarioListBuilder<EblScenarioListBuilder>
private static final String PUT_EBL_SCHEMA_NAME = "UpdateShippingInstructions";
private static final String PATCH_SI_SCHEMA_NAME = "shippinginstructions_documentReference_body";
private static final String PATCH_TD_SCHEMA_NAME = "transportdocuments_transportDocumentReference_body";
private static final String EBL_REF_STATUS_SCHEMA_NAME = "ShippingInstructionsRefStatus";
private static final String RESPONSE_POST_SHIPPING_INSTRUCTIONS_SCHEMA_NAME = "Shipping Instructions Response_1";
private static final String TD_REF_STATUS_SCHEMA_NAME = "TransportDocumentRefStatus";
private static final String EBL_SI_NOTIFICATION_SCHEMA_NAME = "ShippingInstructionsNotification";
private static final String EBL_TD_NOTIFICATION_SCHEMA_NAME = "TransportDocumentNotification";
Expand Down Expand Up @@ -178,7 +178,7 @@ private static EblScenarioListBuilder _uc3_get(
ShippingInstructionsStatus originalSiState,
ShippingInstructionsStatus modifiedSiState,
EblScenarioListBuilder... thenEither) {
return uc3_shipper_submitUpdatedShippingInstructions(false)
return uc3_shipper_submitUpdatedShippingInstructions(originalSiState, false)
.then(
shipper_GetShippingInstructions(originalSiState, modifiedSiState, false)
.thenEither(thenEither));
Expand All @@ -198,7 +198,7 @@ private static EblScenarioListBuilder _uc4d_get(
ShippingInstructionsStatus originalSiState,
ShippingInstructionsStatus modifiedSiState,
EblScenarioListBuilder... thenEither) {
return uc4d_carrier_declineUpdatedShippingInstructions()
return uc4d_carrier_declineUpdatedShippingInstructions(originalSiState)
.then(
shipper_GetShippingInstructions(originalSiState, modifiedSiState, false)
.thenEither(thenEither));
Expand All @@ -212,7 +212,7 @@ private static EblScenarioListBuilder _uc5_get(
ShippingInstructionsStatus originalSiState,
ShippingInstructionsStatus modifiedSiState,
EblScenarioListBuilder... thenEither) {
return uc5_shipper_cancelUpdateToShippingInstructions(false)
return uc5_shipper_cancelUpdateToShippingInstructions(originalSiState, false)
.then(
shipper_GetShippingInstructions(originalSiState, modifiedSiState, false)
.thenEither(thenEither));
Expand Down Expand Up @@ -336,7 +336,7 @@ yield then(
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.thenAllPathsFrom(SI_PENDING_UPDATE, transportDocumentStatus, useTDRef)),
uc3_shipper_submitUpdatedShippingInstructions(useTDRef)
uc3_shipper_submitUpdatedShippingInstructions(SI_RECEIVED, useTDRef)
.then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_RECEIVED, useTDRef)
.then(shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_RECEIVED, true, useTDRef)
Expand Down Expand Up @@ -376,7 +376,7 @@ yield thenEither(
.then(shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_CONFIRMED, useTDRef)
.thenHappyPathFrom(SI_RECEIVED, transportDocumentStatus, useTDRef))
)),
uc4d_carrier_declineUpdatedShippingInstructions()
uc4d_carrier_declineUpdatedShippingInstructions(memoryState)
.then(
shipper_GetShippingInstructions(memoryState, SI_UPDATE_DECLINED, useTDRef)
.thenEither(
Expand All @@ -385,7 +385,7 @@ yield thenEither(
.then(shipper_GetShippingInstructions(memoryState, SI_UPDATE_DECLINED, useTDRef)
.thenHappyPathFrom(memoryState, transportDocumentStatus, useTDRef))
)),
uc5_shipper_cancelUpdateToShippingInstructions(useTDRef)
uc5_shipper_cancelUpdateToShippingInstructions(memoryState, useTDRef)
.then(
shipper_GetShippingInstructions(memoryState, SI_UPDATE_CANCELLED, useTDRef)
.thenEither(
Expand All @@ -398,7 +398,7 @@ yield thenEither(
case SI_PENDING_UPDATE -> {
if (transportDocumentStatus != TD_START) {
yield thenEither(
uc3_shipper_submitUpdatedShippingInstructions(useTDRef)
uc3_shipper_submitUpdatedShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, useTDRef)
.then(shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, true, useTDRef)
Expand All @@ -413,13 +413,13 @@ yield thenEither(
// Otherwise, we would never test the UC2 -> UC3 -> UC5 -> ... flow
// because neither UC2 and UC3
// are considered happy paths.
uc5_shipper_cancelUpdateToShippingInstructions(useTDRef)
uc5_shipper_cancelUpdateToShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.then(
shipper_GetShippingInstructions(
SI_PENDING_UPDATE, SI_UPDATE_CANCELLED, useTDRef)
.thenEither(
noAction().thenHappyPathFrom(SI_PENDING_UPDATE, transportDocumentStatus, useTDRef),
uc3_shipper_submitUpdatedShippingInstructions(useTDRef)
uc3_shipper_submitUpdatedShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.then(
shipper_GetShippingInstructions(
SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, useTDRef)
Expand All @@ -440,7 +440,7 @@ yield thenEither(
);
}
yield thenEither(
uc3_shipper_submitUpdatedShippingInstructions(useTDRef)
uc3_shipper_submitUpdatedShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, useTDRef)
.then(shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, true, useTDRef)
Expand All @@ -455,13 +455,13 @@ yield thenEither(
// Otherwise, we would never test the UC2 -> UC3 -> UC5 -> ... flow
// because neither UC2 and UC3
// are considered happy paths.
uc5_shipper_cancelUpdateToShippingInstructions(useTDRef)
uc5_shipper_cancelUpdateToShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.then(
shipper_GetShippingInstructions(
SI_PENDING_UPDATE, SI_UPDATE_CANCELLED, useTDRef)
.thenEither(
noAction().thenHappyPathFrom(SI_PENDING_UPDATE, transportDocumentStatus, useTDRef),
uc3_shipper_submitUpdatedShippingInstructions(useTDRef)
uc3_shipper_submitUpdatedShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.then(
shipper_GetShippingInstructions(
SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, useTDRef)
Expand All @@ -483,7 +483,7 @@ yield thenEither(
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.thenHappyPathFrom(SI_PENDING_UPDATE, transportDocumentStatus, useTDRef)),
uc3_shipper_submitUpdatedShippingInstructions(useTDRef)
uc3_shipper_submitUpdatedShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, useTDRef)
.then(shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, true, useTDRef)
Expand Down Expand Up @@ -530,7 +530,7 @@ private EblScenarioListBuilder thenHappyPathFrom(
default -> throw new IllegalStateException("Unexpected transportDocumentStatus: " + transportDocumentStatus.name());
});
case SI_PENDING_UPDATE -> then(
uc3_shipper_submitUpdatedShippingInstructions(useTDRef)
uc3_shipper_submitUpdatedShippingInstructions(SI_PENDING_UPDATE, useTDRef)
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, useTDRef)
.then(shipper_GetShippingInstructions(SI_PENDING_UPDATE, SI_UPDATE_RECEIVED, true, useTDRef)
Expand Down Expand Up @@ -560,7 +560,7 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
// https://github.com/dcsaorg/Conformance-Gateway/pull/29#discussion_r1421732797
.thenHappyPathFrom(TD_ISSUED)),

uc3_shipper_submitUpdatedShippingInstructions(true).then(
uc3_shipper_submitUpdatedShippingInstructions(SI_RECEIVED, true).then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_RECEIVED, true).then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_RECEIVED, true, true)
.thenEither(
Expand All @@ -577,13 +577,13 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, true)
.thenAllPathsFrom(SI_PENDING_UPDATE, transportDocumentStatus, true)),
uc5_shipper_cancelUpdateToShippingInstructions(true)
uc5_shipper_cancelUpdateToShippingInstructions(SI_RECEIVED, true)
.then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_CANCELLED, true)
.thenHappyPathFrom(transportDocumentStatus))
)
)),
uc3_shipper_submitUpdatedShippingInstructions(false).then(
uc3_shipper_submitUpdatedShippingInstructions(SI_RECEIVED, false).then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_RECEIVED, false).then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_RECEIVED, true, false)
.thenEither(
Expand All @@ -600,11 +600,11 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
.then(
shipper_GetShippingInstructions(SI_PENDING_UPDATE, false)
.thenAllPathsFrom(SI_PENDING_UPDATE, transportDocumentStatus, false)),
uc4d_carrier_declineUpdatedShippingInstructions()
uc4d_carrier_declineUpdatedShippingInstructions(SI_RECEIVED)
.then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_DECLINED, false)
.thenHappyPathFrom(transportDocumentStatus)),
uc5_shipper_cancelUpdateToShippingInstructions(false)
uc5_shipper_cancelUpdateToShippingInstructions(SI_RECEIVED, false)
.then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_CANCELLED, false)
.thenHappyPathFrom(transportDocumentStatus))
Expand All @@ -619,9 +619,9 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
.thenAllPathsFrom(TD_ISSUED))
);
case TD_ISSUED -> thenEither(
uc3_shipper_submitUpdatedShippingInstructions(true)
uc3_shipper_submitUpdatedShippingInstructions(SI_RECEIVED, true)
.thenHappyPathFrom(SI_UPDATE_RECEIVED, TD_ISSUED, true),
uc3_shipper_submitUpdatedShippingInstructions(false)
uc3_shipper_submitUpdatedShippingInstructions(SI_RECEIVED, false)
.thenHappyPathFrom(SI_UPDATE_RECEIVED, TD_ISSUED, false),
uc9_carrier_awaitSurrenderRequestForAmendment()
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_AMENDMENT)
Expand Down Expand Up @@ -809,11 +809,14 @@ private static EblScenarioListBuilder uc1_shipper_submitShippingInstructions() {
shipperPartyName,
(EblAction) previousAction,
resolveMessageSchemaValidator(EBL_API, POST_EBL_SCHEMA_NAME),
resolveMessageSchemaValidator(EBL_API, EBL_REF_STATUS_SCHEMA_NAME),
resolveMessageSchemaValidator(EBL_API, RESPONSE_POST_SHIPPING_INSTRUCTIONS_SCHEMA_NAME),
resolveMessageSchemaValidator(EBL_NOTIFICATIONS_API, EBL_SI_NOTIFICATION_SCHEMA_NAME)));
}

private static EblScenarioListBuilder uc3_shipper_submitUpdatedShippingInstructions(boolean useTDRef) {
private static EblScenarioListBuilder uc3_shipper_submitUpdatedShippingInstructions(
ShippingInstructionsStatus expectedSiStatus,
boolean useTDRef
) {
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
Expand All @@ -822,9 +825,9 @@ private static EblScenarioListBuilder uc3_shipper_submitUpdatedShippingInstructi
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
expectedSiStatus,
useTDRef,
resolveMessageSchemaValidator(EBL_API, PUT_EBL_SCHEMA_NAME),
resolveMessageSchemaValidator(EBL_API, EBL_REF_STATUS_SCHEMA_NAME),
resolveMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_SI_NOTIFICATION_SCHEMA_NAME)));
}
Expand All @@ -851,12 +854,13 @@ private static EblScenarioListBuilder uc4a_carrier_acceptUpdatedShippingInstruct
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
SI_RECEIVED,
resolveMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_SI_NOTIFICATION_SCHEMA_NAME),
true));
}

private static EblScenarioListBuilder uc4d_carrier_declineUpdatedShippingInstructions() {
private static EblScenarioListBuilder uc4d_carrier_declineUpdatedShippingInstructions(ShippingInstructionsStatus shippingInstructionsStatus) {
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
Expand All @@ -865,12 +869,13 @@ private static EblScenarioListBuilder uc4d_carrier_declineUpdatedShippingInstruc
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
shippingInstructionsStatus,
resolveMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_SI_NOTIFICATION_SCHEMA_NAME),
false));
}

private static EblScenarioListBuilder uc5_shipper_cancelUpdateToShippingInstructions(boolean useTDRef) {
private static EblScenarioListBuilder uc5_shipper_cancelUpdateToShippingInstructions(ShippingInstructionsStatus expectedSIStatus, boolean useTDRef) {
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
Expand All @@ -879,11 +884,10 @@ private static EblScenarioListBuilder uc5_shipper_cancelUpdateToShippingInstruct
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
expectedSIStatus,
useTDRef,
resolveMessageSchemaValidator(
EBL_API, PATCH_SI_SCHEMA_NAME),
resolveMessageSchemaValidator(
EBL_API, EBL_REF_STATUS_SCHEMA_NAME),
resolveMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_SI_NOTIFICATION_SCHEMA_NAME)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected EblAction(
this.dspReference =
previousAction == null
? new OverwritingReference<>(
null, new DynamicScenarioParameters(ScenarioType.REGULAR_SWB, null, null, null, null, null, null, null, false, OBJECT_MAPPER.createObjectNode(), OBJECT_MAPPER.createObjectNode()))
null, new DynamicScenarioParameters(ScenarioType.REGULAR_SWB, null, null, null, null, false, OBJECT_MAPPER.createObjectNode(), OBJECT_MAPPER.createObjectNode()))
: new OverwritingReference<>(previousAction.dspReference, null);
}

Expand Down Expand Up @@ -105,14 +105,6 @@ protected void updateDSPFromSIResponsePayload(ConformanceExchange exchange) {
responseJsonNode.path("shippingInstructionsReference").asText(null);
var newTransportDocumentReference =
responseJsonNode.path("transportDocumentReference").asText(null);
var newShippingInstructionsStatus =
parseShippingInstructionsStatus(
responseJsonNode.path("shippingInstructionsStatus").asText(null));
var newUpdatedShippingInstructionsStatus =
parseShippingInstructionsStatus(
responseJsonNode.path("updatedShippingInstructionsStatus").asText(null));
var newTransportDocumentStatus =
parseTransportDocumentStatus(responseJsonNode.path("transportDocumentStatus").asText(null));

var updatedDsp = dsp;
updatedDsp =
Expand All @@ -123,17 +115,6 @@ protected void updateDSPFromSIResponsePayload(ConformanceExchange exchange) {
updatedDsp =
updateIfNotNull(
updatedDsp, newTransportDocumentReference, updatedDsp::withTransportDocumentReference);
updatedDsp =
updateIfNotNull(
updatedDsp, newShippingInstructionsStatus, updatedDsp::withShippingInstructionsStatus);
updatedDsp =
updateIfNotNull(
updatedDsp,
newUpdatedShippingInstructionsStatus,
updatedDsp::withUpdatedShippingInstructionsStatus);
updatedDsp =
updateIfNotNull(
updatedDsp, newTransportDocumentStatus, updatedDsp::withTransportDocumentStatus);

updatedDsp = updateDSPFromSIHook(exchange, updatedDsp);

Expand All @@ -142,30 +123,6 @@ protected void updateDSPFromSIResponsePayload(ConformanceExchange exchange) {
}
}

private static ShippingInstructionsStatus parseShippingInstructionsStatus(String v) {
if (v == null) {
return null;
}
try {
return ShippingInstructionsStatus.fromWireName(v);
} catch (IllegalArgumentException e) {
// Do not assume conformant payload.
return null;
}
}

private static TransportDocumentStatus parseTransportDocumentStatus(String v) {
if (v == null) {
return null;
}
try {
return TransportDocumentStatus.fromWireName(v);
} catch (IllegalArgumentException e) {
// Do not assume conformant payload.
return null;
}
}

private <T> DynamicScenarioParameters updateIfNotNull(
DynamicScenarioParameters dsp, T value, Function<T, DynamicScenarioParameters> with) {
if (value == null) {
Expand Down
Loading

0 comments on commit 394400c

Please sign in to comment.