diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/EblScenarioListBuilder.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/EblScenarioListBuilder.java index ada28ab6..4591d3ac 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/EblScenarioListBuilder.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/EblScenarioListBuilder.java @@ -46,7 +46,7 @@ class EblScenarioListBuilder extends ScenarioListBuilder 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"; @@ -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)); @@ -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)); @@ -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)); @@ -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) @@ -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( @@ -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( @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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( @@ -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( @@ -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)) @@ -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) @@ -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( @@ -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))); } @@ -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( @@ -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( @@ -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))); } diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/EblAction.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/EblAction.java index 58ae13ff..f7b8071a 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/EblAction.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/EblAction.java @@ -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); } @@ -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 = @@ -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); @@ -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 DynamicScenarioParameters updateIfNotNull( DynamicScenarioParameters dsp, T value, Function with) { if (value == null) { diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC1_Shipper_SubmitShippingInstructionsAction.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC1_Shipper_SubmitShippingInstructionsAction.java index f4c9cdf6..48cf28a8 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC1_Shipper_SubmitShippingInstructionsAction.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC1_Shipper_SubmitShippingInstructionsAction.java @@ -1,7 +1,6 @@ package org.dcsa.conformance.standards.ebl.action; import com.fasterxml.jackson.databind.node.ObjectNode; -import java.util.Set; import java.util.stream.Stream; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -27,7 +26,7 @@ public UC1_Shipper_SubmitShippingInstructionsAction( JsonSchemaValidator requestSchemaValidator, JsonSchemaValidator responseSchemaValidator, JsonSchemaValidator notificationSchemaValidator) { - super(shipperPartyName, carrierPartyName, previousAction, "UC1", Set.of(201, 202)); + super(shipperPartyName, carrierPartyName, previousAction, "UC1", 202); this.requestSchemaValidator = requestSchemaValidator; this.responseSchemaValidator = responseSchemaValidator; this.notificationSchemaValidator = notificationSchemaValidator; @@ -90,19 +89,12 @@ protected Stream createSubChecks() { EBLChecks.siRequestContentChecks(getMatchedExchangeUuid(), expectedApiVersion, getCspSupplier(), getDspSupplier())); return Stream.concat( primaryExchangeChecks, - Stream.concat( - EBLChecks.siRefStatusContentChecks( - getMatchedExchangeUuid(), - expectedApiVersion, - ShippingInstructionsStatus.SI_RECEIVED, - EBLChecks.SIR_REQUIRED_IN_REF_STATUS - ), - getSINotificationChecks( - getMatchedNotificationExchangeUuid(), - expectedApiVersion, - notificationSchemaValidator, - ShippingInstructionsStatus.SI_RECEIVED, - EBLChecks.SIR_REQUIRED_IN_NOTIFICATION)) + getSINotificationChecks( + getMatchedNotificationExchangeUuid(), + expectedApiVersion, + notificationSchemaValidator, + ShippingInstructionsStatus.SI_RECEIVED, + EBLChecks.SIR_REQUIRED_IN_NOTIFICATION) ); } }; diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC3_Shipper_SubmitUpdatedShippingInstructionsAction.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC3_Shipper_SubmitUpdatedShippingInstructionsAction.java index c82aaa71..96d1b237 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC3_Shipper_SubmitUpdatedShippingInstructionsAction.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC3_Shipper_SubmitUpdatedShippingInstructionsAction.java @@ -1,8 +1,6 @@ package org.dcsa.conformance.standards.ebl.action; import com.fasterxml.jackson.databind.node.ObjectNode; -import java.util.Objects; -import java.util.Set; import java.util.stream.Stream; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -17,8 +15,8 @@ @Getter @Slf4j public class UC3_Shipper_SubmitUpdatedShippingInstructionsAction extends StateChangingSIAction { + private final ShippingInstructionsStatus expectedSiStatus; private final JsonSchemaValidator requestSchemaValidator; - private final JsonSchemaValidator responseSchemaValidator; private final JsonSchemaValidator notificationSchemaValidator; private final boolean useTDRef; @@ -26,14 +24,14 @@ public UC3_Shipper_SubmitUpdatedShippingInstructionsAction( String carrierPartyName, String shipperPartyName, EblAction previousAction, + ShippingInstructionsStatus expectedSiStatus, boolean useTDRef, JsonSchemaValidator requestSchemaValidator, - JsonSchemaValidator responseSchemaValidator, JsonSchemaValidator notificationSchemaValidator) { - super(shipperPartyName, carrierPartyName, previousAction, "UC3" + (useTDRef ? " [TDR]" : ""), Set.of(200, 202)); + super(shipperPartyName, carrierPartyName, previousAction, "UC3" + (useTDRef ? " [TDR]" : ""), 202); this.useTDRef = useTDRef; + this.expectedSiStatus = expectedSiStatus; this.requestSchemaValidator = requestSchemaValidator; - this.responseSchemaValidator = responseSchemaValidator; this.notificationSchemaValidator = notificationSchemaValidator; } @@ -71,10 +69,6 @@ public ConformanceCheck createCheck(String expectedApiVersion) { @Override protected Stream createSubChecks() { var dsp = getDspSupplier().get(); - var currentState = Objects.requireNonNullElse( - dsp.shippingInstructionsStatus(), - ShippingInstructionsStatus.SI_RECEIVED // Placeholder to avoid NPE - ); Stream primaryExchangeChecks = Stream.of( new HttpMethodCheck(EblRole::isShipper, getMatchedExchangeUuid(), "PUT"), @@ -96,29 +90,17 @@ protected Stream createSubChecks() { getMatchedExchangeUuid(), HttpMessageType.REQUEST, requestSchemaValidator), - new JsonSchemaCheck( - EblRole::isCarrier, - getMatchedExchangeUuid(), - HttpMessageType.RESPONSE, - responseSchemaValidator), EBLChecks.siRequestContentChecks(getMatchedExchangeUuid(), expectedApiVersion, getCspSupplier(), getDspSupplier()) ); return Stream.concat( primaryExchangeChecks, - Stream.concat( - EBLChecks.siRefStatusContentChecks( - getMatchedExchangeUuid(), - expectedApiVersion, - currentState, - ShippingInstructionsStatus.SI_UPDATE_RECEIVED, - EBLChecks.sirInRefStatusMustMatchDSP(getDspSupplier())), - getSINotificationChecks( - getMatchedNotificationExchangeUuid(), - expectedApiVersion, - notificationSchemaValidator, - currentState, - ShippingInstructionsStatus.SI_UPDATE_RECEIVED, - EBLChecks.sirInNotificationMustMatchDSP(getDspSupplier()))) + getSINotificationChecks( + getMatchedNotificationExchangeUuid(), + expectedApiVersion, + notificationSchemaValidator, + expectedSiStatus, + ShippingInstructionsStatus.SI_UPDATE_RECEIVED, + EBLChecks.sirInNotificationMustMatchDSP(getDspSupplier())) ); } }; diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC4_Carrier_ProcessUpdateToShippingInstructionsAction.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC4_Carrier_ProcessUpdateToShippingInstructionsAction.java index 4e80b5ba..6accdfba 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC4_Carrier_ProcessUpdateToShippingInstructionsAction.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC4_Carrier_ProcessUpdateToShippingInstructionsAction.java @@ -1,7 +1,7 @@ package org.dcsa.conformance.standards.ebl.action; import com.fasterxml.jackson.databind.node.ObjectNode; -import java.util.Objects; + import java.util.stream.Stream; import lombok.Getter; import org.dcsa.conformance.core.check.*; @@ -12,6 +12,7 @@ @Getter public class UC4_Carrier_ProcessUpdateToShippingInstructionsAction extends StateChangingSIAction { + private final ShippingInstructionsStatus expectedSIStatus; private final JsonSchemaValidator requestSchemaValidator; private final boolean acceptChanges; @@ -19,11 +20,14 @@ public UC4_Carrier_ProcessUpdateToShippingInstructionsAction( String carrierPartyName, String shipperPartyName, EblAction previousAction, + ShippingInstructionsStatus expectedSIStatus, JsonSchemaValidator requestSchemaValidator, boolean acceptChanges) { super(carrierPartyName, shipperPartyName, previousAction, acceptChanges ? "UC4a" : "UC4d", 204); + this.expectedSIStatus = expectedSIStatus; this.requestSchemaValidator = requestSchemaValidator; this.acceptChanges = acceptChanges; + assert !acceptChanges || expectedSIStatus == ShippingInstructionsStatus.SI_RECEIVED; } @Override @@ -56,16 +60,11 @@ public ConformanceCheck createCheck(String expectedApiVersion) { return new ConformanceCheck(getActionTitle()) { @Override protected Stream createSubChecks() { - var dsp = getDspSupplier().get(); - var currentState = Objects.requireNonNullElse( - dsp.shippingInstructionsStatus(), - ShippingInstructionsStatus.SI_RECEIVED // Placeholder to avoid NPE - ); return getSINotificationChecks( getMatchedExchangeUuid(), expectedApiVersion, requestSchemaValidator, - acceptChanges ? ShippingInstructionsStatus.SI_RECEIVED : currentState, + expectedSIStatus, acceptChanges ? ShippingInstructionsStatus.SI_UPDATE_CONFIRMED : ShippingInstructionsStatus.SI_UPDATE_DECLINED, EBLChecks.sirInNotificationMustMatchDSP(getDspSupplier()) ); diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC5_Shipper_CancelUpdateToShippingInstructionsAction.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC5_Shipper_CancelUpdateToShippingInstructionsAction.java index fd8fb771..7985a09c 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC5_Shipper_CancelUpdateToShippingInstructionsAction.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/action/UC5_Shipper_CancelUpdateToShippingInstructionsAction.java @@ -16,23 +16,23 @@ @Getter @Slf4j public class UC5_Shipper_CancelUpdateToShippingInstructionsAction extends StateChangingSIAction { + private final ShippingInstructionsStatus expectedSIStatus; private final boolean useTDRef; private final JsonSchemaValidator requestSchemaValidator; - private final JsonSchemaValidator responseSchemaValidator; private final JsonSchemaValidator notificationSchemaValidator; public UC5_Shipper_CancelUpdateToShippingInstructionsAction( String carrierPartyName, String shipperPartyName, EblAction previousAction, + ShippingInstructionsStatus expectedSIStatus, boolean useTDRef, JsonSchemaValidator requestSchemaValidator, - JsonSchemaValidator responseSchemaValidator, JsonSchemaValidator notificationSchemaValidator) { - super(shipperPartyName, carrierPartyName, previousAction, useTDRef ? "UC5 [TDR]" : "UC5", Set.of(200)); + super(shipperPartyName, carrierPartyName, previousAction, useTDRef ? "UC5 [TDR]" : "UC5", 202); + this.expectedSIStatus = expectedSIStatus; this.useTDRef = useTDRef; this.requestSchemaValidator = requestSchemaValidator; - this.responseSchemaValidator = responseSchemaValidator; this.notificationSchemaValidator = notificationSchemaValidator; } @@ -65,7 +65,6 @@ protected Stream createSubChecks() { var documentReference = useTDRef ? Objects.requireNonNullElse(dsp.transportDocumentReference(), "") : Objects.requireNonNullElse(dsp.shippingInstructionsReference(), ""); - var siStatus = Objects.requireNonNullElse(dsp.shippingInstructionsStatus(), ShippingInstructionsStatus.SI_RECEIVED); Stream primaryExchangeChecks = Stream.of( new HttpMethodCheck(EblRole::isShipper, getMatchedExchangeUuid(), "PATCH"), @@ -86,29 +85,16 @@ protected Stream createSubChecks() { EblRole::isShipper, getMatchedExchangeUuid(), HttpMessageType.REQUEST, - requestSchemaValidator), - new JsonSchemaCheck( - EblRole::isCarrier, - getMatchedExchangeUuid(), - HttpMessageType.RESPONSE, - responseSchemaValidator)); + requestSchemaValidator)); return Stream.concat( primaryExchangeChecks, - Stream.concat( - EBLChecks.siRefStatusContentChecks( - getMatchedExchangeUuid(), - expectedApiVersion, - siStatus, - ShippingInstructionsStatus.SI_UPDATE_CANCELLED, - EBLChecks.sirInRefStatusMustMatchDSP(getDspSupplier()) - ), - getSINotificationChecks( + getSINotificationChecks( getMatchedNotificationExchangeUuid(), expectedApiVersion, notificationSchemaValidator, - siStatus, + expectedSIStatus, ShippingInstructionsStatus.SI_UPDATE_CANCELLED, - EBLChecks.sirInNotificationMustMatchDSP(getDspSupplier())))); + EBLChecks.sirInNotificationMustMatchDSP(getDspSupplier()))); } }; } diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/checks/EBLChecks.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/checks/EBLChecks.java index 50fe5bc0..c657c02b 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/checks/EBLChecks.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/checks/EBLChecks.java @@ -804,10 +804,6 @@ public static ActionCheck siResponseContentChecks(UUID matched, String standardV ); } - public static Stream siRefStatusContentChecks(UUID matched, String standardsVersion, ShippingInstructionsStatus shippingInstructionsStatus, JsonContentCheck ... extraChecks) { - return siRefStatusContentChecks(matched, standardsVersion, shippingInstructionsStatus, null, extraChecks); - } - public static Stream siRefStatusContentChecks(UUID matched, String standardsVersion, ShippingInstructionsStatus shippingInstructionsStatus, ShippingInstructionsStatus updatedShippingInstructionsStatus, JsonContentCheck ... extraChecks) { var updatedStatusCheck = updatedShippingInstructionsStatus != null ? JsonAttribute.mustEqual( diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/DynamicScenarioParameters.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/DynamicScenarioParameters.java index 5408ae13..54ad37c3 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/DynamicScenarioParameters.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/DynamicScenarioParameters.java @@ -17,9 +17,6 @@ public record DynamicScenarioParameters( String transportDocumentReference, JsonNode shippingInstructions, JsonNode updatedShippingInstructions, - ShippingInstructionsStatus shippingInstructionsStatus, - ShippingInstructionsStatus updatedShippingInstructionsStatus, - TransportDocumentStatus transportDocumentStatus, boolean newTransportDocumentContent, JsonNode transportDocument, JsonNode previousTransportDocument) { @@ -28,9 +25,6 @@ public ObjectNode toJson() { .put("scenarioType", scenarioType.name()) .put("shippingInstructionsReference", shippingInstructionsReference) .put("transportDocumentReference", transportDocumentReference) - .put("shippingInstructionsStatus", serializeEnum(shippingInstructionsStatus, ShippingInstructionsStatus::wireName)) - .put("updatedShippingInstructionsStatus", serializeEnum(updatedShippingInstructionsStatus, ShippingInstructionsStatus::wireName)) - .put("transportDocumentStatus", serializeEnum(transportDocumentStatus, TransportDocumentStatus::wireName)) .put("newTransportDocumentContent", newTransportDocumentContent); node.replace("shippingInstructions", shippingInstructions); node.replace("updatedShippingInstructions", updatedShippingInstructions); @@ -60,9 +54,6 @@ public static DynamicScenarioParameters fromJson(JsonNode jsonNode) { jsonNode.path("transportDocumentReference").asText(null), jsonNode.path("shippingInstructions"), jsonNode.path("updatedShippingInstructions"), - readEnum(jsonNode.required("shippingInstructionsStatus").asText(null), ShippingInstructionsStatus::fromWireName), - readEnum(jsonNode.required("updatedShippingInstructionsStatus").asText(null), ShippingInstructionsStatus::fromWireName), - readEnum(jsonNode.required("transportDocumentStatus").asText(null), TransportDocumentStatus::fromWireName), jsonNode.path("newTransportDocumentContent").asBoolean(false), jsonNode.path("transportDocument"), jsonNode.path("previousTransportDocument") diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/EblCarrier.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/EblCarrier.java index 2a2adbc7..d6b47832 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/EblCarrier.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/party/EblCarrier.java @@ -580,8 +580,7 @@ private ConformanceResponse _handlePatchShippingInstructions(ConformanceRequest .build() .asJsonNode()); - return returnShippingInstructionsRefStatusResponse( - 200, + return returnEmpty202Response( request, siData, documentReference @@ -620,27 +619,15 @@ private ConformanceResponse _handlePatchTransportDocument(ConformanceRequest req ); } - private ConformanceResponse returnShippingInstructionsRefStatusResponse( + private ConformanceResponse returnShippingInstructionsReferenceResponse( int responseCode, ConformanceRequest request, ObjectNode shippingInstructions, String documentReference) { var sir = shippingInstructions.required("shippingInstructionsReference").asText(); var siStatus = shippingInstructions.required("shippingInstructionsStatus").asText(); var statusObject = OBJECT_MAPPER .createObjectNode() - .put("shippingInstructionsStatus", siStatus) .put("shippingInstructionsReference", sir); - var tdr = shippingInstructions.path("transportDocumentReference"); - var updatedSiStatus = shippingInstructions.path("updatedShippingInstructionsStatus"); - var reason = shippingInstructions.path("reason"); - if (tdr.isTextual()) { - statusObject.set("transportDocumentReference", tdr); - } - if (updatedSiStatus.isTextual()) { - statusObject.set("updatedShippingInstructionsStatus", updatedSiStatus); - } - if (reason.isTextual()) { - statusObject.set("reason", reason); - } + ConformanceResponse response = request.createResponse( responseCode, @@ -652,6 +639,20 @@ private ConformanceResponse returnShippingInstructionsRefStatusResponse( return response; } + private ConformanceResponse returnEmpty202Response(ConformanceRequest request, ObjectNode shippingInstructions, String documentReference) { + var siStatus = shippingInstructions.required("shippingInstructionsStatus").asText(); + + ConformanceResponse response = + request.createResponse( + 202, + Map.of("Api-Version", List.of(apiVersion)), + new ConformanceMessageBody("")); + addOperatorLogEntry( + "Responded %d to %s SI '%s' (resulting state '%s')" + .formatted(202, request.method(), documentReference, siStatus)); + return response; + } + private ConformanceResponse returnTransportDocumentRefStatusResponse( int responseCode, ConformanceRequest request, ObjectNode transportDocument, String documentReference) { @@ -690,8 +691,8 @@ private ConformanceResponse _handlePostShippingInstructions(ConformanceRequest r .build() .asJsonNode()); - return returnShippingInstructionsRefStatusResponse( - 201, + return returnShippingInstructionsReferenceResponse( + 202, request, siPayload, si.getShippingInstructionsReference() @@ -724,7 +725,11 @@ private ConformanceResponse _handlePutShippingInstructions(ConformanceRequest re .build() .asJsonNode()); - return returnShippingInstructionsRefStatusResponse(200, request, si.getShippingInstructions(), documentReference); + return returnEmpty202Response( + request, + si.getShippingInstructions(), + documentReference + ); } @Override