Skip to content

Commit

Permalink
DT-641: UC13 - Carrier - process transport document surrendered for d…
Browse files Browse the repository at this point in the history
…elivery

Signed-off-by: Niels Thykier <[email protected]>
  • Loading branch information
nt-gt committed Dec 7, 2023
1 parent d77eb70 commit f3df5c9
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,18 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
.thenAllPathsFrom(TD_ISSUED)));
case TD_ISSUED -> then(
uc12_carrier_awaitSurrenderRequestForDelivery()
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY))
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY)
.thenAllPathsFrom(TD_PENDING_SURRENDER_FOR_DELIVERY))
);
case TD_PENDING_SURRENDER_FOR_DELIVERY -> thenEither(
uc13a_carrier_acceptSurrenderRequestForDelivery().then(
shipper_GetTransportDocument(TD_SURRENDERED_FOR_DELIVERY)
.thenAllPathsFrom(TD_SURRENDERED_FOR_DELIVERY)
),
uc13r_carrier_rejectSurrenderRequestForDelivery().then(
shipper_GetTransportDocument(TD_SURRENDERED_FOR_DELIVERY)
.thenHappyPathFrom(TD_ISSUED)
)
);
default -> then(noAction()); // TODO
};
Expand All @@ -123,7 +134,14 @@ private EblScenarioListBuilder thenHappyPathFrom(TransportDocumentStatus transpo
return switch (transportDocumentStatus) {
case TD_ISSUED -> then(
uc12_carrier_awaitSurrenderRequestForDelivery()
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY))
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY)
.thenHappyPathFrom(TD_PENDING_SURRENDER_FOR_DELIVERY))
);
case TD_PENDING_SURRENDER_FOR_DELIVERY -> then(
uc13a_carrier_acceptSurrenderRequestForDelivery().then(
shipper_GetTransportDocument(TD_SURRENDERED_FOR_DELIVERY)
.thenHappyPathFrom(TD_SURRENDERED_FOR_DELIVERY)
)
);
default -> then(noAction()); // TODO
};
Expand Down Expand Up @@ -314,4 +332,34 @@ private static EblScenarioListBuilder uc12_carrier_awaitSurrenderRequestForDeliv
componentFactory.getMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_TD_NOTIFICATION_SCHEMA_NAME)));
}

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

private static EblScenarioListBuilder uc13r_carrier_rejectSurrenderRequestForDelivery() {
EblComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
previousAction ->
new UC13_Carrier_ProcessSurrenderRequestForDeliveryAction(
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
componentFactory.getMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_TD_NOTIFICATION_SCHEMA_NAME),
false));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 UC13_Carrier_ProcessSurrenderRequestForDeliveryAction extends StateChangingSIAction {
private final JsonSchemaValidator requestSchemaValidator;
private final boolean acceptDeliveryRequest;

public UC13_Carrier_ProcessSurrenderRequestForDeliveryAction(
String carrierPartyName,
String shipperPartyName,
EblAction previousAction,
JsonSchemaValidator requestSchemaValidator,
boolean acceptDeliveryRequest) {
super(carrierPartyName, shipperPartyName, previousAction, acceptDeliveryRequest ? "UC13a" : "UC13r", 204);
this.requestSchemaValidator = requestSchemaValidator;
this.acceptDeliveryRequest = acceptDeliveryRequest;
}

@Override
public String getHumanReadablePrompt() {
if (acceptDeliveryRequest) {
return ("UC13a: Accept surrender request for delivery for transport document with reference %s"
.formatted(getDspSupplier().get().transportDocumentReference()));
}
return ("UC13r: Reject surrender request for delivery for transport document with reference %s"
.formatted(getDspSupplier().get().transportDocumentReference()));
}

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

@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 @@ -24,10 +24,10 @@ public UC4_Carrier_ProcessUpdateToShippingInstructionsAction(
@Override
public String getHumanReadablePrompt() {
if (acceptChanges) {
return ("UC4: Accept updated shipping instructions with document reference %s"
return ("UC4a: Accept updated shipping instructions with document reference %s"
.formatted(getDspSupplier().get().shippingInstructionsReference()));
}
return ("UC4: Decline updated shipping instructions with document reference %s"
return ("UC4d: Decline updated shipping instructions with document reference %s"
.formatted(getDspSupplier().get().shippingInstructionsReference()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ public void declineUpdatedShippingInstructions(String documentReference, String
changeSIState(UPDATED_SI_STATUS, SI_DECLINED);
}

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

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

public void publishDraftTransportDocument(String documentReference) {
// SI_DECLINED only applies to the updated SI. UC1 -> UC3 -> UC4 (decline) -> UC6 is applicable and
// in this case, the SI would be in RECEIVED with updated state SI_DECLINED.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ protected Map<Class<? extends ConformanceAction>, Consumer<JsonNode>> getActionP
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(UC12_Carrier_AwaitSurrenderRequestForDeliveryAction.class, this::notifyOfSurrenderForDelivery)
Map.entry(UC12_Carrier_AwaitSurrenderRequestForDeliveryAction.class, this::notifyOfSurrenderForDelivery),
Map.entry(UC13_Carrier_ProcessSurrenderRequestForDeliveryAction.class, this::processSurrenderRequestForDelivery)
);
}

Expand Down Expand Up @@ -137,7 +138,7 @@ private void processUpdatedShippingInstructions(JsonNode actionPrompt) {
private void publishDraftTransportDocument(JsonNode actionPrompt) {
log.info("Carrier.publishDraftTransportDocument(%s)".formatted(actionPrompt.toPrettyString()));

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

var si = CarrierShippingInstructions.fromPersistentStore(persistentMap, sir);
Expand All @@ -152,7 +153,7 @@ private void publishDraftTransportDocument(JsonNode actionPrompt) {
private void issueTransportDocument(JsonNode actionPrompt) {
log.info("Carrier.issueTransportDocument(%s)".formatted(actionPrompt.toPrettyString()));

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

var si = CarrierShippingInstructions.fromPersistentStore(persistentMap, sir);
Expand All @@ -166,18 +167,37 @@ private void issueTransportDocument(JsonNode actionPrompt) {
private void notifyOfSurrenderForDelivery(JsonNode actionPrompt) {
log.info("Carrier.notifyOfSurrenderForDelivery(%s)".formatted(actionPrompt.toPrettyString()));

var documentReference = actionPrompt.get("documentReference").asText();
var documentReference = actionPrompt.required("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));
addOperatorLogEntry("Sent notification for surrender for delivery of transport document with reference '%s'".formatted(documentReference));
}


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

var documentReference = actionPrompt.required("documentReference").asText();
var sir = tdrToSir.getOrDefault(documentReference, documentReference);
var accept = actionPrompt.required("acceptDeliveryRequest").asBoolean(true);

var si = CarrierShippingInstructions.fromPersistentStore(persistentMap, sir);
if (accept) {
si.acceptSurrenderForDelivery(documentReference);
} else {
si.rejectSurrenderForDelivery(documentReference);
}
si.save(persistentMap);
generateAndEmitNotificationFromTransportDocument(actionPrompt, si, true);

addOperatorLogEntry("Processed surrender request for delivery of transport document with reference '%s'".formatted(documentReference));
}

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

0 comments on commit f3df5c9

Please sign in to comment.