Skip to content

Commit

Permalink
Merge pull request #213 from dcsaorg/SD-494-Updating-eblsurrender-sce…
Browse files Browse the repository at this point in the history
…narios

Sd-494-Updating eblsurrender scenarios
  • Loading branch information
gj0dcsa authored Oct 31, 2024
2 parents 8630420 + af5eba8 commit bfcab32
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 532 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,15 @@ public Set<String> getReportRoleNames(

public JsonSchemaValidator getMessageSchemaValidator(String apiProviderRole, boolean forRequest) {
String schemaFilePath =
"/standards/eblsurrender/schemas/eblsurrender-v%s.json"
.formatted(
standardVersion);
"/standards/eblsurrender/schemas/eblsurrender-v%s.json".formatted(standardVersion);
String schemaName =
EblSurrenderRole.isCarrier(apiProviderRole)
? (forRequest ? "SurrenderRequestDetails" : null)
: (forRequest ? "SurrenderRequestAnswer" : null);
EblSurrenderRole.isCarrier(apiProviderRole)
? (forRequest ? "SurrenderRequestDetails" : null)
: (forRequest ? "SurrenderRequestAnswer" : null);

if (schemaName == null) {
throw new IllegalArgumentException("No schema for " + apiProviderRole + " (forRequest=" + forRequest + ")");
throw new IllegalArgumentException(
"No schema for " + apiProviderRole + " (forRequest=" + forRequest + ")");
}
return JsonSchemaValidator.getInstance(schemaFilePath, schemaName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package org.dcsa.conformance.standards.eblsurrender;

import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.scenario.ConformanceAction;
import org.dcsa.conformance.core.scenario.ScenarioListBuilder;
import org.dcsa.conformance.standards.eblsurrender.action.SupplyScenarioParametersAction;
import org.dcsa.conformance.standards.eblsurrender.action.SurrenderRequestAction;
import org.dcsa.conformance.standards.eblsurrender.action.SurrenderResponseAction;
import org.dcsa.conformance.standards.eblsurrender.action.VoidAndReissueAction;
import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole;
import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderState;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderState.*;
import lombok.extern.slf4j.Slf4j;
import org.dcsa.conformance.core.scenario.ConformanceAction;
import org.dcsa.conformance.core.scenario.ScenarioListBuilder;
import org.dcsa.conformance.standards.eblsurrender.action.SupplyScenarioParametersAction;
import org.dcsa.conformance.standards.eblsurrender.action.SurrenderRequestResponseAction;
import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole;

@Slf4j
class EblSurrenderScenarioListBuilder
extends ScenarioListBuilder<EblSurrenderScenarioListBuilder> {
class EblSurrenderScenarioListBuilder extends ScenarioListBuilder<EblSurrenderScenarioListBuilder> {
private static final ThreadLocal<EblSurrenderComponentFactory> threadLocalComponentFactory =
new ThreadLocal<>();
private static final ThreadLocal<String> threadLocalCarrierPartyName = new ThreadLocal<>();
private static final ThreadLocal<String> threadLocalPlatformPartyName = new ThreadLocal<>();

private EblSurrenderScenarioListBuilder(
Function<ConformanceAction, ConformanceAction> actionBuilder) {
super(actionBuilder);
}

public static LinkedHashMap<String, EblSurrenderScenarioListBuilder>
createModuleScenarioListBuilders(
EblSurrenderComponentFactory componentFactory,
Expand All @@ -35,144 +33,86 @@ class EblSurrenderScenarioListBuilder
threadLocalCarrierPartyName.set(carrierPartyName);
threadLocalPlatformPartyName.set(platformPartyName);
return Stream.of(
Map.entry("", supplyAvailableTdrAction().thenAllPathsFrom(AVAILABLE_FOR_SURRENDER)))
Map.entry(
"Surrender Accepted",
noAction()
.thenEither(
supplyAvailableTdrAction("SURR", "Straight eBL")
.thenEither(
requestSurrenderForDeliveryAnd(true),
requestSurrenderForAmendmentAnd(true, false),
requestSurrenderForAmendmentAnd(true, true)),
supplyAvailableTdrAction("SURR", "Negotiable eBL")
.thenEither(
requestSurrenderForDeliveryAnd(true),
requestSurrenderForAmendmentAnd(true, false),
requestSurrenderForAmendmentAnd(true, true)))),
Map.entry(
"Surrender Rejected",
noAction()
.thenEither(
supplyAvailableTdrAction("SREJ", "Straight eBL")
.thenEither(
requestSurrenderForDeliveryAnd(false),
requestSurrenderForAmendmentAnd(false, false),
requestSurrenderForAmendmentAnd(false, true)),
supplyAvailableTdrAction("SREJ", "Negotiable eBL")
.thenEither(
requestSurrenderForDeliveryAnd(false),
requestSurrenderForAmendmentAnd(false, false),
requestSurrenderForAmendmentAnd(false, true)))))
.collect(
Collectors.toMap(
Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}

private EblSurrenderScenarioListBuilder thenAllPathsFrom(
EblSurrenderState surrenderState) {
return switch (surrenderState) {
case AVAILABLE_FOR_SURRENDER -> thenEither(
requestSurrenderForDelivery(204).thenAllPathsFrom(DELIVERY_SURRENDER_REQUESTED),
requestSurrenderForAmendment(204).thenAllPathsFrom(AMENDMENT_SURRENDER_REQUESTED)
);
case DELIVERY_SURRENDER_REQUESTED -> thenEither(
acceptSurrenderRequest(204).thenAllPathsFrom(SURRENDERED_FOR_DELIVERY),
rejectSurrenderRequest(204).thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER),
requestSurrenderForAmendment(409).thenAllHappyPathsFrom(DELIVERY_SURRENDER_REQUESTED),
requestSurrenderForDelivery(409).thenAllHappyPathsFrom(DELIVERY_SURRENDER_REQUESTED)
);
case SURRENDERED_FOR_DELIVERY -> thenAnyRequest(409);
case AMENDMENT_SURRENDER_REQUESTED -> thenEither(
acceptSurrenderRequest(204).thenAllPathsFrom(SURRENDERED_FOR_AMENDMENT),
rejectSurrenderRequest(204).thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER),
requestSurrenderForAmendment(409).thenAllHappyPathsFrom(AMENDMENT_SURRENDER_REQUESTED),
requestSurrenderForDelivery(409).thenAllHappyPathsFrom(AMENDMENT_SURRENDER_REQUESTED)
);
case SURRENDERED_FOR_AMENDMENT -> thenEither(
acceptSurrenderRequest(409).thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT),
rejectSurrenderRequest(409).thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT),
requestSurrenderForAmendment(409).thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT),
requestSurrenderForDelivery(409).thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT),
voidAndReissue().thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER)
);
};
}

private EblSurrenderScenarioListBuilder thenAllHappyPathsFrom(
EblSurrenderState surrenderState) {
var cases = switch (surrenderState) {
case AVAILABLE_FOR_SURRENDER -> requestSurrenderForDelivery(204).thenAllHappyPathsFrom(DELIVERY_SURRENDER_REQUESTED);
case DELIVERY_SURRENDER_REQUESTED -> acceptSurrenderRequest(204);
case SURRENDERED_FOR_DELIVERY -> noAction();
case AMENDMENT_SURRENDER_REQUESTED -> acceptSurrenderRequest(204)
.thenAllHappyPathsFrom(SURRENDERED_FOR_AMENDMENT);
case SURRENDERED_FOR_AMENDMENT -> voidAndReissue().thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER);
};
return thenEither(cases);
}

private EblSurrenderScenarioListBuilder noAction() {
private static EblSurrenderScenarioListBuilder noAction() {
return new EblSurrenderScenarioListBuilder(null);
}

private EblSurrenderScenarioListBuilder thenAnyRequest(int status) {
return thenEither(
noAction(),
requestSurrenderForAmendment(status),
requestSurrenderForDelivery(status),
rejectSurrenderRequest(status),
acceptSurrenderRequest(status)
);
}

private static EblSurrenderScenarioListBuilder supplyAvailableTdrAction() {
private static EblSurrenderScenarioListBuilder supplyAvailableTdrAction(
String response, String eblType) {
log.debug("EblSurrenderScenarioListBuilder.supplyAvailableTdrAction()");
String carrierPartyName = threadLocalCarrierPartyName.get();
return new EblSurrenderScenarioListBuilder(
noPreviousAction -> new SupplyScenarioParametersAction(carrierPartyName, null));
noPreviousAction ->
new SupplyScenarioParametersAction(carrierPartyName, null, response, eblType));
}

private EblSurrenderScenarioListBuilder(
Function<ConformanceAction, ConformanceAction> actionBuilder) {
super(actionBuilder);
}
private static EblSurrenderScenarioListBuilder requestSurrenderForAmendmentAnd(
boolean accept, boolean isSWTP) {
log.debug("EblSurrenderScenarioListBuilder.requestSurrenderForAmendment");

private static EblSurrenderScenarioListBuilder requestSurrenderForAmendment(int status) {
log.debug(
"EblSurrenderScenarioListBuilder.requestSurrenderForAmendment(%d)".formatted(status));
return _surrenderRequestBuilder(true, status);
String titleSuffix = isSWTP ? "AndSwitchToPaper" : "";
titleSuffix = accept ? titleSuffix + "Accepted" : titleSuffix + "Rejected";
return _surrenderRequestBuilder(true, accept, "SurrenderForAmendment" + titleSuffix, isSWTP);
}

private static EblSurrenderScenarioListBuilder requestSurrenderForDelivery(int status) {
log.debug(
"EblSurrenderScenarioListBuilder.requestSurrenderForDelivery(%d)".formatted(status));
return _surrenderRequestBuilder(false, status);
private static EblSurrenderScenarioListBuilder requestSurrenderForDeliveryAnd(boolean accept) {
log.debug("EblSurrenderScenarioListBuilder.requestSurrenderForDelivery");
String titleSuffix = accept ? "Accepted" : "Rejected";
return _surrenderRequestBuilder(false, accept, "SurrenderForDelivery" + titleSuffix, false);
}

private static EblSurrenderScenarioListBuilder _surrenderRequestBuilder(
boolean forAmendment, int expectedStatus) {
boolean forAmendment, boolean accept, String title, boolean isSWTP) {
EblSurrenderComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String platformPartyName = threadLocalPlatformPartyName.get();
return new EblSurrenderScenarioListBuilder(
previousAction ->
new SurrenderRequestAction(
new SurrenderRequestResponseAction(
forAmendment,
platformPartyName,
carrierPartyName,
expectedStatus,
204,
previousAction,
componentFactory.getMessageSchemaValidator(
EblSurrenderRole.CARRIER.getConfigName(), true))
);
}

private static EblSurrenderScenarioListBuilder acceptSurrenderRequest(int status) {
log.debug("EblSurrenderScenarioListBuilder.acceptSurrenderRequest(%d)".formatted(status));
return _surrenderResponseBuilder(true, status);
}

private static EblSurrenderScenarioListBuilder rejectSurrenderRequest(int status) {
log.debug("EblSurrenderScenarioListBuilder.rejectSurrenderRequest(%d)".formatted(status));
return _surrenderResponseBuilder(false, status);
}

private static EblSurrenderScenarioListBuilder _surrenderResponseBuilder(
boolean accept, int expectedStatus) {
EblSurrenderComponentFactory componentFactory = threadLocalComponentFactory.get();
String carrierPartyName = threadLocalCarrierPartyName.get();
String platformPartyName = threadLocalPlatformPartyName.get();
return new EblSurrenderScenarioListBuilder(
previousAction ->
new SurrenderResponseAction(
accept,
carrierPartyName,
platformPartyName,
expectedStatus,
previousAction,
EblSurrenderRole.CARRIER.getConfigName(), true),
componentFactory.getMessageSchemaValidator(
EblSurrenderRole.PLATFORM.getConfigName(), true)));
}

private static EblSurrenderScenarioListBuilder voidAndReissue() {
log.debug("EblSurrenderScenarioListBuilder.voidAndReissue()");
String carrierPartyName = threadLocalCarrierPartyName.get();
String platformPartyName = threadLocalPlatformPartyName.get();
return new EblSurrenderScenarioListBuilder(
previousAction ->
new VoidAndReissueAction(carrierPartyName, platformPartyName, previousAction));
EblSurrenderRole.PLATFORM.getConfigName(), true),
accept,
title,
isSWTP));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ private EblSurrenderStandard() {

@Override
public SortedMap<String, SortedSet<String>> getScenarioSuitesByStandardVersion() {
return new TreeMap<>(
Map.ofEntries(
Map.entry("3.0.0", new TreeSet<>(Set.of("Conformance")))));
return new TreeMap<>(Map.ofEntries(Map.entry("3.0.0", new TreeSet<>(Set.of("Conformance")))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.dcsa.conformance.standards.eblsurrender;

import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.DOCUMENTATION_PARTY_CODE_LIST_PROVIDER_CODES;

import java.util.UUID;
import org.dcsa.conformance.core.check.ActionCheck;
import org.dcsa.conformance.core.check.JsonAttribute;
import org.dcsa.conformance.core.check.JsonContentCheck;
Expand All @@ -8,10 +11,6 @@
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole;

import java.util.UUID;

import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.DOCUMENTATION_PARTY_CODE_LIST_PROVIDER_CODES;

public class SurrenderChecks {
private static final KeywordDataset SURRENDER_ACTIONS_DATA_SET = KeywordDataset.staticDataset(
"ISSUE",
Expand Down Expand Up @@ -46,4 +45,5 @@ public static ActionCheck surrenderRequestChecks(UUID matched, String standardVe
SURRENDER_PARTY_CODE_LIST_PROVIDER
);
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package org.dcsa.conformance.standards.eblsurrender.action;

import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.UUID;
import lombok.Getter;
import org.dcsa.conformance.core.scenario.ConformanceAction;
import org.dcsa.conformance.standards.eblsurrender.party.SuppliedScenarioParameters;

import static org.dcsa.conformance.core.toolkit.JsonToolkit.OBJECT_MAPPER;

@Getter
public class SupplyScenarioParametersAction extends ConformanceAction {
private SuppliedScenarioParameters suppliedScenarioParameters = null;
private String response;
private String eblType;

public SupplyScenarioParametersAction(String carrierPartyName, ConformanceAction previousAction) {
super(carrierPartyName, null, previousAction, "SupplyTDR");
public SupplyScenarioParametersAction(String carrierPartyName, ConformanceAction previousAction, String response, String eblType) {
super(carrierPartyName, null, previousAction, "SupplyTDR[%s]".formatted(eblType));
this.response = response;
this.eblType = eblType;
}

@Override
Expand All @@ -29,6 +33,8 @@ public ObjectNode exportJsonState() {
if (suppliedScenarioParameters != null) {
jsonState.set("suppliedScenarioParameters", suppliedScenarioParameters.toJson());
}
jsonState.put("response",response);
jsonState.put("eblType",eblType);
return jsonState;
}

Expand All @@ -39,19 +45,23 @@ public void importJsonState(JsonNode jsonState) {
if (sspNode != null) {
suppliedScenarioParameters = SuppliedScenarioParameters.fromJson(sspNode);
}
response = jsonState.get("response").asText();
eblType = jsonState.get("eblType").asText();
}

@Override
public String getHumanReadablePrompt() {
String responseAction = response.equals("SURR")?"accept":"reject";
return "Use the following format to provide the transport document reference and additional info "
+ "of a straight eBL for which your party can accept a surrender request:";
+ "of a "+ eblType +" for which your party can "+responseAction+ " a surrender request:";
}

@Override
public JsonNode getJsonForHumanReadablePrompt() {
String eblPlatform = response.equals("SURR")?"WAVE":"WAVER";
var issueToParty = OBJECT_MAPPER.createObjectNode();
issueToParty.put("partyName", "Issue To name")
.put("eblPlatform", "WAVE");
.put("eblPlatform", eblPlatform);
var carrierParty = OBJECT_MAPPER.createObjectNode();
carrierParty.put("partyName", "Carrier name")
.put("eblPlatform", "WAVE");
Expand All @@ -78,4 +88,11 @@ public void handlePartyInput(JsonNode partyInput) {
super.handlePartyInput(partyInput);
suppliedScenarioParameters = SuppliedScenarioParameters.fromJson(partyInput.get("input"));
}

@Override
public ObjectNode asJsonNode() {
return super.asJsonNode()
.put("eblType", eblType)
.put("response", response);
}
}
Loading

0 comments on commit bfcab32

Please sign in to comment.