From 2d3b3ab00f3bdfc7c175f289803db198d13ebb17 Mon Sep 17 00:00:00 2001 From: gj0dcsa <135594855+gj0dcsa@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:14:51 +0200 Subject: [PATCH] DT-1678 Safer interface for posting party input to the orchestrator --- .../SupplyScenarioParametersAction.java | 6 ------ .../adoption/party/AdoptionAdopter.java | 6 ++---- .../booking/party/BookingCarrier.java | 6 +----- .../standards/cs/party/CsPublisher.java | 7 +------ .../core/party/ConformanceParty.java | 21 +++++++++++++++++-- .../eblissuance/party/EblIssuanceCarrier.java | 5 +---- .../party/EblIssuancePlatform.java | 5 +---- .../party/EblSurrenderCarrier.java | 7 ++----- .../standards/ebl/party/EblCarrier.java | 17 ++------------- .../standards/jit/party/JitPublisher.java | 7 +------ .../standards/ovs/party/OvsPublisher.java | 7 +------ .../party/PintReceivingPlatform.java | 10 ++------- .../eblinterop/party/PintSendingPlatform.java | 15 +++---------- .../standards/tnt/party/TntPublisher.java | 7 +------ 14 files changed, 37 insertions(+), 89 deletions(-) diff --git a/adoption/src/main/java/org/dcsa/conformance/standards/adoption/action/SupplyScenarioParametersAction.java b/adoption/src/main/java/org/dcsa/conformance/standards/adoption/action/SupplyScenarioParametersAction.java index 2fc71830..f072b798 100644 --- a/adoption/src/main/java/org/dcsa/conformance/standards/adoption/action/SupplyScenarioParametersAction.java +++ b/adoption/src/main/java/org/dcsa/conformance/standards/adoption/action/SupplyScenarioParametersAction.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.NullNode; import com.fasterxml.jackson.databind.node.ObjectNode; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -103,11 +102,6 @@ public void handlePartyInput(JsonNode partyInput) { try { JsonNode input = partyInput.get("input"); - // This should not be needed, but somehow it uses the SupplyScenarioParametersAction also on - // DCSA role - if (input instanceof NullNode) { - return; - } String interval = input.required("interval").asText(); if (interval == null || !(interval.equals("day") || interval.equals("week") || interval.equals("month"))) { diff --git a/adoption/src/main/java/org/dcsa/conformance/standards/adoption/party/AdoptionAdopter.java b/adoption/src/main/java/org/dcsa/conformance/standards/adoption/party/AdoptionAdopter.java index 7a1b13a4..ffbc651e 100644 --- a/adoption/src/main/java/org/dcsa/conformance/standards/adoption/party/AdoptionAdopter.java +++ b/adoption/src/main/java/org/dcsa/conformance/standards/adoption/party/AdoptionAdopter.java @@ -68,10 +68,8 @@ private void getAdoptionStats(JsonNode actionPrompt) { log.info("AdoptionAdopter.getAdoptionStats({})", actionPrompt); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put(ACTION_ID, actionPrompt.required(ACTION_ID).asText()) - .putNull("input")); + actionPrompt.required(ACTION_ID).asText(), + OBJECT_MAPPER.createObjectNode().put("interval", "week").put("date", "2024-12-31")); addOperatorLogEntry( "Provided AdoptionScenarioParameters: %s".formatted(actionPrompt.get(ACTION_ID))); } diff --git a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingCarrier.java b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingCarrier.java index 515b9a84..105ac18b 100644 --- a/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingCarrier.java +++ b/booking/src/main/java/org/dcsa/conformance/standards/booking/party/BookingCarrier.java @@ -1,7 +1,6 @@ package org.dcsa.conformance.standards.booking.party; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import java.time.Instant; import java.util.*; @@ -168,10 +167,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { }; asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.get("actionId").asText()) - .set("input", carrierScenarioParameters.toJson())); + actionPrompt.get("actionId").asText(), carrierScenarioParameters.toJson()); addOperatorLogEntry( "Provided CarrierScenarioParameters: %s".formatted(carrierScenarioParameters)); } diff --git a/commercial-schedules/src/main/java/org/dcsa/conformance/standards/cs/party/CsPublisher.java b/commercial-schedules/src/main/java/org/dcsa/conformance/standards/cs/party/CsPublisher.java index 161734d1..7294cbb4 100644 --- a/commercial-schedules/src/main/java/org/dcsa/conformance/standards/cs/party/CsPublisher.java +++ b/commercial-schedules/src/main/java/org/dcsa/conformance/standards/cs/party/CsPublisher.java @@ -1,7 +1,5 @@ package org.dcsa.conformance.standards.cs.party; -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.*; @@ -140,10 +138,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { }))); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", responseSsp.toJson())); + actionPrompt.required("actionId").asText(), responseSsp.toJson()); addOperatorLogEntry( "Submitting SuppliedScenarioParameters: %s" diff --git a/core/src/main/java/org/dcsa/conformance/core/party/ConformanceParty.java b/core/src/main/java/org/dcsa/conformance/core/party/ConformanceParty.java index 45e2a252..a22e6024 100644 --- a/core/src/main/java/org/dcsa/conformance/core/party/ConformanceParty.java +++ b/core/src/main/java/org/dcsa/conformance/core/party/ConformanceParty.java @@ -129,7 +129,24 @@ public String getCounterpartRole() { return counterpartConfiguration.getRole(); } - protected void asyncOrchestratorPostPartyInput(JsonNode jsonPartyInput) { + /** + * To be invoked like this: + *
+ * {@code + * asyncOrchestratorPostPartyInput( + * actionPrompt.required("actionId").asText(), + * OBJECT_MAPPER.createObjectNode() + * .put("keyOne", valueOne) + * .put("keyTwo", valueTwo)); + * } + *+ */ + protected void asyncOrchestratorPostPartyInput(String actionId, ObjectNode inputObjectNode) { + if (actionId == null) throw new IllegalArgumentException("The actionId may not be null"); + if (inputObjectNode == null) + throw new IllegalArgumentException("The inputObjectNode may not be null"); + ObjectNode jsonPartyInput = + OBJECT_MAPPER.createObjectNode().put("actionId", actionId).set("input", inputObjectNode); if (partyConfiguration.isInManualMode()) { log.info( "Party {} NOT posting its input automatically (it is in manual mode): {}", @@ -198,7 +215,7 @@ protected void asyncCounterpartNotification(String actionId, String path, JsonNo "Party {} notifying orchestrator that action {} is completed instead of sending notification: no counterpart URL is configured", actionId, partyConfiguration.getName()); - asyncOrchestratorPostPartyInput(OBJECT_MAPPER.createObjectNode().put("actionId", actionId)); + asyncOrchestratorPostPartyInput(actionId, OBJECT_MAPPER.createObjectNode()); } else { log.info( "Party {} NOT sending a notification and NOT notifying orchestrator either: no counterpart URL is configured", diff --git a/ebl-issuance/src/main/java/org/dcsa/conformance/standards/eblissuance/party/EblIssuanceCarrier.java b/ebl-issuance/src/main/java/org/dcsa/conformance/standards/eblissuance/party/EblIssuanceCarrier.java index 79d19c51..c7dda5a4 100644 --- a/ebl-issuance/src/main/java/org/dcsa/conformance/standards/eblissuance/party/EblIssuanceCarrier.java +++ b/ebl-issuance/src/main/java/org/dcsa/conformance/standards/eblissuance/party/EblIssuanceCarrier.java @@ -90,10 +90,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { new CarrierScenarioParameters( payloadSigner.getPublicKeyInPemFormat()); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", carrierScenarioParameters.toJson())); + actionPrompt.required("actionId").asText(), carrierScenarioParameters.toJson()); addOperatorLogEntry( "Submitting CarrierScenarioParameters: %s" .formatted(carrierScenarioParameters.toJson().toPrettyString())); diff --git a/ebl-issuance/src/main/java/org/dcsa/conformance/standards/eblissuance/party/EblIssuancePlatform.java b/ebl-issuance/src/main/java/org/dcsa/conformance/standards/eblissuance/party/EblIssuancePlatform.java index b7c3ec95..5d4097ec 100644 --- a/ebl-issuance/src/main/java/org/dcsa/conformance/standards/eblissuance/party/EblIssuancePlatform.java +++ b/ebl-issuance/src/main/java/org/dcsa/conformance/standards/eblissuance/party/EblIssuancePlatform.java @@ -141,10 +141,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { "5678-cn-or-end", "Bolero"); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", suppliedScenarioParameters.toJson())); + actionPrompt.required("actionId").asText(), suppliedScenarioParameters.toJson()); addOperatorLogEntry( "Submitting SuppliedScenarioParameters: %s" .formatted(suppliedScenarioParameters.toJson().toPrettyString())); 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 afe7a116..5eb1c45c 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 @@ -91,10 +91,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { tdr, "XMPL", "Example carrier party code", "Example party code", "Example code list"); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", suppliedScenarioParameters.toJson())); + actionPrompt.required("actionId").asText(), suppliedScenarioParameters.toJson()); addOperatorLogEntry( "Submitting SuppliedScenarioParameters: %s" @@ -111,7 +108,7 @@ private void voidAndReissue(JsonNode actionPrompt) { } eblStatesById.put(tdr, EblSurrenderState.AVAILABLE_FOR_SURRENDER); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER.createObjectNode().put("actionId", actionPrompt.get("actionId").asText())); + actionPrompt.get("actionId").asText(), OBJECT_MAPPER.createObjectNode()); addOperatorLogEntry( "Voided and reissued the eBL with transportDocumentReference '%s'".formatted(tdr)); } 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 2f6be40c..2e3e46e4 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 @@ -200,10 +200,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { ); }; asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", carrierScenarioParameters.toJson())); + actionPrompt.required("actionId").asText(), carrierScenarioParameters.toJson()); addOperatorLogEntry( "Provided CarrierScenarioParameters: %s".formatted(carrierScenarioParameters)); } @@ -258,9 +255,7 @@ private void processOutOfBandUpdateOrAmendmentRequestTransportDocumentAction(Jso si.putShippingInstructions(documentReference, updatedSI); si.acceptUpdatedShippingInstructions(documentReference); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText())); + actionPrompt.required("actionId").asText(), OBJECT_MAPPER.createObjectNode()); addOperatorLogEntry("Process out of band amendment for transport document '%s'".formatted(documentReference)); } @@ -288,14 +283,6 @@ private void publishDraftTransportDocument(JsonNode actionPrompt) { si.publishDraftTransportDocument(documentReference, scenarioType); si.save(persistentMap); tdrToSir.put(si.getTransportDocumentReference(), si.getShippingInstructionsReference()); - if (skipSI) { - asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .putObject("input") - .put("transportDocumentReference", si.getTransportDocumentReference())); - } generateAndEmitNotificationFromTransportDocument(actionPrompt, si, true); addOperatorLogEntry("Published draft transport document '%s'".formatted(si.getTransportDocumentReference())); diff --git a/jit/src/main/java/org/dcsa/conformance/standards/jit/party/JitPublisher.java b/jit/src/main/java/org/dcsa/conformance/standards/jit/party/JitPublisher.java index f96c1510..d950954f 100644 --- a/jit/src/main/java/org/dcsa/conformance/standards/jit/party/JitPublisher.java +++ b/jit/src/main/java/org/dcsa/conformance/standards/jit/party/JitPublisher.java @@ -1,7 +1,5 @@ package org.dcsa.conformance.standards.jit.party; -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.time.ZonedDateTime; @@ -91,10 +89,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { }))); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", responseSsp.toJson())); + actionPrompt.required("actionId").asText(), responseSsp.toJson()); addOperatorLogEntry( "Submitting SuppliedScenarioParameters: %s" diff --git a/ovs/src/main/java/org/dcsa/conformance/standards/ovs/party/OvsPublisher.java b/ovs/src/main/java/org/dcsa/conformance/standards/ovs/party/OvsPublisher.java index 31db731d..d945ecea 100644 --- a/ovs/src/main/java/org/dcsa/conformance/standards/ovs/party/OvsPublisher.java +++ b/ovs/src/main/java/org/dcsa/conformance/standards/ovs/party/OvsPublisher.java @@ -1,7 +1,5 @@ package org.dcsa.conformance.standards.ovs.party; -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.text.SimpleDateFormat; @@ -89,10 +87,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { }))); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", responseSsp.toJson())); + actionPrompt.required("actionId").asText(), responseSsp.toJson()); addOperatorLogEntry( "Submitting SuppliedScenarioParameters: %s" diff --git a/pint/src/main/java/org/dcsa/conformance/standards/eblinterop/party/PintReceivingPlatform.java b/pint/src/main/java/org/dcsa/conformance/standards/eblinterop/party/PintReceivingPlatform.java index 25a9edae..5c3d755f 100644 --- a/pint/src/main/java/org/dcsa/conformance/standards/eblinterop/party/PintReceivingPlatform.java +++ b/pint/src/main/java/org/dcsa/conformance/standards/eblinterop/party/PintReceivingPlatform.java @@ -76,10 +76,7 @@ private void resetScenarioClass(JsonNode actionPrompt) { tdState.setScenarioClass(scenarioClass); tdState.save(persistentMap); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .putNull("input")); + actionPrompt.required("actionId").asText(), OBJECT_MAPPER.createObjectNode()); addOperatorLogEntry( "Finished resetScenarioClass"); } @@ -100,10 +97,7 @@ private void initiateState(JsonNode actionPrompt) { tdState.setScenarioClass(scenarioClass); tdState.save(persistentMap); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", receivingParameters.toJson())); + actionPrompt.required("actionId").asText(), receivingParameters.toJson()); addOperatorLogEntry( "Finished ScenarioType"); } diff --git a/pint/src/main/java/org/dcsa/conformance/standards/eblinterop/party/PintSendingPlatform.java b/pint/src/main/java/org/dcsa/conformance/standards/eblinterop/party/PintSendingPlatform.java index 82f495af..8f3e6152 100644 --- a/pint/src/main/java/org/dcsa/conformance/standards/eblinterop/party/PintSendingPlatform.java +++ b/pint/src/main/java/org/dcsa/conformance/standards/eblinterop/party/PintSendingPlatform.java @@ -143,10 +143,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { carrierPayloadSigner.getPublicKeyInPemFormat() ); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", scenarioParameters.toJson())); + actionPrompt.required("actionId").asText(), scenarioParameters.toJson()); addOperatorLogEntry( "Provided ScenarioParameters: %s".formatted(scenarioParameters)); } @@ -161,10 +158,7 @@ private void resignLatestEntry(JsonNode actionPrompt) { sendingState.resignLatestEntry(payloadSigner); sendingState.save(persistentMap); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .putNull("input")); + actionPrompt.required("actionId").asText(), OBJECT_MAPPER.createObjectNode()); addOperatorLogEntry( "Resigned latest entry for document: %s".formatted(tdr)); } @@ -180,10 +174,7 @@ private void manipulateTransactions(JsonNode actionPrompt) { sendingState.manipulateLatestTransaction(payloadSigner, rsp); sendingState.save(persistentMap); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .putNull("input")); + actionPrompt.required("actionId").asText(), OBJECT_MAPPER.createObjectNode()); addOperatorLogEntry( "Mutated transaction chain for document: %s".formatted(tdr)); } diff --git a/tnt/src/main/java/org/dcsa/conformance/standards/tnt/party/TntPublisher.java b/tnt/src/main/java/org/dcsa/conformance/standards/tnt/party/TntPublisher.java index 19fb50bb..6f78726c 100644 --- a/tnt/src/main/java/org/dcsa/conformance/standards/tnt/party/TntPublisher.java +++ b/tnt/src/main/java/org/dcsa/conformance/standards/tnt/party/TntPublisher.java @@ -1,7 +1,5 @@ package org.dcsa.conformance.standards.tnt.party; -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.time.ZonedDateTime; @@ -103,10 +101,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) { }))); asyncOrchestratorPostPartyInput( - OBJECT_MAPPER - .createObjectNode() - .put("actionId", actionPrompt.required("actionId").asText()) - .set("input", responseSsp.toJson())); + actionPrompt.required("actionId").asText(), responseSsp.toJson()); addOperatorLogEntry( "Submitting SuppliedScenarioParameters: %s"