Skip to content

Commit

Permalink
DT-1678 Safer interface for posting party input to the orchestrator
Browse files Browse the repository at this point in the history
  • Loading branch information
gj0dcsa committed Oct 1, 2024
1 parent df84fac commit 2d3b3ab
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ private void getAdoptionStats(JsonNode actionPrompt) {
log.info("AdoptionAdopter.getAdoptionStats({})", actionPrompt);

asyncOrchestratorPostPartyInput(
OBJECT_MAPPER
.createObjectNode()

This comment has been minimized.

Copy link
@jkosternl

jkosternl Oct 2, 2024

Collaborator

Ah yes, I just missed the fact that I added here a null input object, causing the issue in the SupplyParametersAction. This is a better solution indeed.

.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)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,24 @@ public String getCounterpartRole() {
return counterpartConfiguration.getRole();
}

protected void asyncOrchestratorPostPartyInput(JsonNode jsonPartyInput) {
/**
* To be invoked like this:
* <pre>
* {@code
* asyncOrchestratorPostPartyInput(
* actionPrompt.required("actionId").asText(),
* OBJECT_MAPPER.createObjectNode()
* .put("keyOne", valueOne)
* .put("keyTwo", valueTwo));
* }
* </pre>
*/
protected void asyncOrchestratorPostPartyInput(String actionId, ObjectNode inputObjectNode) {
if (actionId == null) throw new IllegalArgumentException("The actionId may not be null");
if (inputObjectNode == null)

This comment has been minimized.

Copy link
@jkosternl

jkosternl Oct 2, 2024

Collaborator

FYI: These if () then throw can be applied with simple annotations as well.

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): {}",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2d3b3ab

Please sign in to comment.