-
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.
Merge pull request #3 from easybill/v0.2.0
V0.2.0
- Loading branch information
Showing
18 changed files
with
357 additions
and
220 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
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
55 changes: 12 additions & 43 deletions
55
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,53 +1,22 @@ | ||
package io.github.easybill.Dtos; | ||
|
||
import com.helger.schematron.svrl.jaxb.FailedAssert; | ||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public final class ValidationResult { | ||
|
||
@NonNull | ||
private final SchematronOutputType report; | ||
|
||
@NonNull | ||
private final String xmlReport; | ||
|
||
@NonNull | ||
private final List<FailedAssert> errors; | ||
|
||
@NonNull | ||
private final List<FailedAssert> warnings; | ||
|
||
public ValidationResult( | ||
@NonNull SchematronOutputType report, | ||
@NonNull String xmlReport, | ||
@NonNull List<FailedAssert> errors, | ||
@NonNull List<FailedAssert> warnings | ||
) { | ||
this.report = report.clone(); | ||
this.xmlReport = xmlReport; | ||
this.errors = errors.stream().toList(); | ||
this.warnings = warnings.stream().toList(); | ||
public record ValidationResult( | ||
@NonNull ValidationResultMetaData meta, | ||
@NonNull List<@NonNull ValidationResultField> errors, | ||
@NonNull List<@NonNull ValidationResultField> warnings | ||
) { | ||
public ValidationResult { | ||
errors = Collections.unmodifiableList(errors); | ||
warnings = Collections.unmodifiableList(warnings); | ||
} | ||
|
||
@JsonProperty("is_valid") | ||
public boolean isValid() { | ||
return (long) errors.size() == 0; | ||
} | ||
|
||
public @NonNull SchematronOutputType getReport() { | ||
return report.clone(); | ||
} | ||
|
||
public @NonNull String getXmlReport() { | ||
return xmlReport; | ||
} | ||
|
||
public @NonNull List<FailedAssert> getErrors() { | ||
return errors.stream().toList(); | ||
} | ||
|
||
public @NonNull List<FailedAssert> getWarnings() { | ||
return warnings.stream().toList(); | ||
return errors.isEmpty(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/io/github/easybill/Dtos/ValidationResultField.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,52 @@ | ||
package io.github.easybill.Dtos; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.helger.schematron.svrl.jaxb.FailedAssert; | ||
import com.helger.schematron.svrl.jaxb.Text; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
enum Severity { | ||
FATAL, | ||
WARNING, | ||
} | ||
|
||
public record ValidationResultField( | ||
@JsonProperty("rule_id") @NonNull String id, | ||
@JsonProperty("rule_location") @NonNull String location, | ||
@JsonProperty("rule_severity") @NonNull Severity severity, | ||
@JsonProperty("rule_messages") @NonNull List<@NonNull String> messages | ||
) { | ||
public ValidationResultField { | ||
messages = Collections.unmodifiableList(messages); | ||
} | ||
|
||
public static ValidationResultField fromFailedAssert( | ||
@NonNull FailedAssert failedAssert | ||
) { | ||
var messages = failedAssert | ||
.getDiagnosticReferenceOrPropertyReferenceOrText() | ||
.stream() | ||
.filter(element -> element instanceof Text) | ||
.map(element -> | ||
((Text) element).getContent() | ||
.stream() | ||
.filter(innerElement -> innerElement instanceof String) | ||
.map(innerElement -> (String) innerElement) | ||
.toList() | ||
) | ||
.flatMap(List::stream) | ||
.toList(); | ||
|
||
return new ValidationResultField( | ||
Objects.requireNonNullElse(failedAssert.getId(), ""), | ||
Objects.requireNonNullElse(failedAssert.getLocation(), ""), | ||
Objects.equals(failedAssert.getFlag(), "fatal") | ||
? Severity.FATAL | ||
: Severity.WARNING, | ||
messages | ||
); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/io/github/easybill/Dtos/ValidationResultMetaData.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,14 @@ | ||
package io.github.easybill.Dtos; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.github.easybill.Enums.XMLSyntaxType; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
public record ValidationResultMetaData( | ||
@NonNull | ||
@JsonProperty("validation_profile") | ||
XMLSyntaxType validationProfile, | ||
@NonNull | ||
@JsonProperty("validation_profile_version") | ||
String validation_profile_version | ||
) {} |
21 changes: 0 additions & 21 deletions
21
src/main/java/io/github/easybill/EN16931ValidatorApplication.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
src/main/java/io/github/easybill/Interceptors/GlobalExceptionInterceptor.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,26 @@ | ||
package io.github.easybill.Interceptors; | ||
|
||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
import org.jboss.logging.Logger; | ||
|
||
@Provider | ||
public class GlobalExceptionInterceptor implements ExceptionMapper<Throwable> { | ||
|
||
private static final Logger LOGGER = Logger.getLogger( | ||
GlobalExceptionInterceptor.class | ||
); | ||
|
||
@Override | ||
public Response toResponse(Throwable exception) { | ||
if (exception instanceof WebApplicationException) { | ||
return ((WebApplicationException) exception).getResponse(); | ||
} | ||
|
||
LOGGER.error("Encountered an exception:", exception); | ||
|
||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); | ||
} | ||
} |
Oops, something went wrong.