diff --git a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/checks/EBLChecks.java b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/checks/EBLChecks.java index 5c846917..451529ce 100644 --- a/ebl/src/main/java/org/dcsa/conformance/standards/ebl/checks/EBLChecks.java +++ b/ebl/src/main/java/org/dcsa/conformance/standards/ebl/checks/EBLChecks.java @@ -5,6 +5,8 @@ import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.EXEMPT_PACKAGE_CODES; import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.MODE_OF_TRANSPORT; import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.NATIONAL_COMMODITY_CODES; +import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.PARTY_FUNCTION_CODE; +import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.PARTY_FUNCTION_CODE_HBL; import static org.dcsa.conformance.standards.ebl.checks.EblDatasets.REQUESTED_CARRIER_CLAUSES; @@ -666,6 +668,19 @@ private static Consumer allDg(Consumer mav.submitAllMatching("documentParties.other.*.partyFunction"), + JsonAttribute.matchedMustBeDatasetKeywordIfPresent(PARTY_FUNCTION_CODE)); + + static final JsonRebaseableContentCheck VALID_PARTY_FUNCTION_HBL = + JsonAttribute.allIndividualMatchesMustBeValid( + "The partyFunction in OtherDocumentParty of houseBillOfLadings is valid", + mav -> + mav.submitAllMatching("houseBillOfLadings.*.documentParties.other.*.partyFunction"), + JsonAttribute.matchedMustBeDatasetKeywordIfPresent(PARTY_FUNCTION_CODE_HBL)); + private static final List STATIC_SI_CHECKS = Arrays.asList( JsonAttribute.mustBeDatasetKeywordIfPresent( SI_REQUEST_SEND_TO_PLATFORM, @@ -684,6 +699,8 @@ private static Consumer allDg(Consumer allDg(Consumer invalidErrors = VALID_CONSIGMENT_ITEMS_REFERENCE_TYPES.validate(rootNode); assertEquals(1, invalidErrors.size()); } + + @Test + void testValidPartyFunction() { + ObjectNode documentParties = rootNode.putObject("documentParties"); + ArrayNode otherParties = documentParties.putArray("other"); + ObjectNode otherParty = otherParties.addObject(); + otherParty.put("partyFunction", "SCO"); + + Set errors = VALID_PARTY_FUNCTION.validate(rootNode); + assertEquals(0, errors.size()); + + otherParty.put("partyFunction", "SSS"); + errors = VALID_PARTY_FUNCTION.validate(rootNode); + assertEquals(1, errors.size()); + } + + @Test + void testValidPartyFunctionHBL() { + ArrayNode houseBillOfLadings = rootNode.putArray("houseBillOfLadings"); + ObjectNode hbl = houseBillOfLadings.addObject(); + ObjectNode documentParties = hbl.putObject("documentParties"); + ArrayNode otherParties = documentParties.putArray("other"); + ObjectNode otherParty = otherParties.addObject(); + otherParty.put("partyFunction", "CS"); + + Set errors = VALID_PARTY_FUNCTION_HBL.validate(rootNode); + assertEquals(0, errors.size()); + + otherParty.put("partyFunction", "SSS"); + errors = VALID_PARTY_FUNCTION_HBL.validate(rootNode); + assertEquals(1, errors.size()); + } }