From 6f80f320fdec715c7a3d6f962398122a0be6abba Mon Sep 17 00:00:00 2001 From: SangeethaPalat Date: Wed, 30 Oct 2024 09:50:24 +0100 Subject: [PATCH 1/3] SD-494-Updating ebl surrender scenarios modified actions --- .../EblSurrenderScenarioListBuilder.java | 36 ++++++++++--------- .../SupplyScenarioParametersAction.java | 19 ++++++++-- ...va => SurrenderRequestResponseAction.java} | 11 ++++-- .../party/EblSurrenderCarrier.java | 18 ++++++++-- .../party/EblSurrenderPlatform.java | 12 ++++--- 5 files changed, 69 insertions(+), 27 deletions(-) rename ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/{SurrenderRequestAction.java => SurrenderRequestResponseAction.java} (95%) diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java index d27dad4d..bc2befe9 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java @@ -4,11 +4,10 @@ import org.dcsa.conformance.core.scenario.ConformanceAction; import org.dcsa.conformance.core.scenario.ScenarioListBuilder; import org.dcsa.conformance.standards.eblsurrender.action.SupplyScenarioParametersAction; -import org.dcsa.conformance.standards.eblsurrender.action.SurrenderRequestAction; +import org.dcsa.conformance.standards.eblsurrender.action.SurrenderRequestResponseAction; import org.dcsa.conformance.standards.eblsurrender.action.SurrenderResponseAction; import org.dcsa.conformance.standards.eblsurrender.action.VoidAndReissueAction; import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole; -import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderState; import java.util.LinkedHashMap; import java.util.Map; @@ -16,8 +15,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderState.*; - @Slf4j class EblSurrenderScenarioListBuilder extends ScenarioListBuilder { @@ -35,18 +32,25 @@ class EblSurrenderScenarioListBuilder threadLocalCarrierPartyName.set(carrierPartyName); threadLocalPlatformPartyName.set(platformPartyName); return Stream.of( - Map.entry("", supplyAvailableTdrAction().thenAllPathsFrom(AVAILABLE_FOR_SURRENDER))) + Map.entry("Surrender for Delivery", supplyAvailableTdrAction("SURR","Straight eBL").then(requestSurrenderForDeliveryAndAccepted(204)))) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); } - private EblSurrenderScenarioListBuilder thenAllPathsFrom( + /*private EblSurrenderScenarioListBuilder thenAllPathsFrom( EblSurrenderState surrenderState) { return switch (surrenderState) { case AVAILABLE_FOR_SURRENDER -> thenEither( requestSurrenderForDelivery(204).thenAllPathsFrom(DELIVERY_SURRENDER_REQUESTED), requestSurrenderForAmendment(204).thenAllPathsFrom(AMENDMENT_SURRENDER_REQUESTED) + + //requestSurrenderForDeliveryAndAccepted() + //requestSurrenderForDeliveryAndRejected() + //requestSurrenderForAmendmentAndAccepted() + //requestSurrenderForAmendmentAndRejected() + //requestSurrenderForSwitchToPaperAndAccepted() + //requestSurrenderForSwitchToPaperAndRejected() ); case DELIVERY_SURRENDER_REQUESTED -> thenEither( acceptSurrenderRequest(204).thenAllPathsFrom(SURRENDERED_FOR_DELIVERY), @@ -69,9 +73,9 @@ private EblSurrenderScenarioListBuilder thenAllPathsFrom( voidAndReissue().thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER) ); }; - } + }*/ - private EblSurrenderScenarioListBuilder thenAllHappyPathsFrom( + /*private EblSurrenderScenarioListBuilder thenAllHappyPathsFrom( EblSurrenderState surrenderState) { var cases = switch (surrenderState) { case AVAILABLE_FOR_SURRENDER -> requestSurrenderForDelivery(204).thenAllHappyPathsFrom(DELIVERY_SURRENDER_REQUESTED); @@ -82,13 +86,13 @@ private EblSurrenderScenarioListBuilder thenAllHappyPathsFrom( case SURRENDERED_FOR_AMENDMENT -> voidAndReissue().thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER); }; return thenEither(cases); - } + }*/ private EblSurrenderScenarioListBuilder noAction() { return new EblSurrenderScenarioListBuilder(null); } - private EblSurrenderScenarioListBuilder thenAnyRequest(int status) { + /*private EblSurrenderScenarioListBuilder thenAnyRequest(int status) { return thenEither( noAction(), requestSurrenderForAmendment(status), @@ -96,13 +100,13 @@ private EblSurrenderScenarioListBuilder thenAnyRequest(int status) { rejectSurrenderRequest(status), acceptSurrenderRequest(status) ); - } + }*/ - private static EblSurrenderScenarioListBuilder supplyAvailableTdrAction() { + private static EblSurrenderScenarioListBuilder supplyAvailableTdrAction(String response, String eblType) { log.debug("EblSurrenderScenarioListBuilder.supplyAvailableTdrAction()"); String carrierPartyName = threadLocalCarrierPartyName.get(); return new EblSurrenderScenarioListBuilder( - noPreviousAction -> new SupplyScenarioParametersAction(carrierPartyName, null)); + noPreviousAction -> new SupplyScenarioParametersAction(carrierPartyName, null,response, eblType)); } private EblSurrenderScenarioListBuilder( @@ -116,7 +120,7 @@ private static EblSurrenderScenarioListBuilder requestSurrenderForAmendment(int return _surrenderRequestBuilder(true, status); } - private static EblSurrenderScenarioListBuilder requestSurrenderForDelivery(int status) { + private static EblSurrenderScenarioListBuilder requestSurrenderForDeliveryAndAccepted(int status) { log.debug( "EblSurrenderScenarioListBuilder.requestSurrenderForDelivery(%d)".formatted(status)); return _surrenderRequestBuilder(false, status); @@ -129,7 +133,7 @@ private static EblSurrenderScenarioListBuilder _surrenderRequestBuilder( String platformPartyName = threadLocalPlatformPartyName.get(); return new EblSurrenderScenarioListBuilder( previousAction -> - new SurrenderRequestAction( + new SurrenderRequestResponseAction( forAmendment, platformPartyName, carrierPartyName, @@ -167,7 +171,7 @@ private static EblSurrenderScenarioListBuilder _surrenderResponseBuilder( EblSurrenderRole.PLATFORM.getConfigName(), true))); } - private static EblSurrenderScenarioListBuilder voidAndReissue() { + private static EblSurrenderScenarioListBuilder voidAndReissue() { log.debug("EblSurrenderScenarioListBuilder.voidAndReissue()"); String carrierPartyName = threadLocalCarrierPartyName.get(); String platformPartyName = threadLocalPlatformPartyName.get(); diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java index 03731c00..98081bdf 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java @@ -12,9 +12,13 @@ @Getter public class SupplyScenarioParametersAction extends ConformanceAction { private SuppliedScenarioParameters suppliedScenarioParameters = null; + private String response; + private String eblType; - public SupplyScenarioParametersAction(String carrierPartyName, ConformanceAction previousAction) { + public SupplyScenarioParametersAction(String carrierPartyName, ConformanceAction previousAction, String response, String eblType) { super(carrierPartyName, null, previousAction, "SupplyTDR"); + this.response = response; + this.eblType = eblType; } @Override @@ -29,6 +33,8 @@ public ObjectNode exportJsonState() { if (suppliedScenarioParameters != null) { jsonState.set("suppliedScenarioParameters", suppliedScenarioParameters.toJson()); } + jsonState.put("response",response); + jsonState.put("eblType",eblType); return jsonState; } @@ -39,12 +45,14 @@ public void importJsonState(JsonNode jsonState) { if (sspNode != null) { suppliedScenarioParameters = SuppliedScenarioParameters.fromJson(sspNode); } + response = jsonState.get("response").asText(); + eblType = jsonState.get("eblType").asText(); } @Override public String getHumanReadablePrompt() { return "Use the following format to provide the transport document reference and additional info " - + "of a straight eBL for which your party can accept a surrender request:"; + + "of a"+ eblType +"for which your party can accept a surrender request:"; } @Override @@ -78,4 +86,11 @@ public void handlePartyInput(JsonNode partyInput) { super.handlePartyInput(partyInput); suppliedScenarioParameters = SuppliedScenarioParameters.fromJson(partyInput.get("input")); } + + @Override + public ObjectNode asJsonNode() { + return super.asJsonNode() + .put("eblType", eblType) + .put("response", response); + } } diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestAction.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java similarity index 95% rename from ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestAction.java rename to ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java index f3a3e1f6..72e15b2c 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestAction.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java @@ -19,7 +19,7 @@ @Getter @Slf4j -public class SurrenderRequestAction extends EblSurrenderAction { +public class SurrenderRequestResponseAction extends EblSurrenderAction { private final JsonSchemaValidator requestSchemaValidator; private final boolean forAmendment; @@ -27,7 +27,7 @@ public class SurrenderRequestAction extends EblSurrenderAction { private final Supplier srrSupplier = surrenderRequestReference::get; - public SurrenderRequestAction( + public SurrenderRequestResponseAction( boolean forAmendment, String platformPartyName, String carrierPartyName, @@ -67,7 +67,12 @@ public void importJsonState(JsonNode jsonState) { public String getHumanReadablePrompt() { return ("Send a surrender request for %s " + "for the eBL with the transport document reference '%s'") - .formatted(forAmendment ? "amendment" : "delivery", sspSupplier.get()); + .formatted(forAmendment ? "amendment" : "delivery", sspSupplier.get().transportDocumentReference()); + } + + @Override + protected boolean expectsNotificationExchange() { + return true; } @Override diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java index c7a1c461..ebfde812 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java @@ -74,7 +74,7 @@ protected void doReset() { protected Map, Consumer> getActionPromptHandlers() { return Map.ofEntries( Map.entry(SupplyScenarioParametersAction.class, this::supplyScenarioParameters), - Map.entry(SurrenderResponseAction.class, this::sendSurrenderResponse), + //Map.entry(SurrenderResponseAction.class, this::sendSurrenderResponse), Map.entry(VoidAndReissueAction.class, this::voidAndReissue)); } @@ -85,7 +85,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { String tdr = UUID.randomUUID().toString().replace("-", "").substring(0, 20); eblStatesById.put(tdr, EblSurrenderState.AVAILABLE_FOR_SURRENDER); - + persistentMap.save("response",actionPrompt.get("response")); var issueToParty = OBJECT_MAPPER.createObjectNode(); issueToParty.put("partyName", "Issue To name") .put("eblPlatform", "WAVE"); @@ -167,6 +167,20 @@ public ConformanceResponse handleRequest(ConformanceRequest request) { String srr = jsonRequest.get("surrenderRequestReference").asText(); String tdr = jsonRequest.get("transportDocumentReference").asText(); + JsonNode responseCode = null; + if ("*".equals(srr)) { + srr = UUID.randomUUID().toString(); + } + if(persistentMap.load("response") != null){ + responseCode = persistentMap.load("response"); + } + asyncCounterpartNotification(null, + "/v%s/ebl-surrender-responses".formatted(apiVersion.charAt(0)), + OBJECT_MAPPER + .createObjectNode() + .put("surrenderRequestReference", srr) + .put("action", responseCode)); +//.put("action", accept ? "SURR" : "SREJ")); if (Objects.equals( EblSurrenderState.AVAILABLE_FOR_SURRENDER, eblStatesById.getOrDefault( diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java index 50c85a74..b0e2f0b5 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java @@ -19,7 +19,7 @@ import org.dcsa.conformance.core.traffic.ConformanceMessageBody; import org.dcsa.conformance.core.traffic.ConformanceRequest; import org.dcsa.conformance.core.traffic.ConformanceResponse; -import org.dcsa.conformance.standards.eblsurrender.action.SurrenderRequestAction; +import org.dcsa.conformance.standards.eblsurrender.action.SurrenderRequestResponseAction; @Slf4j public class EblSurrenderPlatform extends ConformanceParty { @@ -65,7 +65,7 @@ protected void doReset() { @Override protected Map, Consumer> getActionPromptHandlers() { - return Map.ofEntries(Map.entry(SurrenderRequestAction.class, this::requestSurrender)); + return Map.ofEntries(Map.entry(SurrenderRequestResponseAction.class, this::requestSurrender)); } private void requestSurrender(JsonNode actionPrompt) { @@ -151,9 +151,13 @@ public ConformanceResponse handleRequest(ConformanceRequest request) { "Rejecting '%s' for document '%s' because it is in state '%s'" .formatted(action, tdr, eblStatesById.get(tdr))))); } - addOperatorLogEntry( + /*addOperatorLogEntry( "Handling surrender response with action '%s' and surrenderRequestReference '%s' for eBL with transportDocumentReference '%s' (now in state '%s')" - .formatted(action, srr, tdr, eblStatesById.get(tdr))); + .formatted(action, srr, tdr, eblStatesById.get(tdr)));*/ + + addOperatorLogEntry( + "Handling notification with action '%s' and surrenderRequestReference '%s' for eBL with transportDocumentReference '%s' (now in state '%s')" + .formatted(action, srr, tdr, eblStatesById.get(tdr))); return response; } } From a5b6b9878f7fd76397474693cf589b3fef3db496 Mon Sep 17 00:00:00 2001 From: SangeethaPalat Date: Wed, 30 Oct 2024 16:55:32 +0100 Subject: [PATCH 2/3] SD-494-EBL-surrender-updated scenarios and checks --- .../EblSurrenderScenarioListBuilder.java | 48 ++++++++++++++----- .../SupplyScenarioParametersAction.java | 8 ++-- .../SurrenderRequestResponseAction.java | 47 ++++++++++++++++-- .../party/EblSurrenderCarrier.java | 17 ++++--- .../party/EblSurrenderPlatform.java | 4 ++ 5 files changed, 98 insertions(+), 26 deletions(-) diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java index bc2befe9..bb63799a 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java @@ -32,7 +32,30 @@ class EblSurrenderScenarioListBuilder threadLocalCarrierPartyName.set(carrierPartyName); threadLocalPlatformPartyName.set(platformPartyName); return Stream.of( - Map.entry("Surrender for Delivery", supplyAvailableTdrAction("SURR","Straight eBL").then(requestSurrenderForDeliveryAndAccepted(204)))) + Map.entry( + "Surrender Accepted", + noAction() + .thenEither( + supplyAvailableTdrAction("SURR", "Straight eBL") + .thenEither( + requestSurrenderForDeliveryAnd(true), + requestSurrenderForAmendmentAnd( true)), + supplyAvailableTdrAction("SURR", "Negotiable eBL") + .thenEither( + requestSurrenderForDeliveryAnd( true), + requestSurrenderForAmendmentAnd( true)))), + Map.entry( + "Surrender Rejected", + noAction() + .thenEither( + supplyAvailableTdrAction("SREJ", "Straight eBL") + .thenEither( + requestSurrenderForDeliveryAnd( false), + requestSurrenderForAmendmentAnd(false)), + supplyAvailableTdrAction("SREJ", "Negotiable eBL") + .thenEither( + requestSurrenderForDeliveryAnd(false), + requestSurrenderForAmendmentAnd( false))))) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); @@ -88,7 +111,7 @@ class EblSurrenderScenarioListBuilder return thenEither(cases); }*/ - private EblSurrenderScenarioListBuilder noAction() { + private static EblSurrenderScenarioListBuilder noAction() { return new EblSurrenderScenarioListBuilder(null); } @@ -114,20 +137,22 @@ private EblSurrenderScenarioListBuilder( super(actionBuilder); } - private static EblSurrenderScenarioListBuilder requestSurrenderForAmendment(int status) { + private static EblSurrenderScenarioListBuilder requestSurrenderForAmendmentAnd(boolean accept) { log.debug( - "EblSurrenderScenarioListBuilder.requestSurrenderForAmendment(%d)".formatted(status)); - return _surrenderRequestBuilder(true, status); + "EblSurrenderScenarioListBuilder.requestSurrenderForAmendment"); + String titleSuffix = accept ? "Accepted" : "Rejected"; + return _surrenderRequestBuilder(true,accept,"SurrenderForAmendment"+titleSuffix); } - private static EblSurrenderScenarioListBuilder requestSurrenderForDeliveryAndAccepted(int status) { + private static EblSurrenderScenarioListBuilder requestSurrenderForDeliveryAnd( boolean accept) { log.debug( - "EblSurrenderScenarioListBuilder.requestSurrenderForDelivery(%d)".formatted(status)); - return _surrenderRequestBuilder(false, status); + "EblSurrenderScenarioListBuilder.requestSurrenderForDelivery"); + String titleSuffix = accept ? "Accepted" : "Rejected"; + return _surrenderRequestBuilder(false, accept, "SurrenderForDeliveryAnd"+titleSuffix); } private static EblSurrenderScenarioListBuilder _surrenderRequestBuilder( - boolean forAmendment, int expectedStatus) { + boolean forAmendment,boolean accept, String title) { EblSurrenderComponentFactory componentFactory = threadLocalComponentFactory.get(); String carrierPartyName = threadLocalCarrierPartyName.get(); String platformPartyName = threadLocalPlatformPartyName.get(); @@ -137,10 +162,11 @@ private static EblSurrenderScenarioListBuilder _surrenderRequestBuilder( forAmendment, platformPartyName, carrierPartyName, - expectedStatus, + 204, previousAction, componentFactory.getMessageSchemaValidator( - EblSurrenderRole.CARRIER.getConfigName(), true)) + EblSurrenderRole.CARRIER.getConfigName(), true),componentFactory.getMessageSchemaValidator( + EblSurrenderRole.PLATFORM.getConfigName(),true),accept, title) ); } diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java index 98081bdf..e3a71e08 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java @@ -16,7 +16,7 @@ public class SupplyScenarioParametersAction extends ConformanceAction { private String eblType; public SupplyScenarioParametersAction(String carrierPartyName, ConformanceAction previousAction, String response, String eblType) { - super(carrierPartyName, null, previousAction, "SupplyTDR"); + super(carrierPartyName, null, previousAction, "SupplyTDR[%s]".formatted(eblType)); this.response = response; this.eblType = eblType; } @@ -51,15 +51,17 @@ public void importJsonState(JsonNode jsonState) { @Override public String getHumanReadablePrompt() { + String responseAction = response.equals("SURR")?"accept":"reject"; return "Use the following format to provide the transport document reference and additional info " - + "of a"+ eblType +"for which your party can accept a surrender request:"; + + "of a "+ eblType +" for which your party can "+responseAction+ " a surrender request:"; } @Override public JsonNode getJsonForHumanReadablePrompt() { + String eblPlatform = response.equals("SURR")?"WAVE":"WAVER"; var issueToParty = OBJECT_MAPPER.createObjectNode(); issueToParty.put("partyName", "Issue To name") - .put("eblPlatform", "WAVE"); + .put("eblPlatform", eblPlatform); var carrierParty = OBJECT_MAPPER.createObjectNode(); carrierParty.put("partyName", "Carrier name") .put("eblPlatform", "WAVE"); diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java index 72e15b2c..739dfaa4 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java @@ -21,7 +21,9 @@ @Slf4j public class SurrenderRequestResponseAction extends EblSurrenderAction { private final JsonSchemaValidator requestSchemaValidator; + private final JsonSchemaValidator responseSchemaValidator; private final boolean forAmendment; + private final boolean accept; private final AtomicReference surrenderRequestReference = new AtomicReference<>(); @@ -33,15 +35,19 @@ public SurrenderRequestResponseAction( String carrierPartyName, int expectedStatus, ConformanceAction previousAction, - JsonSchemaValidator requestSchemaValidator) { + JsonSchemaValidator requestSchemaValidator, + JsonSchemaValidator responseSchemaValidator, + boolean accept, + String title) { super( platformPartyName, carrierPartyName, expectedStatus, - previousAction, - "%s %d".formatted(forAmendment ? "AREQ" : "SREQ", expectedStatus)); + previousAction,title); //"%s %d".formatted(forAmendment ? "AREQ" : "SREQ" this.forAmendment = forAmendment; this.requestSchemaValidator = requestSchemaValidator; + this.responseSchemaValidator = responseSchemaValidator; + this.accept = accept; } @Override @@ -99,7 +105,7 @@ public ConformanceCheck createCheck(String expectedApiVersion) { return new ConformanceCheck(getActionTitle()) { @Override protected Stream createSubChecks() { - return Stream.of( + return Stream.concat(Stream.of( new UrlPathCheck( EblSurrenderRole::isPlatform, getMatchedExchangeUuid(), "/ebl-surrender-requests"), new ResponseStatusCheck( @@ -131,7 +137,38 @@ protected Stream createSubChecks() { getMatchedExchangeUuid(), HttpMessageType.REQUEST, JsonPointer.compile("/transportDocumentReference"), - sspSupplier.get() == null ? null : sspSupplier.get().transportDocumentReference())); + sspSupplier.get() == null ? null : sspSupplier.get().transportDocumentReference())), + Stream.of( + new UrlPathCheck("[Response]", + EblSurrenderRole::isCarrier, + getMatchedNotificationExchangeUuid(), + "/ebl-surrender-responses"), + new ResponseStatusCheck("[Response]", + EblSurrenderRole::isPlatform, getMatchedNotificationExchangeUuid(), getExpectedStatus()), + new ApiHeaderCheck( + EblSurrenderRole::isPlatform, + getMatchedNotificationExchangeUuid(), + HttpMessageType.RESPONSE, + expectedApiVersion), + new JsonSchemaCheck("[Response]", + EblSurrenderRole::isCarrier, + getMatchedNotificationExchangeUuid(), + HttpMessageType.REQUEST, + responseSchemaValidator), + new JsonAttributeCheck("[Response]", + EblSurrenderRole::isCarrier, + getMatchedNotificationExchangeUuid(), + HttpMessageType.REQUEST, + JsonPointer.compile("/action"), + accept ? "SURR" : "SREJ") + /*expectedSrr == null || expectedSrr.equals("*") + ? null + : new JsonAttributeCheck( + EblSurrenderRole::isCarrier, + getMatchedExchangeUuid(), + HttpMessageType.REQUEST, + JsonPointer.compile("/surrenderRequestReference"), + expectedSrr)*/)); } }; } diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java index ebfde812..fe9590c7 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java @@ -166,20 +166,23 @@ public ConformanceResponse handleRequest(ConformanceRequest request) { String src = jsonRequest.get("surrenderRequestCode").asText(); String srr = jsonRequest.get("surrenderRequestReference").asText(); String tdr = jsonRequest.get("transportDocumentReference").asText(); + String action = tdr.contains("WAVER") ? "SREJ":"SURR"; - JsonNode responseCode = null; + String responseCode = null; if ("*".equals(srr)) { srr = UUID.randomUUID().toString(); } if(persistentMap.load("response") != null){ - responseCode = persistentMap.load("response"); + action = persistentMap.load("response").asText(); } + + var carrierResponse = OBJECT_MAPPER + .createObjectNode() + .put("surrenderRequestReference", srr) + .put("action", action); asyncCounterpartNotification(null, - "/v%s/ebl-surrender-responses".formatted(apiVersion.charAt(0)), - OBJECT_MAPPER - .createObjectNode() - .put("surrenderRequestReference", srr) - .put("action", responseCode)); + "/v3/ebl-surrender-responses",carrierResponse); + //.put("action", accept ? "SURR" : "SREJ")); if (Objects.equals( EblSurrenderState.AVAILABLE_FOR_SURRENDER, diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java index b0e2f0b5..2795c2bf 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java @@ -76,6 +76,10 @@ private void requestSurrender(JsonNode actionPrompt) { String tdr = ssp.transportDocumentReference(); boolean forAmendment = actionPrompt.get("forAmendment").booleanValue(); String src = forAmendment ? "AREQ" : "SREQ"; + String action = ssp.issueToParty().get("eblPlatform") != null? ssp.issueToParty().get("eblPlatform").asText() : null; + if(action != null && action.equals("WAVER")){ + tdr = tdr+action; + } tdrsBySrr.put(srr, tdr); eblStatesById.put( tdr, From af5eba8242faae2a4bed4e095e0dbb8dd433393f Mon Sep 17 00:00:00 2001 From: SangeethaPalat Date: Thu, 31 Oct 2024 17:03:28 +0100 Subject: [PATCH 3/3] SD-494-EBL surrender scenarios updated --- .../EblSurrenderComponentFactory.java | 13 +- .../EblSurrenderScenarioListBuilder.java | 170 +++++------------- .../eblsurrender/EblSurrenderStandard.java | 4 +- .../eblsurrender/SurrenderChecks.java | 8 +- .../SupplyScenarioParametersAction.java | 4 +- .../SurrenderRequestResponseAction.java | 161 +++++++++-------- .../action/SurrenderResponseAction.java | 121 ------------- .../action/VoidAndReissueAction.java | 56 ------ .../party/EblSurrenderCarrier.java | 91 ++-------- .../party/EblSurrenderPlatform.java | 30 ++-- .../eblsurrender/party/EblSurrenderState.java | 10 +- .../eblsurrender-api-v3.0.0-request.json | 2 +- 12 files changed, 179 insertions(+), 491 deletions(-) delete mode 100644 ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderResponseAction.java delete mode 100644 ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/VoidAndReissueAction.java diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderComponentFactory.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderComponentFactory.java index 016a7f59..c22602e0 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderComponentFactory.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderComponentFactory.java @@ -99,16 +99,15 @@ public Set getReportRoleNames( public JsonSchemaValidator getMessageSchemaValidator(String apiProviderRole, boolean forRequest) { String schemaFilePath = - "/standards/eblsurrender/schemas/eblsurrender-v%s.json" - .formatted( - standardVersion); + "/standards/eblsurrender/schemas/eblsurrender-v%s.json".formatted(standardVersion); String schemaName = - EblSurrenderRole.isCarrier(apiProviderRole) - ? (forRequest ? "SurrenderRequestDetails" : null) - : (forRequest ? "SurrenderRequestAnswer" : null); + EblSurrenderRole.isCarrier(apiProviderRole) + ? (forRequest ? "SurrenderRequestDetails" : null) + : (forRequest ? "SurrenderRequestAnswer" : null); if (schemaName == null) { - throw new IllegalArgumentException("No schema for " + apiProviderRole + " (forRequest=" + forRequest + ")"); + throw new IllegalArgumentException( + "No schema for " + apiProviderRole + " (forRequest=" + forRequest + ")"); } return JsonSchemaValidator.getInstance(schemaFilePath, schemaName); } diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java index bb63799a..9b1bd4d1 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderScenarioListBuilder.java @@ -1,28 +1,29 @@ package org.dcsa.conformance.standards.eblsurrender; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; import org.dcsa.conformance.core.scenario.ConformanceAction; import org.dcsa.conformance.core.scenario.ScenarioListBuilder; import org.dcsa.conformance.standards.eblsurrender.action.SupplyScenarioParametersAction; import org.dcsa.conformance.standards.eblsurrender.action.SurrenderRequestResponseAction; -import org.dcsa.conformance.standards.eblsurrender.action.SurrenderResponseAction; -import org.dcsa.conformance.standards.eblsurrender.action.VoidAndReissueAction; import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - @Slf4j -class EblSurrenderScenarioListBuilder - extends ScenarioListBuilder { +class EblSurrenderScenarioListBuilder extends ScenarioListBuilder { private static final ThreadLocal threadLocalComponentFactory = new ThreadLocal<>(); private static final ThreadLocal threadLocalCarrierPartyName = new ThreadLocal<>(); private static final ThreadLocal threadLocalPlatformPartyName = new ThreadLocal<>(); + private EblSurrenderScenarioListBuilder( + Function actionBuilder) { + super(actionBuilder); + } + public static LinkedHashMap createModuleScenarioListBuilders( EblSurrenderComponentFactory componentFactory, @@ -39,120 +40,62 @@ class EblSurrenderScenarioListBuilder supplyAvailableTdrAction("SURR", "Straight eBL") .thenEither( requestSurrenderForDeliveryAnd(true), - requestSurrenderForAmendmentAnd( true)), + requestSurrenderForAmendmentAnd(true, false), + requestSurrenderForAmendmentAnd(true, true)), supplyAvailableTdrAction("SURR", "Negotiable eBL") .thenEither( - requestSurrenderForDeliveryAnd( true), - requestSurrenderForAmendmentAnd( true)))), + requestSurrenderForDeliveryAnd(true), + requestSurrenderForAmendmentAnd(true, false), + requestSurrenderForAmendmentAnd(true, true)))), Map.entry( "Surrender Rejected", noAction() .thenEither( supplyAvailableTdrAction("SREJ", "Straight eBL") .thenEither( - requestSurrenderForDeliveryAnd( false), - requestSurrenderForAmendmentAnd(false)), + requestSurrenderForDeliveryAnd(false), + requestSurrenderForAmendmentAnd(false, false), + requestSurrenderForAmendmentAnd(false, true)), supplyAvailableTdrAction("SREJ", "Negotiable eBL") .thenEither( requestSurrenderForDeliveryAnd(false), - requestSurrenderForAmendmentAnd( false))))) + requestSurrenderForAmendmentAnd(false, false), + requestSurrenderForAmendmentAnd(false, true))))) .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); } - /*private EblSurrenderScenarioListBuilder thenAllPathsFrom( - EblSurrenderState surrenderState) { - return switch (surrenderState) { - case AVAILABLE_FOR_SURRENDER -> thenEither( - requestSurrenderForDelivery(204).thenAllPathsFrom(DELIVERY_SURRENDER_REQUESTED), - requestSurrenderForAmendment(204).thenAllPathsFrom(AMENDMENT_SURRENDER_REQUESTED) - - //requestSurrenderForDeliveryAndAccepted() - //requestSurrenderForDeliveryAndRejected() - //requestSurrenderForAmendmentAndAccepted() - //requestSurrenderForAmendmentAndRejected() - //requestSurrenderForSwitchToPaperAndAccepted() - //requestSurrenderForSwitchToPaperAndRejected() - ); - case DELIVERY_SURRENDER_REQUESTED -> thenEither( - acceptSurrenderRequest(204).thenAllPathsFrom(SURRENDERED_FOR_DELIVERY), - rejectSurrenderRequest(204).thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER), - requestSurrenderForAmendment(409).thenAllHappyPathsFrom(DELIVERY_SURRENDER_REQUESTED), - requestSurrenderForDelivery(409).thenAllHappyPathsFrom(DELIVERY_SURRENDER_REQUESTED) - ); - case SURRENDERED_FOR_DELIVERY -> thenAnyRequest(409); - case AMENDMENT_SURRENDER_REQUESTED -> thenEither( - acceptSurrenderRequest(204).thenAllPathsFrom(SURRENDERED_FOR_AMENDMENT), - rejectSurrenderRequest(204).thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER), - requestSurrenderForAmendment(409).thenAllHappyPathsFrom(AMENDMENT_SURRENDER_REQUESTED), - requestSurrenderForDelivery(409).thenAllHappyPathsFrom(AMENDMENT_SURRENDER_REQUESTED) - ); - case SURRENDERED_FOR_AMENDMENT -> thenEither( - acceptSurrenderRequest(409).thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT), - rejectSurrenderRequest(409).thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT), - requestSurrenderForAmendment(409).thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT), - requestSurrenderForDelivery(409).thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT), - voidAndReissue().thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER) - ); - }; - }*/ - - /*private EblSurrenderScenarioListBuilder thenAllHappyPathsFrom( - EblSurrenderState surrenderState) { - var cases = switch (surrenderState) { - case AVAILABLE_FOR_SURRENDER -> requestSurrenderForDelivery(204).thenAllHappyPathsFrom(DELIVERY_SURRENDER_REQUESTED); - case DELIVERY_SURRENDER_REQUESTED -> acceptSurrenderRequest(204); - case SURRENDERED_FOR_DELIVERY -> noAction(); - case AMENDMENT_SURRENDER_REQUESTED -> acceptSurrenderRequest(204) - .thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT); - case SURRENDERED_FOR_AMENDMENT -> voidAndReissue().thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER); - }; - return thenEither(cases); - }*/ - private static EblSurrenderScenarioListBuilder noAction() { return new EblSurrenderScenarioListBuilder(null); } - /*private EblSurrenderScenarioListBuilder thenAnyRequest(int status) { - return thenEither( - noAction(), - requestSurrenderForAmendment(status), - requestSurrenderForDelivery(status), - rejectSurrenderRequest(status), - acceptSurrenderRequest(status) - ); - }*/ - - private static EblSurrenderScenarioListBuilder supplyAvailableTdrAction(String response, String eblType) { + private static EblSurrenderScenarioListBuilder supplyAvailableTdrAction( + String response, String eblType) { log.debug("EblSurrenderScenarioListBuilder.supplyAvailableTdrAction()"); String carrierPartyName = threadLocalCarrierPartyName.get(); return new EblSurrenderScenarioListBuilder( - noPreviousAction -> new SupplyScenarioParametersAction(carrierPartyName, null,response, eblType)); + noPreviousAction -> + new SupplyScenarioParametersAction(carrierPartyName, null, response, eblType)); } - private EblSurrenderScenarioListBuilder( - Function actionBuilder) { - super(actionBuilder); - } + private static EblSurrenderScenarioListBuilder requestSurrenderForAmendmentAnd( + boolean accept, boolean isSWTP) { + log.debug("EblSurrenderScenarioListBuilder.requestSurrenderForAmendment"); - private static EblSurrenderScenarioListBuilder requestSurrenderForAmendmentAnd(boolean accept) { - log.debug( - "EblSurrenderScenarioListBuilder.requestSurrenderForAmendment"); - String titleSuffix = accept ? "Accepted" : "Rejected"; - return _surrenderRequestBuilder(true,accept,"SurrenderForAmendment"+titleSuffix); + String titleSuffix = isSWTP ? "AndSwitchToPaper" : ""; + titleSuffix = accept ? titleSuffix + "Accepted" : titleSuffix + "Rejected"; + return _surrenderRequestBuilder(true, accept, "SurrenderForAmendment" + titleSuffix, isSWTP); } - private static EblSurrenderScenarioListBuilder requestSurrenderForDeliveryAnd( boolean accept) { - log.debug( - "EblSurrenderScenarioListBuilder.requestSurrenderForDelivery"); + private static EblSurrenderScenarioListBuilder requestSurrenderForDeliveryAnd(boolean accept) { + log.debug("EblSurrenderScenarioListBuilder.requestSurrenderForDelivery"); String titleSuffix = accept ? "Accepted" : "Rejected"; - return _surrenderRequestBuilder(false, accept, "SurrenderForDeliveryAnd"+titleSuffix); + return _surrenderRequestBuilder(false, accept, "SurrenderForDelivery" + titleSuffix, false); } private static EblSurrenderScenarioListBuilder _surrenderRequestBuilder( - boolean forAmendment,boolean accept, String title) { + boolean forAmendment, boolean accept, String title, boolean isSWTP) { EblSurrenderComponentFactory componentFactory = threadLocalComponentFactory.get(); String carrierPartyName = threadLocalCarrierPartyName.get(); String platformPartyName = threadLocalPlatformPartyName.get(); @@ -165,44 +108,11 @@ private static EblSurrenderScenarioListBuilder _surrenderRequestBuilder( 204, previousAction, componentFactory.getMessageSchemaValidator( - EblSurrenderRole.CARRIER.getConfigName(), true),componentFactory.getMessageSchemaValidator( - EblSurrenderRole.PLATFORM.getConfigName(),true),accept, title) - ); - } - - private static EblSurrenderScenarioListBuilder acceptSurrenderRequest(int status) { - log.debug("EblSurrenderScenarioListBuilder.acceptSurrenderRequest(%d)".formatted(status)); - return _surrenderResponseBuilder(true, status); - } - - private static EblSurrenderScenarioListBuilder rejectSurrenderRequest(int status) { - log.debug("EblSurrenderScenarioListBuilder.rejectSurrenderRequest(%d)".formatted(status)); - return _surrenderResponseBuilder(false, status); - } - - private static EblSurrenderScenarioListBuilder _surrenderResponseBuilder( - boolean accept, int expectedStatus) { - EblSurrenderComponentFactory componentFactory = threadLocalComponentFactory.get(); - String carrierPartyName = threadLocalCarrierPartyName.get(); - String platformPartyName = threadLocalPlatformPartyName.get(); - return new EblSurrenderScenarioListBuilder( - previousAction -> - new SurrenderResponseAction( - accept, - carrierPartyName, - platformPartyName, - expectedStatus, - previousAction, + EblSurrenderRole.CARRIER.getConfigName(), true), componentFactory.getMessageSchemaValidator( - EblSurrenderRole.PLATFORM.getConfigName(), true))); - } - - private static EblSurrenderScenarioListBuilder voidAndReissue() { - log.debug("EblSurrenderScenarioListBuilder.voidAndReissue()"); - String carrierPartyName = threadLocalCarrierPartyName.get(); - String platformPartyName = threadLocalPlatformPartyName.get(); - return new EblSurrenderScenarioListBuilder( - previousAction -> - new VoidAndReissueAction(carrierPartyName, platformPartyName, previousAction)); + EblSurrenderRole.PLATFORM.getConfigName(), true), + accept, + title, + isSWTP)); } } diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderStandard.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderStandard.java index eb66d255..0b4cdd7a 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderStandard.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/EblSurrenderStandard.java @@ -13,9 +13,7 @@ private EblSurrenderStandard() { @Override public SortedMap> getScenarioSuitesByStandardVersion() { - return new TreeMap<>( - Map.ofEntries( - Map.entry("3.0.0", new TreeSet<>(Set.of("Conformance"))))); + return new TreeMap<>(Map.ofEntries(Map.entry("3.0.0", new TreeSet<>(Set.of("Conformance"))))); } @Override diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/SurrenderChecks.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/SurrenderChecks.java index 10018124..4b79de50 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/SurrenderChecks.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/SurrenderChecks.java @@ -1,5 +1,8 @@ package org.dcsa.conformance.standards.eblsurrender; +import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.DOCUMENTATION_PARTY_CODE_LIST_PROVIDER_CODES; + +import java.util.UUID; import org.dcsa.conformance.core.check.ActionCheck; import org.dcsa.conformance.core.check.JsonAttribute; import org.dcsa.conformance.core.check.JsonContentCheck; @@ -8,10 +11,6 @@ import org.dcsa.conformance.core.traffic.HttpMessageType; import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole; -import java.util.UUID; - -import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.DOCUMENTATION_PARTY_CODE_LIST_PROVIDER_CODES; - public class SurrenderChecks { private static final KeywordDataset SURRENDER_ACTIONS_DATA_SET = KeywordDataset.staticDataset( "ISSUE", @@ -46,4 +45,5 @@ public static ActionCheck surrenderRequestChecks(UUID matched, String standardVe SURRENDER_PARTY_CODE_LIST_PROVIDER ); } + } diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java index e3a71e08..d7a6a16d 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SupplyScenarioParametersAction.java @@ -1,5 +1,7 @@ package org.dcsa.conformance.standards.eblsurrender.action; +import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import java.util.UUID; @@ -7,8 +9,6 @@ import org.dcsa.conformance.core.scenario.ConformanceAction; import org.dcsa.conformance.standards.eblsurrender.party.SuppliedScenarioParameters; -import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER; - @Getter public class SupplyScenarioParametersAction extends ConformanceAction { private SuppliedScenarioParameters suppliedScenarioParameters = null; diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java index 739dfaa4..bec77edc 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderRequestResponseAction.java @@ -1,9 +1,10 @@ package org.dcsa.conformance.standards.eblsurrender.action; +import static org.dcsa.conformance.standards.eblsurrender.SurrenderChecks.surrenderRequestChecks; + import com.fasterxml.jackson.core.JsonPointer; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; - import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import java.util.stream.Stream; @@ -15,8 +16,6 @@ import org.dcsa.conformance.core.traffic.HttpMessageType; import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole; -import static org.dcsa.conformance.standards.eblsurrender.SurrenderChecks.surrenderRequestChecks; - @Getter @Slf4j public class SurrenderRequestResponseAction extends EblSurrenderAction { @@ -24,6 +23,7 @@ public class SurrenderRequestResponseAction extends EblSurrenderAction { private final JsonSchemaValidator responseSchemaValidator; private final boolean forAmendment; private final boolean accept; + private final boolean isSwitchToPaper; private final AtomicReference surrenderRequestReference = new AtomicReference<>(); @@ -38,16 +38,14 @@ public SurrenderRequestResponseAction( JsonSchemaValidator requestSchemaValidator, JsonSchemaValidator responseSchemaValidator, boolean accept, - String title) { - super( - platformPartyName, - carrierPartyName, - expectedStatus, - previousAction,title); //"%s %d".formatted(forAmendment ? "AREQ" : "SREQ" + String title, + boolean isSWTP) { + super(platformPartyName, carrierPartyName, expectedStatus, previousAction, title); this.forAmendment = forAmendment; this.requestSchemaValidator = requestSchemaValidator; this.responseSchemaValidator = responseSchemaValidator; this.accept = accept; + this.isSwitchToPaper = isSWTP; } @Override @@ -73,7 +71,9 @@ public void importJsonState(JsonNode jsonState) { public String getHumanReadablePrompt() { return ("Send a surrender request for %s " + "for the eBL with the transport document reference '%s'") - .formatted(forAmendment ? "amendment" : "delivery", sspSupplier.get().transportDocumentReference()); + .formatted( + forAmendment ? "amendment" : "delivery", + sspSupplier.get().transportDocumentReference()); } @Override @@ -89,7 +89,9 @@ public synchronized Supplier getSrrSupplier() { @Override public ObjectNode asJsonNode() { // don't include srr because it's not known when this is sent out - return super.asJsonNode().put("forAmendment", forAmendment); + return super.asJsonNode() + .put("forAmendment", forAmendment) + .put("isSwitchToPaper", isSwitchToPaper); } @Override @@ -105,70 +107,79 @@ public ConformanceCheck createCheck(String expectedApiVersion) { return new ConformanceCheck(getActionTitle()) { @Override protected Stream createSubChecks() { - return Stream.concat(Stream.of( - new UrlPathCheck( - EblSurrenderRole::isPlatform, getMatchedExchangeUuid(), "/ebl-surrender-requests"), - new ResponseStatusCheck( - EblSurrenderRole::isCarrier, getMatchedExchangeUuid(), getExpectedStatus()), - new ApiHeaderCheck( - EblSurrenderRole::isPlatform, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - expectedApiVersion), - new ApiHeaderCheck( - EblSurrenderRole::isCarrier, - getMatchedExchangeUuid(), - HttpMessageType.RESPONSE, - expectedApiVersion), - new JsonSchemaCheck( - EblSurrenderRole::isPlatform, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - requestSchemaValidator), - new JsonAttributeCheck( - EblSurrenderRole::isPlatform, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - JsonPointer.compile("/surrenderRequestCode"), - forAmendment ? "AREQ" : "SREQ"), - surrenderRequestChecks(getMatchedExchangeUuid(), expectedApiVersion), - new JsonAttributeCheck( - EblSurrenderRole::isPlatform, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - JsonPointer.compile("/transportDocumentReference"), - sspSupplier.get() == null ? null : sspSupplier.get().transportDocumentReference())), - Stream.of( - new UrlPathCheck("[Response]", - EblSurrenderRole::isCarrier, - getMatchedNotificationExchangeUuid(), - "/ebl-surrender-responses"), - new ResponseStatusCheck("[Response]", - EblSurrenderRole::isPlatform, getMatchedNotificationExchangeUuid(), getExpectedStatus()), - new ApiHeaderCheck( - EblSurrenderRole::isPlatform, - getMatchedNotificationExchangeUuid(), - HttpMessageType.RESPONSE, - expectedApiVersion), - new JsonSchemaCheck("[Response]", - EblSurrenderRole::isCarrier, - getMatchedNotificationExchangeUuid(), - HttpMessageType.REQUEST, - responseSchemaValidator), - new JsonAttributeCheck("[Response]", - EblSurrenderRole::isCarrier, - getMatchedNotificationExchangeUuid(), - HttpMessageType.REQUEST, - JsonPointer.compile("/action"), - accept ? "SURR" : "SREJ") - /*expectedSrr == null || expectedSrr.equals("*") - ? null - : new JsonAttributeCheck( - EblSurrenderRole::isCarrier, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - JsonPointer.compile("/surrenderRequestReference"), - expectedSrr)*/)); + return Stream.concat( + Stream.of( + new UrlPathCheck( + EblSurrenderRole::isPlatform, + getMatchedExchangeUuid(), + "/ebl-surrender-requests"), + new ResponseStatusCheck( + EblSurrenderRole::isCarrier, getMatchedExchangeUuid(), getExpectedStatus()), + new ApiHeaderCheck( + EblSurrenderRole::isPlatform, + getMatchedExchangeUuid(), + HttpMessageType.REQUEST, + expectedApiVersion), + new ApiHeaderCheck( + EblSurrenderRole::isCarrier, + getMatchedExchangeUuid(), + HttpMessageType.RESPONSE, + expectedApiVersion), + new JsonSchemaCheck( + EblSurrenderRole::isPlatform, + getMatchedExchangeUuid(), + HttpMessageType.REQUEST, + requestSchemaValidator), + new JsonAttributeCheck( + EblSurrenderRole::isPlatform, + getMatchedExchangeUuid(), + HttpMessageType.REQUEST, + JsonPointer.compile("/surrenderRequestCode"), + forAmendment ? "AREQ" : "SREQ"), + new JsonAttributeCheck( + EblSurrenderRole::isPlatform, + getMatchedExchangeUuid(), + HttpMessageType.REQUEST, + JsonPointer.compile("/reasonCode"), + forAmendment && isSwitchToPaper ? "SWTP" : ""), + surrenderRequestChecks(getMatchedExchangeUuid(), expectedApiVersion), + new JsonAttributeCheck( + EblSurrenderRole::isPlatform, + getMatchedExchangeUuid(), + HttpMessageType.REQUEST, + JsonPointer.compile("/transportDocumentReference"), + sspSupplier.get() == null + ? null + : sspSupplier.get().transportDocumentReference())), + Stream.of( + new UrlPathCheck( + "[Response]", + EblSurrenderRole::isCarrier, + getMatchedNotificationExchangeUuid(), + "/ebl-surrender-responses"), + new ResponseStatusCheck( + "[Response]", + EblSurrenderRole::isPlatform, + getMatchedNotificationExchangeUuid(), + getExpectedStatus()), + new ApiHeaderCheck( + EblSurrenderRole::isPlatform, + getMatchedNotificationExchangeUuid(), + HttpMessageType.RESPONSE, + expectedApiVersion), + new JsonSchemaCheck( + "[Response]", + EblSurrenderRole::isCarrier, + getMatchedNotificationExchangeUuid(), + HttpMessageType.REQUEST, + responseSchemaValidator), + new JsonAttributeCheck( + "[Response]", + EblSurrenderRole::isCarrier, + getMatchedNotificationExchangeUuid(), + HttpMessageType.REQUEST, + JsonPointer.compile("/action"), + accept ? "SURR" : "SREJ"))); } }; } diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderResponseAction.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderResponseAction.java deleted file mode 100644 index d03de71d..00000000 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/SurrenderResponseAction.java +++ /dev/null @@ -1,121 +0,0 @@ -package org.dcsa.conformance.standards.eblsurrender.action; - -import com.fasterxml.jackson.core.JsonPointer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import java.util.Objects; -import java.util.function.Supplier; -import java.util.stream.Stream; -import lombok.Getter; -import org.dcsa.conformance.core.check.*; -import org.dcsa.conformance.core.scenario.ConformanceAction; -import org.dcsa.conformance.core.traffic.HttpMessageType; -import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole; - -@Getter -public class SurrenderResponseAction extends EblSurrenderAction { - private final JsonSchemaValidator requestSchemaValidator; - private final boolean accept; - private Supplier srrSupplier; - - public SurrenderResponseAction( - boolean accept, - String carrierPartyName, - String platformPartyName, - int expectedStatus, - ConformanceAction previousAction, - JsonSchemaValidator requestSchemaValidator) { - super( - carrierPartyName, - platformPartyName, - expectedStatus, - previousAction, - "%s %d".formatted(accept ? "SURR" : "SREJ", expectedStatus)); - this.accept = accept; - this.requestSchemaValidator = requestSchemaValidator; - } - - @Override - public ObjectNode exportJsonState() { - return super.exportJsonState(); - } - - @Override - public void importJsonState(JsonNode jsonState) { - super.importJsonState(jsonState); - } - - @Override - public String getHumanReadablePrompt() { - return ("%s the surrender request with surrender request reference '%s'") - .formatted(accept ? "Accept" : "Reject", getSrrSupplier().get()); - } - - @Override - public synchronized Supplier getSrrSupplier() { - if (srrSupplier != null) return srrSupplier; - for (ConformanceAction action = this.previousAction; - action != null; - action = action.getPreviousAction()) { - if (action instanceof EblSurrenderAction tdrAction) { - if ((srrSupplier = tdrAction.getSrrSupplier()) != null) { - return srrSupplier; - } - } - } - return () -> "*"; - } - - @Override - public ObjectNode asJsonNode() { - return super.asJsonNode().put("srr", getSrrSupplier().get()).put("accept", accept); - } - - @Override - public ConformanceCheck createCheck(String expectedApiVersion) { - return new ConformanceCheck(getActionTitle()) { - @Override - protected Stream createSubChecks() { - String expectedSrr = getSrrSupplier().get(); - return Stream.of( - new UrlPathCheck( - EblSurrenderRole::isCarrier, - getMatchedExchangeUuid(), - "/ebl-surrender-responses"), - new ResponseStatusCheck( - EblSurrenderRole::isPlatform, getMatchedExchangeUuid(), getExpectedStatus()), - new ApiHeaderCheck( - EblSurrenderRole::isCarrier, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - expectedApiVersion), - new ApiHeaderCheck( - EblSurrenderRole::isPlatform, - getMatchedExchangeUuid(), - HttpMessageType.RESPONSE, - expectedApiVersion), - new JsonSchemaCheck( - EblSurrenderRole::isCarrier, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - requestSchemaValidator), - new JsonAttributeCheck( - EblSurrenderRole::isCarrier, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - JsonPointer.compile("/action"), - accept ? "SURR" : "SREJ"), - expectedSrr == null || expectedSrr.equals("*") - ? null - : new JsonAttributeCheck( - EblSurrenderRole::isCarrier, - getMatchedExchangeUuid(), - HttpMessageType.REQUEST, - JsonPointer.compile("/surrenderRequestReference"), - expectedSrr)) - .filter(Objects::nonNull); - } - }; - } -} diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/VoidAndReissueAction.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/VoidAndReissueAction.java deleted file mode 100644 index 0795c9f6..00000000 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/action/VoidAndReissueAction.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.dcsa.conformance.standards.eblsurrender.action; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.function.Supplier; -import lombok.Getter; -import org.dcsa.conformance.core.scenario.ConformanceAction; - -@Getter -public class VoidAndReissueAction extends EblSurrenderAction { - - private final Consumer tdrConsumer = - tdr -> { - if (!Objects.equals(tdr, sspSupplier.get().transportDocumentReference())) { - throw new UnsupportedOperationException( - "Changing the transportDocumentReference during void/reissue is currently not supported"); - } - }; - - public VoidAndReissueAction( - String carrierPartyName, String platformPartyName, ConformanceAction previousAction) { - super(carrierPartyName, platformPartyName, -1, previousAction, "Void&Reissue"); - } - - @Override - public ObjectNode exportJsonState() { - return super.exportJsonState(); - } - - @Override - public void importJsonState(JsonNode jsonState) { - super.importJsonState(jsonState); - } - - @Override - public String getHumanReadablePrompt() { - return "Void and reissue the eBL with transport document reference '%s'".formatted(sspSupplier.get()); - } - - @Override - public boolean isConfirmationRequired() { - return true; - } - - @Override - public boolean isMissingMatchedExchange() { - return false; - } - - @Override - public Supplier getSrrSupplier() { - return null; - } -} diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java index fe9590c7..508d1717 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderCarrier.java @@ -19,8 +19,6 @@ import org.dcsa.conformance.core.traffic.ConformanceRequest; import org.dcsa.conformance.core.traffic.ConformanceResponse; import org.dcsa.conformance.standards.eblsurrender.action.SupplyScenarioParametersAction; -import org.dcsa.conformance.standards.eblsurrender.action.SurrenderResponseAction; -import org.dcsa.conformance.standards.eblsurrender.action.VoidAndReissueAction; @Slf4j public class EblSurrenderCarrier extends ConformanceParty { @@ -73,9 +71,7 @@ protected void doReset() { @Override protected Map, Consumer> getActionPromptHandlers() { return Map.ofEntries( - Map.entry(SupplyScenarioParametersAction.class, this::supplyScenarioParameters), - //Map.entry(SurrenderResponseAction.class, this::sendSurrenderResponse), - Map.entry(VoidAndReissueAction.class, this::voidAndReissue)); + Map.entry(SupplyScenarioParametersAction.class, this::supplyScenarioParameters)); } private void supplyScenarioParameters(JsonNode actionPrompt) { @@ -85,21 +81,17 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { String tdr = UUID.randomUUID().toString().replace("-", "").substring(0, 20); eblStatesById.put(tdr, EblSurrenderState.AVAILABLE_FOR_SURRENDER); - persistentMap.save("response",actionPrompt.get("response")); + persistentMap.save("response", actionPrompt.get("response")); var issueToParty = OBJECT_MAPPER.createObjectNode(); - issueToParty.put("partyName", "Issue To name") - .put("eblPlatform", "WAVE"); + issueToParty.put("partyName", "Issue To name").put("eblPlatform", "WAVE"); var carrierParty = OBJECT_MAPPER.createObjectNode(); - carrierParty.put("partyName", "Carrier name") - .put("eblPlatform", "WAVE"); + carrierParty.put("partyName", "Carrier name").put("eblPlatform", "WAVE"); var surrendereeParty = OBJECT_MAPPER.createObjectNode(); - surrendereeParty.put("partyName", "Surrenderee name") - .put("eblPlatform", "BOLE"); + surrendereeParty.put("partyName", "Surrenderee name").put("eblPlatform", "BOLE"); SuppliedScenarioParameters suppliedScenarioParameters = - new SuppliedScenarioParameters( - tdr, issueToParty, carrierParty, surrendereeParty); + new SuppliedScenarioParameters(tdr, issueToParty, carrierParty, surrendereeParty); asyncOrchestratorPostPartyInput( actionPrompt.required("actionId").asText(), suppliedScenarioParameters.toJson()); @@ -109,56 +101,6 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { .formatted(suppliedScenarioParameters.toJson().toPrettyString())); } - private void voidAndReissue(JsonNode actionPrompt) { - log.info("EblSurrenderCarrier.voidAndReissue(%s)".formatted(actionPrompt.toPrettyString())); - SuppliedScenarioParameters ssp = SuppliedScenarioParameters.fromJson(actionPrompt.get("suppliedScenarioParameters")); - String tdr = ssp.transportDocumentReference(); - if (!Objects.equals(eblStatesById.get(tdr), EblSurrenderState.SURRENDERED_FOR_AMENDMENT)) { - throw new IllegalStateException( - "Cannot void and reissue in state: " + eblStatesById.get(tdr)); - } - eblStatesById.put(tdr, EblSurrenderState.AVAILABLE_FOR_SURRENDER); - asyncOrchestratorPostPartyInput( - actionPrompt.get("actionId").asText(), OBJECT_MAPPER.createObjectNode()); - addOperatorLogEntry( - "Voided and reissued the eBL with transportDocumentReference '%s'".formatted(tdr)); - } - - private void sendSurrenderResponse(JsonNode actionPrompt) { - log.info( - "EblSurrenderCarrier.sendSurrenderResponse(%s)".formatted(actionPrompt.toPrettyString())); - SuppliedScenarioParameters ssp = SuppliedScenarioParameters.fromJson(actionPrompt.get("suppliedScenarioParameters")); - String tdr = ssp.transportDocumentReference(); - boolean accept = actionPrompt.get("accept").asBoolean(); - switch (eblStatesById.get(tdr)) { - case AMENDMENT_SURRENDER_REQUESTED -> eblStatesById.put( - tdr, - accept - ? EblSurrenderState.SURRENDERED_FOR_AMENDMENT - : EblSurrenderState.AVAILABLE_FOR_SURRENDER); - case DELIVERY_SURRENDER_REQUESTED -> eblStatesById.put( - tdr, - accept - ? EblSurrenderState.SURRENDERED_FOR_DELIVERY - : EblSurrenderState.AVAILABLE_FOR_SURRENDER); - default -> {} // ignore -- sending from wrong state for testing purposes - } - String srr = actionPrompt.get("srr").asText(); - if ("*".equals(srr)) { - srr = UUID.randomUUID().toString(); - } - syncCounterpartPost( - "/v%s/ebl-surrender-responses".formatted(apiVersion.charAt(0)), - OBJECT_MAPPER - .createObjectNode() - .put("surrenderRequestReference", srr) - .put("action", accept ? "SURR" : "SREJ")); - - addOperatorLogEntry( - "%s surrender request with surrenderRequestReference '%s' for eBL with transportDocumentReference '%s' (now in state '%s')" - .formatted(accept ? "Accepted" : "Rejected", srr, tdr, eblStatesById.get(tdr))); - } - @Override public ConformanceResponse handleRequest(ConformanceRequest request) { log.info("EblSurrenderCarrier.handleRequest(%s)".formatted(request)); @@ -166,29 +108,28 @@ public ConformanceResponse handleRequest(ConformanceRequest request) { String src = jsonRequest.get("surrenderRequestCode").asText(); String srr = jsonRequest.get("surrenderRequestReference").asText(); String tdr = jsonRequest.get("transportDocumentReference").asText(); - String action = tdr.contains("WAVER") ? "SREJ":"SURR"; + String action = tdr.contains("WAVER") ? "SREJ" : "SURR"; - String responseCode = null; if ("*".equals(srr)) { srr = UUID.randomUUID().toString(); } - if(persistentMap.load("response") != null){ + if (persistentMap.load("response") != null) { action = persistentMap.load("response").asText(); } - var carrierResponse = OBJECT_MAPPER - .createObjectNode() - .put("surrenderRequestReference", srr) - .put("action", action); - asyncCounterpartNotification(null, - "/v3/ebl-surrender-responses",carrierResponse); + var carrierResponse = + OBJECT_MAPPER + .createObjectNode() + .put("surrenderRequestReference", srr) + .put("action", action); + asyncCounterpartNotification(null, "/v3/ebl-surrender-responses", carrierResponse); -//.put("action", accept ? "SURR" : "SREJ")); if (Objects.equals( EblSurrenderState.AVAILABLE_FOR_SURRENDER, eblStatesById.getOrDefault( tdr, - // workaround for supplyScenarioParameters() not getting called on parties in manual mode + // workaround for supplyScenarioParameters() not getting called on parties in manual + // mode this.partyConfiguration.isInManualMode() ? EblSurrenderState.AVAILABLE_FOR_SURRENDER : null))) { diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java index 2795c2bf..72747053 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderPlatform.java @@ -45,8 +45,7 @@ public EblSurrenderPlatform( @Override protected void exportPartyJsonState(ObjectNode targetObjectNode) { targetObjectNode.set( - "eblStatesById", - StateManagementUtil.storeMap(eblStatesById, EblSurrenderState::name)); + "eblStatesById", StateManagementUtil.storeMap(eblStatesById, EblSurrenderState::name)); targetObjectNode.set("tdrsBySrr", StateManagementUtil.storeMap(tdrsBySrr)); } @@ -76,9 +75,12 @@ private void requestSurrender(JsonNode actionPrompt) { String tdr = ssp.transportDocumentReference(); boolean forAmendment = actionPrompt.get("forAmendment").booleanValue(); String src = forAmendment ? "AREQ" : "SREQ"; - String action = ssp.issueToParty().get("eblPlatform") != null? ssp.issueToParty().get("eblPlatform").asText() : null; - if(action != null && action.equals("WAVER")){ - tdr = tdr+action; + String action = + ssp.issueToParty().get("eblPlatform") != null + ? ssp.issueToParty().get("eblPlatform").asText() + : null; + if (action != null && action.equals("WAVER")) { + tdr = tdr + action; } tdrsBySrr.put(srr, tdr); eblStatesById.put( @@ -86,7 +88,11 @@ private void requestSurrender(JsonNode actionPrompt) { forAmendment ? EblSurrenderState.AMENDMENT_SURRENDER_REQUESTED : EblSurrenderState.DELIVERY_SURRENDER_REQUESTED); - + String reasonCode = + actionPrompt.get("isSwitchToPaper") != null + && actionPrompt.get("isSwitchToPaper").booleanValue() + ? "SWTP" + : ""; JsonNode jsonRequestBody = JsonToolkit.templateFileToJsonNode( "/standards/eblsurrender/messages/eblsurrender-api-v%s-request.json" @@ -95,14 +101,14 @@ private void requestSurrender(JsonNode actionPrompt) { Map.entry("SURRENDER_REQUEST_REFERENCE_PLACEHOLDER", srr), Map.entry("TRANSPORT_DOCUMENT_REFERENCE_PLACEHOLDER", tdr), Map.entry("SURRENDER_REQUEST_CODE_PLACEHOLDER", src), + Map.entry("REASON_CODE", reasonCode), Map.entry("ISSUE_TO_PARTY", ssp.issueToParty().toString()), Map.entry("SURRENDEREE_PARTY", ssp.surrendereeParty().toString()), Map.entry("CARRIER_PARTY", ssp.carrierParty().toString()), Map.entry("ACTION_DATE_TIME_PLACEHOLDER", Instant.now().toString()))); syncCounterpartPost( - "/v%s/ebl-surrender-requests".formatted(apiVersion.charAt(0)), - jsonRequestBody); + "/v%s/ebl-surrender-requests".formatted(apiVersion.charAt(0)), jsonRequestBody); addOperatorLogEntry( "Sent surrender request with surrenderRequestCode '%s' and surrenderRequestReference '%s' for eBL with transportDocumentReference '%s'" @@ -156,12 +162,12 @@ public ConformanceResponse handleRequest(ConformanceRequest request) { .formatted(action, tdr, eblStatesById.get(tdr))))); } /*addOperatorLogEntry( - "Handling surrender response with action '%s' and surrenderRequestReference '%s' for eBL with transportDocumentReference '%s' (now in state '%s')" - .formatted(action, srr, tdr, eblStatesById.get(tdr)));*/ + "Handling surrender response with action '%s' and surrenderRequestReference '%s' for eBL with transportDocumentReference '%s' (now in state '%s')" + .formatted(action, srr, tdr, eblStatesById.get(tdr)));*/ addOperatorLogEntry( - "Handling notification with action '%s' and surrenderRequestReference '%s' for eBL with transportDocumentReference '%s' (now in state '%s')" - .formatted(action, srr, tdr, eblStatesById.get(tdr))); + "Handling notification with action '%s' and surrenderRequestReference '%s' for eBL with transportDocumentReference '%s' (now in state '%s')" + .formatted(action, srr, tdr, eblStatesById.get(tdr))); return response; } } diff --git a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderState.java b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderState.java index 6fdf30e7..9e2baac8 100644 --- a/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderState.java +++ b/ebl-surrender/src/main/java/org/dcsa/conformance/standards/eblsurrender/party/EblSurrenderState.java @@ -1,9 +1,9 @@ package org.dcsa.conformance.standards.eblsurrender.party; public enum EblSurrenderState { - AVAILABLE_FOR_SURRENDER, - AMENDMENT_SURRENDER_REQUESTED, - SURRENDERED_FOR_AMENDMENT, - DELIVERY_SURRENDER_REQUESTED, - SURRENDERED_FOR_DELIVERY, + AVAILABLE_FOR_SURRENDER, + AMENDMENT_SURRENDER_REQUESTED, + SURRENDERED_FOR_AMENDMENT, + DELIVERY_SURRENDER_REQUESTED, + SURRENDERED_FOR_DELIVERY, } diff --git a/ebl-surrender/src/main/resources/standards/eblsurrender/messages/eblsurrender-api-v3.0.0-request.json b/ebl-surrender/src/main/resources/standards/eblsurrender/messages/eblsurrender-api-v3.0.0-request.json index 8a515350..9aafeb6a 100644 --- a/ebl-surrender/src/main/resources/standards/eblsurrender/messages/eblsurrender-api-v3.0.0-request.json +++ b/ebl-surrender/src/main/resources/standards/eblsurrender/messages/eblsurrender-api-v3.0.0-request.json @@ -2,7 +2,7 @@ "surrenderRequestReference": "SURRENDER_REQUEST_REFERENCE_PLACEHOLDER", "transportDocumentReference": "TRANSPORT_DOCUMENT_REFERENCE_PLACEHOLDER", "surrenderRequestCode": "SURRENDER_REQUEST_CODE_PLACEHOLDER", - "reasonCode": "SWTP", + "reasonCode": "REASON_CODE", "comments": "As requested...", "endorsementChain": [ {