Skip to content

Commit

Permalink
DT-640: UC12 - request surrender of transport docuemnt for delivery
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 6, 2023
1 parent bf8393f commit db8b982
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,22 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
.then(
shipper_GetTransportDocument(TD_ISSUED)
.thenAllPathsFrom(TD_ISSUED)));
case TD_ISSUED -> then(noAction()); // TODO
case TD_ISSUED -> then(
uc12_carrier_awaitSurrenderRequestForDelivery()
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY))
);
default -> then(noAction()); // TODO
};
}

private EblScenarioListBuilder thenHappyPathFrom(TransportDocumentStatus tdStatus) {
return then(noAction()); // TODO
private EblScenarioListBuilder thenHappyPathFrom(TransportDocumentStatus transportDocumentStatus) {
return switch (transportDocumentStatus) {
case TD_ISSUED -> then(
uc12_carrier_awaitSurrenderRequestForDelivery()
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY))
);
default -> then(noAction()); // TODO
};
}

private EblScenarioListBuilder(Function<ConformanceAction, ConformanceAction> actionBuilder) {
Expand Down Expand Up @@ -291,4 +300,18 @@ private static EblScenarioListBuilder uc8_carrier_issueTransportDocument() {
componentFactory.getMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_TD_NOTIFICATION_SCHEMA_NAME)));
}

private static EblScenarioListBuilder uc12_carrier_awaitSurrenderRequestForDelivery() {
EblComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
previousAction ->
new UC12_Carrier_AwaitSurrenderRequestForDeliveryAction(
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
componentFactory.getMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_TD_NOTIFICATION_SCHEMA_NAME)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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.*;

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

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

@Override
public String getHumanReadablePrompt() {
return ("UC12: Shipper requests surrender for delivery (via the surrender API if applicable) for transport document with reference %s and carrier sends notification that surrender has been requested. Note when the conformance toolkit is acting as carrier, no action is required from the shipper (the action will auto-resolve). When the conformance toolkit is acting like the Shipper, you will have to ensure that the carrier system sees a surrender request (the surrender uses a different API not in scope for this test)."
.formatted(getDspSupplier().get().transportDocumentReference()));
}

@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 getTDNotificationChecks(
getMatchedExchangeUuid(),
expectedApiVersion,
requestSchemaValidator
);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ public void issueTransportDocument(String documentReference) {
.put(shippedDateField, date);
}

public void surrenderForDeliveryRequest(String documentReference) {
checkState(documentReference, getTransportDocumentState(), s -> s == TD_ISSUED);
var td = getTransportDocument().orElseThrow();
td.put(TRANSPORT_DOCUMENT_STATUS, TD_PENDING_SURRENDER_FOR_DELIVERY.wireName());
}

private void copyFieldIfPresent(JsonNode source, ObjectNode dest, String field) {
var data = source.get(field);
if (data != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ protected Map<Class<? extends ConformanceAction>, Consumer<JsonNode>> getActionP
Map.entry(UC2_Carrier_RequestUpdateToShippingInstructionsAction.class, this::requestUpdateToShippingInstructions),
Map.entry(UC4_Carrier_ProcessUpdateToShippingInstructionsAction.class, this::processUpdatedShippingInstructions),
Map.entry(UC6_Carrier_PublishDraftTransportDocumentAction.class, this::publishDraftTransportDocument),
Map.entry(UC8_Carrier_IssueTransportDocumentAction.class, this::issueTransportDocument)
Map.entry(UC8_Carrier_IssueTransportDocumentAction.class, this::issueTransportDocument),
Map.entry(UC12_Carrier_AwaitSurrenderRequestForDeliveryAction.class, this::notifyOfSurrenderForDelivery)
);
}

Expand Down Expand Up @@ -162,6 +163,21 @@ private void issueTransportDocument(JsonNode actionPrompt) {
addOperatorLogEntry("Issued transport document '%s'".formatted(documentReference));
}

private void notifyOfSurrenderForDelivery(JsonNode actionPrompt) {
log.info("Carrier.notifyOfSurrenderForDelivery(%s)".formatted(actionPrompt.toPrettyString()));

var documentReference = actionPrompt.get("documentReference").asText();
var sir = tdrToSir.getOrDefault(documentReference, documentReference);

var si = CarrierShippingInstructions.fromPersistentStore(persistentMap, sir);
si.surrenderForDeliveryRequest(documentReference);
si.save(persistentMap);
generateAndEmitNotificationFromTransportDocument(actionPrompt, si, true);

addOperatorLogEntry("Sent notification for surrender for delivery of transport document '%s'".formatted(documentReference));
}


private void generateAndEmitNotificationFromShippingInstructions(JsonNode actionPrompt, CarrierShippingInstructions shippingInstructions, boolean includeShippingInstructionsReference) {
var notification =
ShippingInstructionsNotification.builder()
Expand Down

0 comments on commit db8b982

Please sign in to comment.