Skip to content

Commit

Permalink
DT-626: UC6 - Carrier - Publish draft transport document
Browse files Browse the repository at this point in the history
Signed-off-by: Niels Thykier <[email protected]>
  • Loading branch information
nt-gt committed Dec 5, 2023
1 parent aad5591 commit 0368e6b
Show file tree
Hide file tree
Showing 9 changed files with 503 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public class EblScenarioListBuilder extends ScenarioListBuilder<EblScenarioListB

private static final String EBL_NOTIFICATIONS_API = "notification";
private static final String GET_EBL_SCHEMA_NAME = "ShippingInstructionsResponse";
private static final String GET_TD_SCHEMA_NAME = "getTransportDocument";
private static final String POST_EBL_SCHEMA_NAME = "ShippingInstructionsRequest";
private static final String PUT_EBL_SCHEMA_NAME = "ShippingInstructionsUpdate";
private static final String EBL_REF_STATUS_SCHEMA_NAME = "ShippingInstructionsRefStatus";
private static final String EBL_SI_NOTIFICATION_SCHEMA_NAME = "ShippingInstructionsNotification";
private static final String EBL_TD_NOTIFICATION_SCHEMA_NAME = "TransportDocumentNotification";

public static EblScenarioListBuilder buildTree(
EblComponentFactory componentFactory, String carrierPartyName, String shipperPartyName) {
Expand All @@ -51,19 +53,16 @@ private EblScenarioListBuilder thenAllPathsFrom(
uc3_shipper_submitUpdatedShippingInstructions()
.then(
shipper_GetShippingInstructions(SI_RECEIVED, SI_UPDATE_RECEIVED, TD_START)
.thenEither(uc6_carrier_publishDraftTransportDocument()
.then(
shipper_GetShippingInstructions(SI_RECEIVED, TD_DRAFT)
.thenAllPathsFrom(TD_DRAFT)
),
.then(
uc2_carrier_requestUpdateToShippingInstruction()
.then(shipper_GetShippingInstructions(SI_PENDING_UPDATE, TD_START)
.thenHappyPathFrom(SI_PENDING_UPDATE)))),
uc6_carrier_publishDraftTransportDocument()
.then(
shipper_GetShippingInstructions(SI_RECEIVED, TD_DRAFT)
.thenAllPathsFrom(TD_DRAFT)));
default -> null; // TODO
shipper_GetShippingInstructions(SI_RECEIVED, TD_DRAFT, true)
.then(shipper_GetTransportDocument(TD_DRAFT)
.thenAllPathsFrom(TD_DRAFT))));
default -> then(noAction()); // TODO
};
}

Expand All @@ -79,7 +78,7 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
.then(
shipper_GetShippingInstructions(SI_ANY, TD_ISSUED).thenAllPathsFrom(TD_ISSUED)));
case TD_ISSUED -> then(noAction()); // TODO
default -> null; // TODO
default -> then(noAction()); // TODO
};
}

Expand All @@ -106,23 +105,54 @@ private static EblScenarioListBuilder shipper_GetShippingInstructions(
ShippingInstructionsStatus expectedSiStatus, TransportDocumentStatus expectedTdStatus) {
return shipper_GetShippingInstructions(expectedSiStatus, null, expectedTdStatus);
}

private static EblScenarioListBuilder shipper_GetShippingInstructions(
ShippingInstructionsStatus expectedSiStatus, TransportDocumentStatus expectedTdStatus, boolean recordTDR) {
return shipper_GetShippingInstructions(expectedSiStatus, null, expectedTdStatus, false, recordTDR);
}

private static EblScenarioListBuilder shipper_GetShippingInstructions(
ShippingInstructionsStatus expectedSiStatus,
ShippingInstructionsStatus expectedUpdatedSiStatus,
TransportDocumentStatus expectedTdStatus) {
return shipper_GetShippingInstructions(expectedSiStatus, expectedUpdatedSiStatus, expectedTdStatus, false, false);
}

private static EblScenarioListBuilder shipper_GetShippingInstructions(
ShippingInstructionsStatus expectedSiStatus,
ShippingInstructionsStatus expectedUpdatedSiStatus,
TransportDocumentStatus expectedTdStatus) {
ShippingInstructionsStatus expectedSiStatus,
ShippingInstructionsStatus expectedUpdatedSiStatus,
TransportDocumentStatus expectedTdStatus,
boolean requestAmendedSI,
boolean recordTDR) {
EblComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
previousAction ->
new Shipper_GetShippingInstructionsAction(
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
expectedSiStatus,
expectedUpdatedSiStatus,
componentFactory.getMessageSchemaValidator(EBL_API, GET_EBL_SCHEMA_NAME),
requestAmendedSI,
recordTDR));
}

private static EblScenarioListBuilder shipper_GetTransportDocument(
TransportDocumentStatus expectedTdStatus) {
EblComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
previousAction ->
new Shipper_GetShippingInstructionsAction(
new Shipper_GetTransportDocumentAction(
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
expectedSiStatus,
expectedUpdatedSiStatus,
componentFactory.getMessageSchemaValidator(EBL_API, GET_EBL_SCHEMA_NAME),
false));
expectedTdStatus,
componentFactory.getMessageSchemaValidator(EBL_API, GET_TD_SCHEMA_NAME)));
}

private static EblScenarioListBuilder uc1_shipper_submitShippingInstructions() {
Expand Down Expand Up @@ -171,7 +201,17 @@ private static EblScenarioListBuilder uc2_carrier_requestUpdateToShippingInstruc
}

private static EblScenarioListBuilder uc6_carrier_publishDraftTransportDocument() {
return noAction();
EblComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
previousAction ->
new UC6_Carrier_PublishDraftTransportDocumentAction(
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
componentFactory.getMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_TD_NOTIFICATION_SCHEMA_NAME)));
}

private static EblScenarioListBuilder uc8_carrier_issueTransportDocument() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ protected Supplier<DynamicScenarioParameters> getDspSupplier() {
return dspReference::get;
}

protected void updateDSPFromResponsePayload(ConformanceExchange exchange) {
protected Consumer<DynamicScenarioParameters> getDspConsumer() {
return dspReference::set;
}

protected void updateDSPFromSIResponsePayload(ConformanceExchange exchange) {
DynamicScenarioParameters dsp = dspReference.get();

JsonNode responseJsonNode = exchange.getResponse().message().body().getJsonBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.stream.Stream;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.traffic.ConformanceExchange;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.ebl.party.EblRole;
import org.dcsa.conformance.standards.ebl.party.ShippingInstructionsStatus;
Expand All @@ -13,6 +14,7 @@ public class Shipper_GetShippingInstructionsAction extends EblAction {
private final ShippingInstructionsStatus expectedAmendedSiStatus;
private final JsonSchemaValidator responseSchemaValidator;
private final boolean requestAmendedStatus;
private final boolean recordTDR;

public Shipper_GetShippingInstructionsAction(
String carrierPartyName,
Expand All @@ -21,19 +23,20 @@ public Shipper_GetShippingInstructionsAction(
ShippingInstructionsStatus expectedSiStatus,
ShippingInstructionsStatus expectedAmendedSiStatus,
JsonSchemaValidator responseSchemaValidator,
boolean requestAmendedStatus) {
super(shipperPartyName, carrierPartyName, previousAction, "GET", 200);
boolean requestAmendedStatus,
boolean recordTDR) {
super(shipperPartyName, carrierPartyName, previousAction, requestAmendedStatus ? "GET aSI" : "GET SI", 200);
this.expectedSiStatus = expectedSiStatus;
this.expectedAmendedSiStatus = expectedAmendedSiStatus;
this.responseSchemaValidator = responseSchemaValidator;
this.requestAmendedStatus = requestAmendedStatus;
this.recordTDR = recordTDR;
}

@Override
public ObjectNode asJsonNode() {
ObjectNode jsonNode = super.asJsonNode();
jsonNode.put("sir", getDspSupplier().get().shippingInstructionsReference());
return jsonNode;
return super.asJsonNode()
.put("sir", getDspSupplier().get().shippingInstructionsReference());
}

@Override
Expand All @@ -42,6 +45,17 @@ public String getHumanReadablePrompt() {
.formatted(getDspSupplier().get().shippingInstructionsReference());
}

protected void doHandleExchange(ConformanceExchange exchange) {
super.doHandleExchange(exchange);
if (recordTDR) {
var dsp = getDspSupplier().get();
var tdr = exchange.getResponse().message().body().getJsonBody().path("transportDocumentReference");
if (!tdr.isMissingNode()) {
getDspConsumer().accept(dsp.withTransportDocumentReference(tdr.asText()));
}
}
}

@Override
public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.dcsa.conformance.standards.ebl.action;

import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.stream.Stream;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.ebl.party.*;

public class Shipper_GetTransportDocumentAction extends EblAction {

private final TransportDocumentStatus expectedTdStatus;
private final JsonSchemaValidator responseSchemaValidator;

public Shipper_GetTransportDocumentAction(
String carrierPartyName,
String shipperPartyName,
EblAction previousAction,
TransportDocumentStatus expectedTdStatus,
JsonSchemaValidator responseSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "GET TD", 200);
this.expectedTdStatus = expectedTdStatus;
this.responseSchemaValidator = responseSchemaValidator;
}

@Override
public ObjectNode asJsonNode() {
return super.asJsonNode()
.put("tdr", getDspSupplier().get().transportDocumentReference());
}


@Override
public String getHumanReadablePrompt() {
return "GET the TD with reference '%s'"
.formatted(getDspSupplier().get().transportDocumentReference());
}

@Override
public ConformanceCheck createCheck(String expectedApiVersion) {
var dsp = getDspSupplier().get();
var tdr = dsp.transportDocumentReference() != null ? dsp.transportDocumentReference() : "<UNKNOWN-TDR>";
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
return Stream.of(
new UrlPathCheck(
EblRole::isShipper,
getMatchedExchangeUuid(),
"/v3/transport-documents/" + tdr),
new ResponseStatusCheck(
EblRole::isCarrier, getMatchedExchangeUuid(), expectedStatus),
new ApiHeaderCheck(
EblRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
expectedApiVersion),
new ApiHeaderCheck(
EblRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
expectedApiVersion));
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ protected StateChangingSIAction(String sourcePartyName, String targetPartyName,
@Override
protected void doHandleExchange(ConformanceExchange exchange) {
super.doHandleExchange(exchange);
updateDSPFromResponsePayload(exchange);
updateDSPFromSIResponsePayload(exchange);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.dcsa.conformance.standards.ebl.action;

import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.stream.Stream;
import lombok.Getter;
import org.dcsa.conformance.core.check.*;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.ebl.party.EblRole;

@Getter
public class UC6_Carrier_PublishDraftTransportDocumentAction extends StateChangingSIAction {
private final JsonSchemaValidator requestSchemaValidator;

public UC6_Carrier_PublishDraftTransportDocumentAction(
String carrierPartyName,
String shipperPartyName,
EblAction previousAction,
JsonSchemaValidator requestSchemaValidator) {
super(carrierPartyName, shipperPartyName, previousAction, "UC6", 204);
this.requestSchemaValidator = requestSchemaValidator;
}

@Override
public String getHumanReadablePrompt() {
return ("UC6: Publish draft transport document for shipping instructions with reference %s"
.formatted(getDspSupplier().get().shippingInstructionsReference()));
}

@Override
public ObjectNode asJsonNode() {
return super.asJsonNode()
.put("documentReference", getDspSupplier().get().shippingInstructionsReference());
}

@Override
public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
return Stream.of(
new HttpMethodCheck(EblRole::isCarrier, getMatchedExchangeUuid(), "POST"),
new UrlPathCheck(
EblRole::isCarrier, getMatchedExchangeUuid(), "/v3/transport-document-notifications"),
new ResponseStatusCheck(
EblRole::isShipper, getMatchedExchangeUuid(), expectedStatus),
// TODO: Notification payload check
new ApiHeaderCheck(
EblRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
expectedApiVersion),
new ApiHeaderCheck(
EblRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
expectedApiVersion),
new JsonSchemaCheck(
EblRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator));
}
};
}
}
Loading

0 comments on commit 0368e6b

Please sign in to comment.