-
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.
* Improve the way how the validator works
- Loading branch information
Showing
17 changed files
with
484 additions
and
164 deletions.
There are no files selected for viewing
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
61 changes: 19 additions & 42 deletions
61
src/main/java/io/github/easybill/Dtos/ValidationResult.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 |
---|---|---|
@@ -1,71 +1,48 @@ | ||
package io.github.easybill.Dtos; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.helger.schematron.svrl.jaxb.FailedAssert; | ||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
import io.github.easybill.Dtos.ValidatorResults.ValidatorResult; | ||
import io.github.easybill.Enums.XmlProfileType; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public record ValidationResult( | ||
@NonNull ValidationResultMetaData meta, | ||
@NonNull List<@NonNull ValidationResultField> errors, | ||
@NonNull List<@NonNull ValidationResultField> warnings | ||
@JsonProperty("validation_results") | ||
@NonNull | ||
List<@NonNull ValidatorResult> validationResults | ||
) { | ||
public ValidationResult { | ||
errors = Collections.unmodifiableList(errors); | ||
warnings = Collections.unmodifiableList(warnings); | ||
public ValidationResult( | ||
@NonNull ValidationResultMetaData meta, | ||
@JsonProperty( | ||
"validation_results" | ||
) @NonNull List<@NonNull ValidatorResult> validationResults | ||
) { | ||
this.meta = meta; | ||
this.validationResults = | ||
Collections.unmodifiableList(validationResults); | ||
} | ||
|
||
@JsonProperty("is_valid") | ||
public boolean isValid() { | ||
return errors.isEmpty(); | ||
return validationResults | ||
.stream() | ||
.allMatch(element -> element.getErrors().isEmpty()); | ||
} | ||
|
||
public static ValidationResult of( | ||
XmlProfileType xmlProfileType, | ||
ValidationRequest validationRequest, | ||
SchematronOutputType schematronOutputType | ||
ValidatorResult... validatorResults | ||
) { | ||
return new ValidationResult( | ||
new ValidationResultMetaData( | ||
validationRequest.xmlSyntaxType(), | ||
xmlProfileType | ||
), | ||
getErrorsFromSchematronOutput(schematronOutputType), | ||
getWarningsFromSchematronOutput(schematronOutputType) | ||
Arrays.stream(validatorResults).toList() | ||
); | ||
} | ||
|
||
private static List<@NonNull ValidationResultField> getErrorsFromSchematronOutput( | ||
@NonNull SchematronOutputType outputType | ||
) { | ||
return outputType | ||
.getActivePatternAndFiredRuleAndFailedAssert() | ||
.stream() | ||
.filter(element -> element instanceof FailedAssert) | ||
.filter(element -> | ||
Objects.equals(((FailedAssert) element).getFlag(), "fatal") | ||
) | ||
.map(element -> (FailedAssert) element) | ||
.map(ValidationResultField::fromFailedAssert) | ||
.toList(); | ||
} | ||
|
||
private static List<@NonNull ValidationResultField> getWarningsFromSchematronOutput( | ||
@NonNull SchematronOutputType outputType | ||
) { | ||
return outputType | ||
.getActivePatternAndFiredRuleAndFailedAssert() | ||
.stream() | ||
.filter(element -> element instanceof FailedAssert) | ||
.filter(element -> | ||
Objects.equals(((FailedAssert) element).getFlag(), "warning") | ||
) | ||
.map(element -> (FailedAssert) element) | ||
.map(ValidationResultField::fromFailedAssert) | ||
.toList(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/github/easybill/Dtos/ValidatorResults/EN16931ValidatorResult.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,29 @@ | ||
package io.github.easybill.Dtos.ValidatorResults; | ||
|
||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
import io.github.easybill.Dtos.ValidationResultField; | ||
import java.util.List; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public final class EN16931ValidatorResult extends ValidatorResult { | ||
|
||
public EN16931ValidatorResult( | ||
@NonNull String name, | ||
@NonNull String version, | ||
@NonNull List<@NonNull ValidationResultField> errors, | ||
@NonNull List<@NonNull ValidationResultField> warnings | ||
) { | ||
super(name, version, errors, warnings); | ||
} | ||
|
||
public static EN16931ValidatorResult of( | ||
@NonNull SchematronOutputType report | ||
) { | ||
return new EN16931ValidatorResult( | ||
"EN16931", | ||
"1.3.13", | ||
getErrorsFromSchematronOutput(report), | ||
getWarningsFromSchematronOutput(report) | ||
); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/github/easybill/Dtos/ValidatorResults/FacturXValidatorResult.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,29 @@ | ||
package io.github.easybill.Dtos.ValidatorResults; | ||
|
||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
import io.github.easybill.Dtos.ValidationResultField; | ||
import java.util.List; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public final class FacturXValidatorResult extends ValidatorResult { | ||
|
||
public FacturXValidatorResult( | ||
@NonNull String name, | ||
@NonNull String version, | ||
@NonNull List<@NonNull ValidationResultField> errors, | ||
@NonNull List<@NonNull ValidationResultField> warnings | ||
) { | ||
super(name, version, errors, warnings); | ||
} | ||
|
||
public static FacturXValidatorResult of( | ||
@NonNull SchematronOutputType report | ||
) { | ||
return new FacturXValidatorResult( | ||
"factur-x", | ||
"1.07.2", | ||
getErrorsFromSchematronOutput(report), | ||
getWarningsFromSchematronOutput(report) | ||
); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/github/easybill/Dtos/ValidatorResults/PeppolValidatorResult.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,29 @@ | ||
package io.github.easybill.Dtos.ValidatorResults; | ||
|
||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
import io.github.easybill.Dtos.ValidationResultField; | ||
import java.util.List; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public final class PeppolValidatorResult extends ValidatorResult { | ||
|
||
public PeppolValidatorResult( | ||
@NonNull String name, | ||
@NonNull String version, | ||
@NonNull List<@NonNull ValidationResultField> errors, | ||
@NonNull List<@NonNull ValidationResultField> warnings | ||
) { | ||
super(name, version, errors, warnings); | ||
} | ||
|
||
public static PeppolValidatorResult of( | ||
@NonNull SchematronOutputType report | ||
) { | ||
return new PeppolValidatorResult( | ||
"Peppol BIS", | ||
"3.0", | ||
getErrorsFromSchematronOutput(report), | ||
getWarningsFromSchematronOutput(report) | ||
); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/main/java/io/github/easybill/Dtos/ValidatorResults/ValidatorResult.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,83 @@ | ||
package io.github.easybill.Dtos.ValidatorResults; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.helger.schematron.svrl.jaxb.FailedAssert; | ||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
import io.github.easybill.Dtos.ValidationResultField; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public abstract class ValidatorResult { | ||
|
||
@NonNull | ||
private final String name; | ||
|
||
@NonNull | ||
private final String version; | ||
|
||
@NonNull | ||
private final List<@NonNull ValidationResultField> warnings; | ||
|
||
@NonNull | ||
private final List<@NonNull ValidationResultField> errors; | ||
|
||
public ValidatorResult( | ||
@JsonProperty("name") @NonNull String name, | ||
@JsonProperty("artifact_version") @NonNull String version, | ||
@NonNull List<@NonNull ValidationResultField> errors, | ||
@NonNull List<@NonNull ValidationResultField> warnings | ||
) { | ||
this.name = name; | ||
this.version = version; | ||
this.errors = Collections.unmodifiableList(errors); | ||
this.warnings = Collections.unmodifiableList(warnings); | ||
} | ||
|
||
static List<@NonNull ValidationResultField> getErrorsFromSchematronOutput( | ||
@NonNull SchematronOutputType outputType | ||
) { | ||
return outputType | ||
.getActivePatternAndFiredRuleAndFailedAssert() | ||
.stream() | ||
.filter(element -> element instanceof FailedAssert) | ||
.filter(element -> | ||
Objects.equals(((FailedAssert) element).getFlag(), "fatal") | ||
) | ||
.map(element -> (FailedAssert) element) | ||
.map(ValidationResultField::fromFailedAssert) | ||
.toList(); | ||
} | ||
|
||
static List<@NonNull ValidationResultField> getWarningsFromSchematronOutput( | ||
@NonNull SchematronOutputType outputType | ||
) { | ||
return outputType | ||
.getActivePatternAndFiredRuleAndFailedAssert() | ||
.stream() | ||
.filter(element -> element instanceof FailedAssert) | ||
.filter(element -> | ||
Objects.equals(((FailedAssert) element).getFlag(), "warning") | ||
) | ||
.map(element -> (FailedAssert) element) | ||
.map(ValidationResultField::fromFailedAssert) | ||
.toList(); | ||
} | ||
|
||
public @NonNull List<@NonNull ValidationResultField> getErrors() { | ||
return errors; | ||
} | ||
|
||
public @NonNull List<@NonNull ValidationResultField> getWarnings() { | ||
return warnings; | ||
} | ||
|
||
public @NonNull String getName() { | ||
return name; | ||
} | ||
|
||
public @NonNull String getVersion() { | ||
return version; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/github/easybill/Dtos/ValidatorResults/XRechnungValidatorResult.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,29 @@ | ||
package io.github.easybill.Dtos.ValidatorResults; | ||
|
||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
import io.github.easybill.Dtos.ValidationResultField; | ||
import java.util.List; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public final class XRechnungValidatorResult extends ValidatorResult { | ||
|
||
public XRechnungValidatorResult( | ||
@NonNull String name, | ||
@NonNull String version, | ||
@NonNull List<@NonNull ValidationResultField> errors, | ||
@NonNull List<@NonNull ValidationResultField> warnings | ||
) { | ||
super(name, version, errors, warnings); | ||
} | ||
|
||
public static XRechnungValidatorResult of( | ||
@NonNull SchematronOutputType report | ||
) { | ||
return new XRechnungValidatorResult( | ||
"XRechnung", | ||
"3.2", | ||
getErrorsFromSchematronOutput(report), | ||
getWarningsFromSchematronOutput(report) | ||
); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/io/github/easybill/Exceptions/ValidationChainException.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,8 @@ | ||
package io.github.easybill.Exceptions; | ||
|
||
public class ValidationChainException extends ValidatorException { | ||
|
||
public ValidationChainException() { | ||
super(); | ||
} | ||
} |
Oops, something went wrong.