Skip to content

Commit

Permalink
DT-1266: Add Issuance and Surrender actions to surrender API
Browse files Browse the repository at this point in the history
  • Loading branch information
nt-gt committed Jun 18, 2024
1 parent 8ea94f8 commit e9966fa
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ public JsonSchemaValidator getMessageSchemaValidator(String apiProviderRole, boo
} else {
schemaName =
EblSurrenderRole.isCarrier(apiProviderRole)
? (forRequest ? "SurrenderRequestDetails" : "SurrenderRequestAcknowledgement")
? (forRequest ? "SurrenderRequestDetails" : null)
: (forRequest ? "SurrenderRequestAnswer" : null);
}
if (schemaName == null) {
throw new IllegalArgumentException("No schema for " + apiProviderRole + " (forRequest=" + forRequest + ")");
}
return JsonSchemaValidator.getInstance(schemaFilePath, schemaName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ private static EblSurrenderScenarioListBuilder _surrenderRequestBuilder(
expectedStatus,
previousAction,
componentFactory.getMessageSchemaValidator(
EblSurrenderRole.CARRIER.getConfigName(), true),
componentFactory.getMessageSchemaValidator(
EblSurrenderRole.CARRIER.getConfigName(), false)));
EblSurrenderRole.CARRIER.getConfigName(), true))
);
}

private static EblSurrenderScenarioListBuilder acceptSurrenderRequest(int status) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.dcsa.conformance.standards.eblsurrender;

import org.dcsa.conformance.core.check.ActionCheck;
import org.dcsa.conformance.core.check.JsonAttribute;
import org.dcsa.conformance.core.check.JsonContentCheck;
import org.dcsa.conformance.core.check.KeywordDataset;
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole;

import java.util.UUID;

public class SurrenderChecks {
private static final KeywordDataset SURRENDER_ACTIONS_DATA_SET = KeywordDataset.staticDataset(
"ISSUE",
"ENDORSE",
"SIGN",
"SURRENDER FOR DELIVERY",
"SURRENDER FOR AMENDMENT"
);

private static final JsonContentCheck SURRENDER_ACTION_VALIDATION = JsonAttribute.allIndividualMatchesMustBeValid(
"Validate Surrender Actions",
(mav) -> mav.submitAllMatching("endorsementChain.*.actionCode"),
JsonAttribute.matchedMustBeDatasetKeywordIfPresent(SURRENDER_ACTIONS_DATA_SET)
);

public static ActionCheck surrenderRequestChecks(UUID matched, String standardVersion) {
return JsonAttribute.contentChecks(
EblSurrenderRole::isPlatform,
matched,
HttpMessageType.REQUEST,
standardVersion,
SURRENDER_ACTION_VALIDATION
);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public String getHumanReadablePrompt() {

@Override
public JsonNode getJsonForHumanReadablePrompt() {
return new SuppliedScenarioParameters(
return new SuppliedScenarioParameters(
UUID.randomUUID().toString().replaceAll("-", "").substring(0, 20),
"XMPL",
"Example carrier party code",
"Example party code",
"Example code list")
.toJson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import org.dcsa.conformance.core.traffic.HttpMessageType;
import org.dcsa.conformance.standards.eblsurrender.party.EblSurrenderRole;

import static org.dcsa.conformance.standards.eblsurrender.SurrenderChecks.surrenderRequestChecks;

@Getter
@Slf4j
public class SurrenderRequestAction extends EblSurrenderAction {
private final JsonSchemaValidator requestSchemaValidator;
private final JsonSchemaValidator responseSchemaValidator;
private final boolean forAmendment;

private final AtomicReference<String> surrenderRequestReference = new AtomicReference<>();
Expand All @@ -32,8 +33,7 @@ public SurrenderRequestAction(
String carrierPartyName,
int expectedStatus,
ConformanceAction previousAction,
JsonSchemaValidator requestSchemaValidator,
JsonSchemaValidator responseSchemaValidator) {
JsonSchemaValidator requestSchemaValidator) {
super(
platformPartyName,
carrierPartyName,
Expand All @@ -42,7 +42,6 @@ public SurrenderRequestAction(
"%s %d".formatted(forAmendment ? "AREQ" : "SREQ", expectedStatus));
this.forAmendment = forAmendment;
this.requestSchemaValidator = requestSchemaValidator;
this.responseSchemaValidator = responseSchemaValidator;
}

@Override
Expand Down Expand Up @@ -115,17 +114,13 @@ protected Stream<? extends ConformanceCheck> createSubChecks() {
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
requestSchemaValidator),
new JsonSchemaCheck(
EblSurrenderRole::isCarrier,
getMatchedExchangeUuid(),
HttpMessageType.RESPONSE,
responseSchemaValidator),
new JsonAttributeCheck(
EblSurrenderRole::isPlatform,
getMatchedExchangeUuid(),
HttpMessageType.REQUEST,
JsonPointer.compile("/surrenderRequestCode"),
forAmendment ? "AREQ" : "SREQ"),
surrenderRequestChecks(getMatchedExchangeUuid(), expectedApiVersion),
new JsonAttributeCheck(
EblSurrenderRole::isPlatform,
getMatchedExchangeUuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void supplyScenarioParameters(JsonNode actionPrompt) {
eblStatesById.put(tdr, EblSurrenderState.AVAILABLE_FOR_SURRENDER);

SuppliedScenarioParameters suppliedScenarioParameters =
new SuppliedScenarioParameters(tdr, "XMPL", "Example party code", "Example code list");
new SuppliedScenarioParameters(tdr, "XMPL", "Example carrier party code", "Example party code", "Example code list");

asyncOrchestratorPostPartyInput(
objectMapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ private void requestSurrender(JsonNode actionPrompt) {
Map.entry("TRANSPORT_DOCUMENT_REFERENCE_PLACEHOLDER", tdr),
Map.entry("SURRENDER_REQUEST_CODE_PLACEHOLDER", src),
Map.entry("EBL_PLATFORM_PLACEHOLDER", ssp.eblPlatform()),
Map.entry("PARTY_CODE_PLACEHOLDER", ssp.partyCode()),
Map.entry("CARRIER_PARTY_CODE_PLACEHOLDER", ssp.carrierPartyCode()),
Map.entry("PARTY_CODE_PLACEHOLDER", ssp.surrenderPartyCode()),
Map.entry("CODE_LIST_NAME_PLACEHOLDER", ssp.codeListName()),
Map.entry("ACTION_DATE_TIME_PLACEHOLDER", Instant.now().toString())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
import com.fasterxml.jackson.databind.node.ObjectNode;

public record SuppliedScenarioParameters(
String transportDocumentReference, String eblPlatform, String partyCode, String codeListName) {
String transportDocumentReference, String eblPlatform, String carrierPartyCode, String surrenderPartyCode, String codeListName) {
public ObjectNode toJson() {
return new ObjectMapper()
.createObjectNode()
.put("transportDocumentReference", transportDocumentReference)
.put("eblPlatform", eblPlatform)
.put("partyCode", partyCode)
.put("carrierPartyCode", surrenderPartyCode)
.put("surrenderPartyCode", surrenderPartyCode)
.put("codeListName", codeListName);
}

public static SuppliedScenarioParameters fromJson(JsonNode jsonNode) {
return new SuppliedScenarioParameters(
jsonNode.required("transportDocumentReference").asText(),
jsonNode.required("eblPlatform").asText(),
jsonNode.required("partyCode").asText(),
jsonNode.required("carrierPartyCode").asText(),
jsonNode.required("surrenderPartyCode").asText(),
jsonNode.required("codeListName").asText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,59 @@
"codeListName": "CODE_LIST_NAME_PLACEHOLDER"
}
]
}
},
"endorsementChain": [
{
"actionCode": "ISSUE",
"actionDateTime": "2024-06-11T13:54:00Z",
"actor": {
"eblPlatform": "EBL_PLATFORM_PLACEHOLDER",
"partyName": "legal name",
"partyCodes": [
{
"partyCode": "CARRIER_PARTY_CODE_PLACEHOLDER",
"codeListProvider": "EPUI",
"codeListName": "CODE_LIST_NAME_PLACEHOLDER"
}
]
},
"recipient": {
"eblPlatform": "EBL_PLATFORM_PLACEHOLDER",
"partyName": "legal name",
"partyCodes": [
{
"partyCode": "PARTY_CODE_PLACEHOLDER",
"codeListProvider": "EPUI",
"codeListName": "CODE_LIST_NAME_PLACEHOLDER"
}
]
}
},
{
"actionCode": "SURRENDER FOR DELIVERY",
"actionDateTime": "2024-06-12T14:54:00Z",
"recipient": {
"eblPlatform": "EBL_PLATFORM_PLACEHOLDER",
"partyName": "legal name",
"partyCodes": [
{
"partyCode": "CARRIER_PARTY_CODE_PLACEHOLDER",
"codeListProvider": "EPUI",
"codeListName": "CODE_LIST_NAME_PLACEHOLDER"
}
]
},
"actor": {
"eblPlatform": "EBL_PLATFORM_PLACEHOLDER",
"partyName": "legal name",
"partyCodes": [
{
"partyCode": "PARTY_CODE_PLACEHOLDER",
"codeListProvider": "EPUI",
"codeListName": "CODE_LIST_NAME_PLACEHOLDER"
}
]
}
}
]
}
Loading

0 comments on commit e9966fa

Please sign in to comment.