Skip to content

Commit

Permalink
DT-741: UC14 - Carrier - Confirm Shipping Instructions complete
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 7, 2023
1 parent f3df5c9 commit c25d44d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
.thenHappyPathFrom(TD_ISSUED)
)
);
case TD_SURRENDERED_FOR_DELIVERY -> thenHappyPathFrom(transportDocumentStatus);
default -> then(noAction()); // TODO
};
}

private EblScenarioListBuilder thenHappyPathFrom(TransportDocumentStatus transportDocumentStatus) {
return switch (transportDocumentStatus) {
case TD_DRAFT -> then(
uc8_carrier_issueTransportDocument()
.then(
shipper_GetTransportDocument(TD_ISSUED)
.thenAllPathsFrom(TD_ISSUED)));
case TD_ISSUED -> then(
uc12_carrier_awaitSurrenderRequestForDelivery()
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY)
Expand All @@ -143,6 +149,11 @@ private EblScenarioListBuilder thenHappyPathFrom(TransportDocumentStatus transpo
.thenHappyPathFrom(TD_SURRENDERED_FOR_DELIVERY)
)
);
case TD_SURRENDERED_FOR_DELIVERY -> then(
uc14_carrier_confirmShippingInstructionsComplete().then(
shipper_GetShippingInstructions(SI_COMPLETED, TD_SURRENDERED_FOR_DELIVERY)
)
);
default -> then(noAction()); // TODO
};
}
Expand Down Expand Up @@ -362,4 +373,19 @@ private static EblScenarioListBuilder uc13r_carrier_rejectSurrenderRequestForDel
EBL_NOTIFICATIONS_API, EBL_TD_NOTIFICATION_SCHEMA_NAME),
false));
}


private static EblScenarioListBuilder uc14_carrier_confirmShippingInstructionsComplete() {
EblComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String shipperPartyName = threadLocalShipperPartyName.get();
return new EblScenarioListBuilder(
previousAction ->
new UC14_Carrier_ConfirmShippingInstructionsCompleteAction(
carrierPartyName,
shipperPartyName,
(EblAction) previousAction,
componentFactory.getMessageSchemaValidator(
EBL_NOTIFICATIONS_API, EBL_TD_NOTIFICATION_SCHEMA_NAME)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String getHumanReadablePrompt() {
@Override
public ObjectNode asJsonNode() {
return super.asJsonNode()
.put("documentReference", getDspSupplier().get().shippingInstructionsReference());
.put("documentReference", getDspSupplier().get().transportDocumentReference());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String getHumanReadablePrompt() {
@Override
public ObjectNode asJsonNode() {
return super.asJsonNode()
.put("documentReference", getDspSupplier().get().shippingInstructionsReference())
.put("documentReference", getDspSupplier().get().transportDocumentReference())
.put("acceptDeliveryRequest", acceptDeliveryRequest);
}

Expand Down
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 UC14_Carrier_ConfirmShippingInstructionsCompleteAction extends StateChangingSIAction {
private final JsonSchemaValidator requestSchemaValidator;

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

@Override
public String getHumanReadablePrompt() {
return ("UC14: Confirm shipping instructions with reference %s is complete."
.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 getTDNotificationChecks(
getMatchedExchangeUuid(),
expectedApiVersion,
requestSchemaValidator
);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public void declineUpdatedShippingInstructions(String documentReference, String
changeSIState(UPDATED_SI_STATUS, SI_DECLINED);
}

public void confirmShippingInstructionsComplete(String documentReference) {
checkState(documentReference, getOriginalShippingInstructionState(), s -> s == SI_RECEIVED);
changeSIState(SI_STATUS, SI_COMPLETED);
}

public void acceptSurrenderForDelivery(String documentReference) {
checkState(documentReference, getTransportDocumentState(), s -> s == TD_PENDING_SURRENDER_FOR_DELIVERY);
var td = getTransportDocument().orElseThrow();
Expand Down Expand Up @@ -305,6 +310,12 @@ public void putShippingInstructions(String documentReference, ObjectNode newShip
removeRequestedChanges();
}

public ShippingInstructionsStatus getOriginalShippingInstructionState() {
var siData = getShippingInstructions();
var s = siData.required(SI_STATUS);
return ShippingInstructionsStatus.fromWireName(s.asText());
}

public ShippingInstructionsStatus getShippingInstructionsState() {
var siData = getShippingInstructions();
var s = siData.path(UPDATED_SI_STATUS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ protected Map<Class<? extends ConformanceAction>, Consumer<JsonNode>> getActionP
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(UC13_Carrier_ProcessSurrenderRequestForDeliveryAction.class, this::processSurrenderRequestForDelivery)
Map.entry(UC13_Carrier_ProcessSurrenderRequestForDeliveryAction.class, this::processSurrenderRequestForDelivery),
Map.entry(UC14_Carrier_ConfirmShippingInstructionsCompleteAction.class, this::confirmShippingInstructionsComplete)
);
}

Expand Down Expand Up @@ -198,6 +199,20 @@ private void processSurrenderRequestForDelivery(JsonNode actionPrompt) {
addOperatorLogEntry("Processed surrender request for delivery of transport document with reference '%s'".formatted(documentReference));
}

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

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

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

addOperatorLogEntry("Confirmed shipping instructions with reference %s is complete".formatted(documentReference));
}

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

0 comments on commit c25d44d

Please sign in to comment.