Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-1217 + DT-1266 #99

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -45,8 +45,8 @@ private EblSurrenderScenarioListBuilder thenAllPathsFrom(
EblSurrenderState surrenderState) {
return switch (surrenderState) {
case AVAILABLE_FOR_SURRENDER -> thenEither(
requestSurrenderForDelivery(202).thenAllPathsFrom(DELIVERY_SURRENDER_REQUESTED),
requestSurrenderForAmendment(202).thenAllPathsFrom(AMENDMENT_SURRENDER_REQUESTED),
requestSurrenderForDelivery(204).thenAllPathsFrom(DELIVERY_SURRENDER_REQUESTED),
requestSurrenderForAmendment(204).thenAllPathsFrom(AMENDMENT_SURRENDER_REQUESTED),
acceptSurrenderRequest(409).thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER),
rejectSurrenderRequest(409).thenAllHappyPathsFrom(AVAILABLE_FOR_SURRENDER)
);
Expand Down Expand Up @@ -76,7 +76,7 @@ private EblSurrenderScenarioListBuilder thenAllPathsFrom(
private EblSurrenderScenarioListBuilder thenAllHappyPathsFrom(
EblSurrenderState surrenderState) {
var cases = switch (surrenderState) {
case AVAILABLE_FOR_SURRENDER -> requestSurrenderForDelivery(202).thenAllHappyPathsFrom(DELIVERY_SURRENDER_REQUESTED);
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)
Expand Down 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 Expand Up @@ -171,7 +171,7 @@ public ConformanceResponse handleRequest(ConformanceRequest request) {
.formatted(src, srr, tdr, eblStatesById.get(tdr)));

return request.createResponse(
202,
204,
Map.of("Api-Version", List.of(apiVersion)),
new ConformanceMessageBody(
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
Loading