-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Niels Thykier <[email protected]>
- Loading branch information
Showing
17 changed files
with
538 additions
and
195 deletions.
There are no files selected for viewing
384 changes: 250 additions & 134 deletions
384
core/src/main/java/org/dcsa/conformance/core/check/JsonAttribute.java
Large diffs are not rendered by default.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
core/src/main/java/org/dcsa/conformance/core/check/JsonContentCheckRebaser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.dcsa.conformance.core.check; | ||
|
||
import java.util.List; | ||
|
||
import static org.dcsa.conformance.core.check.JsonAttribute.rebaserFor; | ||
|
||
public interface JsonContentCheckRebaser { | ||
|
||
|
||
default JsonRebaseableContentCheck offset(JsonRebaseableContentCheck jsonRebaseableContentCheck) { | ||
JsonContentMatchedValidation m = offset(jsonRebaseableContentCheck::validate); | ||
return new JsonAttribute.JsonRebaseableCheckImpl( | ||
jsonRebaseableContentCheck.description(), | ||
m::validate | ||
); | ||
} | ||
|
||
JsonContentMatchedValidation offset(JsonContentMatchedValidation jsonContentMatchedValidation); | ||
|
||
static JsonContentCheckRebaser of(String path) { | ||
return rebaserFor(List.of(path)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
core/src/main/java/org/dcsa/conformance/core/check/JsonRebaseableAttributeBasedCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.dcsa.conformance.core.check; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
import lombok.NonNull; | ||
import org.dcsa.conformance.core.traffic.ConformanceExchange; | ||
import org.dcsa.conformance.core.traffic.HttpMessageType; | ||
|
||
class JsonRebaseableAttributeBasedCheck extends ActionCheck { | ||
|
||
private final JsonContentCheckRebaser rebaser; | ||
private final List<JsonRebaseableContentCheck> validators; | ||
|
||
JsonRebaseableAttributeBasedCheck( | ||
String titlePrefix, | ||
String title, | ||
Predicate<String> isRelevantForRoleName, | ||
UUID matchedExchangeUuid, | ||
HttpMessageType httpMessageType, | ||
@NonNull JsonContentCheckRebaser rebaser, | ||
@NonNull | ||
List<@NonNull JsonRebaseableContentCheck> validators) { | ||
super(titlePrefix, title, isRelevantForRoleName, matchedExchangeUuid, httpMessageType); | ||
if (validators.isEmpty()) { | ||
throw new IllegalArgumentException("Must have at least one subcheck (validators must be non-empty)"); | ||
} | ||
this.rebaser = rebaser; | ||
this.validators = validators; | ||
} | ||
|
||
@Override | ||
protected final Set<String> checkConformance(Function<UUID, ConformanceExchange> getExchangeByUuid) { | ||
// All checks are delegated to sub-checks; nothing to do in here. | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
protected Stream<? extends ConformanceCheck> createSubChecks() { | ||
return this.validators.stream() | ||
.map(validator -> new SingleValidatorCheck(this::isRelevantForRole, matchedExchangeUuid, httpMessageType, rebaser.offset(validator))); | ||
} | ||
|
||
|
||
private static class SingleValidatorCheck extends ActionCheck { | ||
|
||
private final JsonRebaseableContentCheck validator; | ||
|
||
public SingleValidatorCheck(Predicate<String> isRelevantForRoleName, UUID matchedExchangeUuid, HttpMessageType httpMessageType, @NonNull JsonRebaseableContentCheck validator) { | ||
super(validator.description(), isRelevantForRoleName, matchedExchangeUuid, httpMessageType); | ||
this.validator = validator; | ||
} | ||
|
||
@Override | ||
protected Set<String> checkConformance(Function<UUID, ConformanceExchange> getExchangeByUuid) { | ||
ConformanceExchange exchange = getExchangeByUuid.apply(matchedExchangeUuid); | ||
if (exchange == null) return Collections.emptySet(); | ||
JsonNode jsonBody = exchange.getMessage(httpMessageType).body().getJsonBody(); | ||
return this.validator.validate(jsonBody); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/main/java/org/dcsa/conformance/core/check/JsonRebaseableContentCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.dcsa.conformance.core.check; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import java.util.Set; | ||
|
||
public interface JsonRebaseableContentCheck extends JsonContentCheck { | ||
/** | ||
* @param nodeToValidate The node to validate | ||
* @param contextPath The path to this node, which should be included in any validation errors | ||
* to describe where in the Json tree the error applies. | ||
* @return A set of validation errors (returns the empty set if everything is ok) | ||
*/ | ||
Set<String> validate(JsonNode nodeToValidate, String contextPath); | ||
|
||
@Override | ||
default Set<String> validate(JsonNode body) { | ||
return validate(body, ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
"document": { | ||
"transportDocumentReference": "TRANSPORT_DOCUMENT_REFERENCE_PLACEHOLDER", | ||
"shippingInstructionsReference": "SHIPPING_INSTRUCTION_REFERENCE_PLACEHOLDER", | ||
"transportDocumentTypeCode": "SWB", | ||
"transportDocumentTypeCode": "BOL", | ||
"freightPaymentTermCode": "PRE", | ||
"isElectronic": true, | ||
"isToOrder": true, | ||
"isToOrder": false, | ||
"invoicePayableAt": { | ||
"locationType": "UNCO", | ||
"UNLocationCode": "DKAAR" | ||
|
@@ -29,6 +29,26 @@ | |
}, | ||
"partyFunction": "OS", | ||
"isToBeNotified": false | ||
}, | ||
{ | ||
"party": { | ||
"partyName": "CONSIGNEE_NAME_PLACEHOLDER", | ||
"partyCodes": [ | ||
{ | ||
"partyCode": "CONSIGNEE_PARTY_CODE_PLACEHOLDER", | ||
"codeListProvider": "EPUI", | ||
"codeListName": "CONSIGNEE_CODE_LIST_NAME_PLACEHOLDER" | ||
} | ||
], | ||
"partyContactDetails": [ | ||
{ | ||
"name": "DCSA test person", | ||
"email": "[email protected]" | ||
} | ||
] | ||
}, | ||
"partyFunction": "CN", | ||
"isToBeNotified": false | ||
} | ||
], | ||
"consignmentItems": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.