Skip to content

Commit

Permalink
DT-623: EBL UC1 - Submit Shipping Instructions
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 4, 2023
1 parent 92a8cc8 commit 170b8c1
Show file tree
Hide file tree
Showing 14 changed files with 2,619 additions and 2,275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@

public class PersistableCarrierBooking {

private static final String[] METADATA_FIELDS_TO_PRESERVE = {
"carrierBookingRequestReference",
"carrierBookingReference",
"bookingStatus",
"amendedBookingStatus",
};

private static final Map<BookingState, Predicate<BookingState>> PREREQUISITE_STATE_FOR_TARGET_STATE = Map.ofEntries(
Map.entry(CONFIRMED, Set.of(RECEIVED, PENDING_UPDATE_CONFIRMATION, CONFIRMED)::contains),
Map.entry(REJECTED, Set.of(RECEIVED, PENDING_UPDATE, PENDING_UPDATE_CONFIRMATION)::contains),
Expand Down Expand Up @@ -60,6 +53,17 @@ public class PersistableCarrierBooking {
private static final String BOOKING_STATUS = "bookingStatus";
private static final String AMENDED_BOOKING_STATUS = "amendedBookingStatus";

private static final String CARRIER_BOOKING_REQUEST_REFERENCE = "carrierBookingRequestReference";
private static final String CARRIER_BOOKING_REFERENCE = "carrierBookingReference";


private static final String[] METADATA_FIELDS_TO_PRESERVE = {
CARRIER_BOOKING_REQUEST_REFERENCE,
CARRIER_BOOKING_REFERENCE,
BOOKING_STATUS,
AMENDED_BOOKING_STATUS,
};

private static final String BOOKING_DATA_FIELD = "booking";
private static final String AMENDED_BOOKING_DATA_FIELD = "amendedBooking";

Expand All @@ -71,11 +75,11 @@ private PersistableCarrierBooking(ObjectNode state) {
}

public String getCarrierBookingRequestReference() {
return getBooking().path("carrierBookingRequestReference").asText();
return getBooking().required(CARRIER_BOOKING_REQUEST_REFERENCE).asText();
}

public String getCarrierBookingReference() {
return getBooking().path("carrierBookingReference").asText(null);
return getBooking().path(CARRIER_BOOKING_REFERENCE).asText(null);
}

public ObjectNode getBooking() {
Expand Down Expand Up @@ -112,7 +116,7 @@ public void confirmBooking(String reference, Supplier<String> cbrGenerator, Stri
checkState(reference, getBookingState(), prerequisites);
if (this.getCarrierBookingReference() == null) {
var newCbr = cbrGenerator.get();
mutateBookingAndAmendment(b -> b.put("carrierBookingReference", newCbr));
mutateBookingAndAmendment(b -> b.put(CARRIER_BOOKING_REFERENCE, newCbr));
}
changeState(BOOKING_STATUS, CONFIRMED);
mutateBookingAndAmendment(this::ensureConfirmedBookingHasCarrierFields);
Expand Down Expand Up @@ -262,7 +266,7 @@ public BookingState getBookingState() {

public static PersistableCarrierBooking initializeFromBookingRequest(ObjectNode bookingRequest) {
String cbrr = UUID.randomUUID().toString();
bookingRequest.put("carrierBookingRequestReference", cbrr)
bookingRequest.put(CARRIER_BOOKING_REQUEST_REFERENCE, cbrr)
.put(BOOKING_STATUS, BookingState.RECEIVED.wireName());
var state = OBJECT_MAPPER.createObjectNode();
state.set(BOOKING_DATA_FIELD, bookingRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ private void sendBookingRequest(JsonNode actionPrompt) {
jsonRequestBody,
conformanceResponse -> {
JsonNode jsonBody = conformanceResponse.message().body().getJsonBody();
String cbrr = jsonBody.get("carrierBookingRequestReference").asText();
String bookingStatus = jsonBody.get("bookingStatus").asText();
String cbrr = jsonBody.path("carrierBookingRequestReference").asText();
String bookingStatus = jsonBody.path("bookingStatus").asText();
ObjectNode updatedBooking =
((ObjectNode) jsonRequestBody)
.put("bookingStatus", bookingStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public class EblScenarioListBuilder extends ScenarioListBuilder<EblScenarioListB
private static final ThreadLocal<String> threadLocalShipperPartyName = new ThreadLocal<>();

private static final String EBL_API = "api";
private static final String GET_EBL_SCHEMA_NAME = "ShippingInstructions";

private static final String EBL_NOTIFICATIONS_API = "notification";
private static final String GET_EBL_SCHEMA_NAME = "ShippingInstructionsResponse";
private static final String POST_EBL_SCHEMA_NAME = "ShippingInstructionsRequest";
private static final String EBL_REF_STATUS_SCHEMA_NAME = "ShippingInstructionsRefStatus";
private static final String EBL_SI_NOTIFICATION_SCHEMA_NAME = "ShippingInstructionsNotification";

public static EblScenarioListBuilder buildTree(
EblComponentFactory componentFactory, String carrierPartyName, String shipperPartyName) {
Expand Down Expand Up @@ -99,7 +104,18 @@ private static EblScenarioListBuilder shipper_GetShippingInstructions(
}

private static EblScenarioListBuilder uc1_shipper_submitShippingInstructions() {
return noAction();
EblComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
previousAction ->
new UC1_Shipper_SubmitShippingInstructionsAction(
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
componentFactory.getMessageSchemaValidator(EBL_API, POST_EBL_SCHEMA_NAME),
componentFactory.getMessageSchemaValidator(EBL_API, EBL_REF_STATUS_SCHEMA_NAME),
componentFactory.getMessageSchemaValidator(EBL_NOTIFICATIONS_API, EBL_SI_NOTIFICATION_SCHEMA_NAME)));
}

private static EblScenarioListBuilder uc6_carrier_publishDraftTransportDocument() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ public String getHumanReadablePrompt() {

@Override
public JsonNode getJsonForHumanReadablePrompt() {
return new CarrierScenarioParameters("Example Carrier Service", "1234567890").toJson();
return new CarrierScenarioParameters(
"Booking ref X",
"Commodity Subref for X",
"APZU4812090",
"DKCPH",
"Consignment Item HS Code",
"Shoes"

).toJson();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private <T> DynamicScenarioParameters updateIfNotNull(
return with.apply(value);
}

protected Stream<ActionCheck> getNotificationChecks(
protected Stream<ActionCheck> getSINotificationChecks(
String expectedApiVersion, JsonSchemaValidator notificationSchemaValidator) {
String titlePrefix = "[Notification]";
return Stream.of(
Expand All @@ -161,7 +161,7 @@ protected Stream<ActionCheck> getNotificationChecks(
titlePrefix,
EblRole::isCarrier,
getMatchedNotificationExchangeUuid(),
"/v2/shipping-instruction-notifications"),
"/v3/shipping-instructions-notifications"),
new ResponseStatusCheck(
titlePrefix, EblRole::isShipper, getMatchedNotificationExchangeUuid(), 204),
new ApiHeaderCheck(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
new UrlPathCheck(
EblRole::isShipper,
getMatchedExchangeUuid(),
"/v2/shipping-instructions/" + getDspSupplier().get().shippingInstructionsReference()),
"/v3/shipping-instructions/" + getDspSupplier().get().shippingInstructionsReference()),
new ResponseStatusCheck(
EblRole::isCarrier, getMatchedExchangeUuid(), expectedStatus),
new ApiHeaderCheck(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.dcsa.conformance.standards.ebl.action;

import org.dcsa.conformance.core.traffic.ConformanceExchange;

public abstract class StateChangingSIAction extends EblAction {
protected StateChangingSIAction(String sourcePartyName, String targetPartyName, EblAction previousAction, String actionTitle, int expectedStatus) {
super(sourcePartyName, targetPartyName, previousAction, actionTitle, expectedStatus);
}

@Override
protected void doHandleExchange(ConformanceExchange exchange) {
super.doHandleExchange(exchange);
updateDSPFromResponsePayload(exchange);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.dcsa.conformance.standards.ebl.action;

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

@Getter
@Slf4j
public class UC1_Shipper_SubmitShippingInstructionsAction extends StateChangingSIAction {
private final JsonSchemaValidator requestSchemaValidator;
private final JsonSchemaValidator responseSchemaValidator;
private final JsonSchemaValidator notificationSchemaValidator;

public UC1_Shipper_SubmitShippingInstructionsAction(
String carrierPartyName,
String shipperPartyName,
EblAction previousAction,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator,
JsonSchemaValidator notificationSchemaValidator) {
super(shipperPartyName, carrierPartyName, previousAction, "UC1", 201);
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
this.notificationSchemaValidator = notificationSchemaValidator;
}

@Override
public String getHumanReadablePrompt() {
return ("UC1: Submit a booking request using the following parameters:");
}

@Override
public ObjectNode asJsonNode() {
ObjectNode jsonNode = super.asJsonNode();
jsonNode.set("csp", getCspSupplier().get().toJson());
return jsonNode;
}

@Override
protected boolean expectsNotificationExchange() {
return true;
}

@Override
public ConformanceCheck createCheck(String expectedApiVersion) {
return new ConformanceCheck(getActionTitle()) {
@Override
protected Stream<? extends ConformanceCheck> createSubChecks() {
Stream<ActionCheck> primaryExchangeChecks =
Stream.of(
new HttpMethodCheck(EblRole::isShipper, getMatchedExchangeUuid(), "POST"),
new UrlPathCheck(EblRole::isShipper, getMatchedExchangeUuid(), "/v3/shipping-instructions"),
new ResponseStatusCheck(
EblRole::isCarrier, getMatchedExchangeUuid(), expectedStatus),
new ApiHeaderCheck(
EblRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
expectedApiVersion),
new ApiHeaderCheck(
EblRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
expectedApiVersion),
// TODO: Add Carrier Ref Status Payload response check
// TODO: Add Shipper content conformance check
new JsonSchemaCheck(
EblRole::isShipper,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator),
new JsonSchemaCheck(
EblRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator));
return Stream.concat(
primaryExchangeChecks,
getSINotificationChecks(
expectedApiVersion,
notificationSchemaValidator));
}
};
}
}
Loading

0 comments on commit 170b8c1

Please sign in to comment.