Skip to content

Commit

Permalink
DT-638: UC10 - Carrier - Process Transport Document Surrender Request…
Browse files Browse the repository at this point in the history
… for Amendment

Signed-off-by: Niels Thykier <[email protected]>
  • Loading branch information
nt-gt committed Dec 7, 2023
1 parent 8ff3c18 commit e342e05
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,24 @@ private EblScenarioListBuilder thenAllPathsFrom(TransportDocumentStatus transpor
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY)
.thenAllPathsFrom(TD_PENDING_SURRENDER_FOR_DELIVERY))
);
case TD_PENDING_SURRENDER_FOR_AMENDMENT -> then(noAction()); // TODO: Implement
case TD_PENDING_SURRENDER_FOR_AMENDMENT -> thenEither(
uc10a_carrier_acceptSurrenderRequestForAmendment().then(
shipper_GetTransportDocument(TD_SURRENDERED_FOR_AMENDMENT)
.thenAllPathsFrom(TD_SURRENDERED_FOR_AMENDMENT)
),
uc10r_carrier_rejectSurrenderRequestForAmendment().then(
shipper_GetTransportDocument(TD_ISSUED)
.thenHappyPathFrom(TD_ISSUED)
)
);
case TD_SURRENDERED_FOR_AMENDMENT -> then(noAction()); // TODO: Implement
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)
shipper_GetTransportDocument(TD_ISSUED)
.thenHappyPathFrom(TD_ISSUED)
)
);
Expand All @@ -151,13 +161,19 @@ private EblScenarioListBuilder thenHappyPathFrom(TransportDocumentStatus transpo
uc8_carrier_issueTransportDocument()
.then(
shipper_GetTransportDocument(TD_ISSUED)
.thenAllPathsFrom(TD_ISSUED)));
.thenHappyPathFrom(TD_ISSUED)));
case TD_ISSUED -> then(
uc12_carrier_awaitSurrenderRequestForDelivery()
.then(shipper_GetTransportDocument(TD_PENDING_SURRENDER_FOR_DELIVERY)
.thenHappyPathFrom(TD_PENDING_SURRENDER_FOR_DELIVERY))
);
case TD_PENDING_SURRENDER_FOR_AMENDMENT -> then(noAction()); // TODO: Implement
case TD_PENDING_SURRENDER_FOR_AMENDMENT -> then(
uc10a_carrier_acceptSurrenderRequestForAmendment().then(
shipper_GetTransportDocument(TD_SURRENDERED_FOR_AMENDMENT)
.thenHappyPathFrom(TD_SURRENDERED_FOR_AMENDMENT)
)
);
case TD_SURRENDERED_FOR_AMENDMENT -> then(noAction()); // TODO: Implement
case TD_PENDING_SURRENDER_FOR_DELIVERY -> then(
uc13a_carrier_acceptSurrenderRequestForDelivery().then(
shipper_GetTransportDocument(TD_SURRENDERED_FOR_DELIVERY)
Expand Down Expand Up @@ -361,6 +377,36 @@ private static EblScenarioListBuilder uc9_carrier_awaitSurrenderRequestForAmendm
EBL_NOTIFICATIONS_API, EBL_TD_NOTIFICATION_SCHEMA_NAME)));
}

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

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

private static EblScenarioListBuilder uc12_carrier_awaitSurrenderRequestForDelivery() {
EblComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
Expand Down
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 UC10_Carrier_ProcessSurrenderRequestForAmendmentAction extends StateChangingSIAction {
private final JsonSchemaValidator requestSchemaValidator;
private final boolean acceptAmendmentRequest;

public UC10_Carrier_ProcessSurrenderRequestForAmendmentAction(
String carrierPartyName,
String shipperPartyName,
EblAction previousAction,
JsonSchemaValidator requestSchemaValidator,
boolean acceptAmendmentRequest) {
super(carrierPartyName, shipperPartyName, previousAction, acceptAmendmentRequest ? "UC10a" : "UC10r", 204);
this.requestSchemaValidator = requestSchemaValidator;
this.acceptAmendmentRequest = acceptAmendmentRequest;
}

@Override
public String getHumanReadablePrompt() {
if (acceptAmendmentRequest) {
return ("UC10a: Accept surrender request for amendment for transport document with reference %s"
.formatted(getDspSupplier().get().transportDocumentReference()));
}
return ("UC10r: Reject surrender request for amendment for transport document with reference %s"
.formatted(getDspSupplier().get().transportDocumentReference()));
}

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

@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 @@ -185,10 +185,23 @@ public void confirmShippingInstructionsComplete(String documentReference) {
changeSIState(SI_STATUS, SI_COMPLETED);
}


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

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

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());
td.put(TRANSPORT_DOCUMENT_STATUS, TD_SURRENDERED_FOR_DELIVERY.wireName());
}

public void rejectSurrenderForDelivery(String documentReference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ 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(UC9_Carrier_AwaitSurrenderRequestForAmendmentAction.class, this::notifyOfSurrenderForAmendment),
Map.entry(UC10_Carrier_ProcessSurrenderRequestForAmendmentAction.class, this::processSurrenderRequestForAmendment),
Map.entry(UC12_Carrier_AwaitSurrenderRequestForDeliveryAction.class, this::notifyOfSurrenderForDelivery),
Map.entry(UC13_Carrier_ProcessSurrenderRequestForDeliveryAction.class, this::processSurrenderRequestForDelivery),
Map.entry(UC14_Carrier_ConfirmShippingInstructionsCompleteAction.class, this::confirmShippingInstructionsComplete)
Expand Down Expand Up @@ -194,6 +195,24 @@ private void notifyOfSurrenderForDelivery(JsonNode actionPrompt) {
addOperatorLogEntry("Sent notification for surrender for delivery of transport document with reference '%s'".formatted(documentReference));
}

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

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

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

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

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

0 comments on commit e342e05

Please sign in to comment.