diff --git a/src/main/java/de/kosit/validationtool/cmd/CheckAssertionAction.java b/src/main/java/de/kosit/validationtool/cmd/CheckAssertionAction.java index aef0bcd..0293290 100644 --- a/src/main/java/de/kosit/validationtool/cmd/CheckAssertionAction.java +++ b/src/main/java/de/kosit/validationtool/cmd/CheckAssertionAction.java @@ -16,14 +16,13 @@ package de.kosit.validationtool.cmd; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import de.kosit.validationtool.impl.tasks.CreateReportAction; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLDetectionBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; +import de.kosit.validationtool.model.xvrl.XVRLDetection; import de.kosit.validationtool.model.xvrl.XVRLReport; import org.apache.commons.lang3.StringUtils; @@ -104,9 +103,15 @@ public ProcessStepResult check(final Process results) { return processStepResult; } - private static XVRLReport generateXVRLReport(final Result parserResult) { - // TODO create report here - return XVRLBuilder.builder().name("Assertions Validator").addErrors(parserResult.getErrors()).build(); + private static XVRLReport generateXVRLReport(final Result assertionResult) { + return XVRLReportBuilder.builder() + .name("Assertions Validator") + .addErrors(assertionResult.getErrors()) + .addDetections(Collections.singletonList(XVRLDetectionBuilder.builder() + .addMessageString(assertionResult.getObject().toString()) + .setSeverity(XVRLDetection.Severity.INFO) + .build())) + .build(); } private List findAssertions(final String name) { diff --git a/src/main/java/de/kosit/validationtool/cmd/ExtractHtmlContentAction.java b/src/main/java/de/kosit/validationtool/cmd/ExtractHtmlContentAction.java index c928f14..15f8c6b 100644 --- a/src/main/java/de/kosit/validationtool/cmd/ExtractHtmlContentAction.java +++ b/src/main/java/de/kosit/validationtool/cmd/ExtractHtmlContentAction.java @@ -21,7 +21,7 @@ import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.tasks.CreateReportAction; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.xvrl.XVRLReport; import lombok.RequiredArgsConstructor; @@ -75,7 +75,9 @@ public ProcessStepResult check(final Process results) { private static XVRLReport generateXVRLReport(final Result result) { // TODO create report here - return XVRLBuilder.builder().name("Extract Html Content").addErrors(result.getErrors()).build(); + return XVRLReportBuilder.builder().name("Extract Html Content").addErrors(result.getErrors()) + .setValid("" + result.getErrors().isEmpty()) + .build(); } private void print(final String origName, final XdmItem xdmItem) { diff --git a/src/main/java/de/kosit/validationtool/cmd/InternalCheck.java b/src/main/java/de/kosit/validationtool/cmd/InternalCheck.java index c0b3989..7a44ee7 100644 --- a/src/main/java/de/kosit/validationtool/cmd/InternalCheck.java +++ b/src/main/java/de/kosit/validationtool/cmd/InternalCheck.java @@ -69,10 +69,10 @@ public Result checkInput(final Input input) { final CheckAction.Process process = new CheckAction.Process(input, createXVRLMetadata()); final Result result = runCheckInternal(process); // TODO where are AssertionResults set? - //if (process.getAssertionResult() != null) { - // this.checkAssertions += process.getAssertionResult().getObject(); - // this.failedAssertions += process.getAssertionResult().getErrors().size(); - //} + // if (process.getAssertionResult() != null) { + // this.checkAssertions += process.getAssertionResult().getObject(); + // this.failedAssertions += process.getAssertionResult().getErrors().size(); + // } return result; } diff --git a/src/main/java/de/kosit/validationtool/cmd/PrintMemoryStats.java b/src/main/java/de/kosit/validationtool/cmd/PrintMemoryStats.java index 2738798..8e22fbc 100644 --- a/src/main/java/de/kosit/validationtool/cmd/PrintMemoryStats.java +++ b/src/main/java/de/kosit/validationtool/cmd/PrintMemoryStats.java @@ -20,7 +20,7 @@ import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.xvrl.XVRLReport; import lombok.extern.slf4j.Slf4j; @@ -59,6 +59,10 @@ public ProcessStepResult check(final Process results) { private static XVRLReport generateXVRLReport(final Result result) { // TODO create report here - return XVRLBuilder.builder().name("Print Memory Stats").addErrors(result.getErrors()).build(); + return XVRLReportBuilder.builder() + .name("Print Memory Stats") + .addErrors(result.getErrors()) + .setValid("" + result.getErrors().isEmpty()) + .build(); } } diff --git a/src/main/java/de/kosit/validationtool/cmd/PrintReportAction.java b/src/main/java/de/kosit/validationtool/cmd/PrintReportAction.java index 5d5485b..b1d3684 100644 --- a/src/main/java/de/kosit/validationtool/cmd/PrintReportAction.java +++ b/src/main/java/de/kosit/validationtool/cmd/PrintReportAction.java @@ -21,7 +21,7 @@ import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.tasks.CreateReportAction; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.xvrl.XVRLReport; import lombok.RequiredArgsConstructor; @@ -69,6 +69,10 @@ public ProcessStepResult check(final Process results) { private static XVRLReport generateXVRLReport(final Result result) { // TODO create report here - return XVRLBuilder.builder().name("Print Report").addErrors(result.getErrors()).build(); + return XVRLReportBuilder.builder() + .name("Print Report") + .addErrors(result.getErrors()) + .setValid("" + result.getErrors().isEmpty()) + .build(); } } diff --git a/src/main/java/de/kosit/validationtool/cmd/SerializeReportAction.java b/src/main/java/de/kosit/validationtool/cmd/SerializeReportAction.java index 003e537..de9186c 100644 --- a/src/main/java/de/kosit/validationtool/cmd/SerializeReportAction.java +++ b/src/main/java/de/kosit/validationtool/cmd/SerializeReportAction.java @@ -21,7 +21,7 @@ import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.tasks.CreateReportAction; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.xvrl.XVRLReport; import lombok.RequiredArgsConstructor; @@ -73,7 +73,11 @@ public ProcessStepResult check(final Process results) { private static XVRLReport generateXVRLReport(final Result result) { // TODO create report here - return XVRLBuilder.builder().name("Serialize Report").addErrors(result.getErrors()).build(); + return XVRLReportBuilder.builder() + .name("Serialize Report") + .addErrors(result.getErrors()) + .setValid("" + result.getErrors().isEmpty()) + .build(); } @Override diff --git a/src/main/java/de/kosit/validationtool/cmd/SerializeReportInputAction.java b/src/main/java/de/kosit/validationtool/cmd/SerializeReportInputAction.java index d134c51..d8d1355 100644 --- a/src/main/java/de/kosit/validationtool/cmd/SerializeReportInputAction.java +++ b/src/main/java/de/kosit/validationtool/cmd/SerializeReportInputAction.java @@ -22,7 +22,7 @@ import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.xvrl.XVRLReport; import lombok.RequiredArgsConstructor; @@ -66,7 +66,11 @@ public ProcessStepResult check(final Process results) { private static XVRLReport generateXVRLReport(final Result result) { // TODO create report here - return XVRLBuilder.builder().name("Serialize Report Input").addErrors(result.getErrors()).build(); + return XVRLReportBuilder.builder() + .name("Serialize Report Input") + .addErrors(result.getErrors()) + .setValid("" + result.getErrors().isEmpty()) + .build(); } @Override diff --git a/src/main/java/de/kosit/validationtool/impl/DefaultCheck.java b/src/main/java/de/kosit/validationtool/impl/DefaultCheck.java index c60b296..0a928f7 100644 --- a/src/main/java/de/kosit/validationtool/impl/DefaultCheck.java +++ b/src/main/java/de/kosit/validationtool/impl/DefaultCheck.java @@ -96,16 +96,6 @@ public DefaultCheck(final Processor processor, final Configuration... configurat this.checkSteps.add(new ComputeAcceptanceAction()); } - protected static CreateReportInput createReport() { - final CreateReportInput type = new CreateReportInput(); - final EngineType e = new EngineType(); - e.setName(EngineInformation.getName() + " " + EngineInformation.getVersion()); - type.setEngine(e); - type.setTimestamp(createTimestamp()); - type.setFrameworkVersion(EngineInformation.getFrameworkVersion()); - return type; - } - protected static XVRLMetadata createXVRLMetadata() { final XVRLMetadata metadata = new XVRLMetadata(); @@ -169,8 +159,7 @@ private Result createResult(final Process process) { .getResult(SchematronValidationAction.class); if (schematronValidationResult != null) { xvrlResult.setSchematronResult(schematronValidationResult.getObject().stream() - .map(schematronResult -> schematronResult.getResults().getSchematronOutput()) - .collect(Collectors.toList())); + .map(schematronResult -> schematronResult.getResults().getSchematronOutput()).collect(Collectors.toList())); } xvrlResult.setProcessingSuccessful(!process.isStopped() && process.isFinished()); diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java index b5afa08..abfe59c 100644 --- a/src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java +++ b/src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java @@ -19,7 +19,9 @@ import java.util.Collections; import java.util.Optional; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLDetectionBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; +import de.kosit.validationtool.model.xvrl.XVRLDetection; import de.kosit.validationtool.model.xvrl.XVRLReport; import lombok.RequiredArgsConstructor; @@ -46,17 +48,17 @@ public class ComputeAcceptanceAction implements CheckAction { @Override - public ProcessStepResult check(final Process results) { + public ProcessStepResult check(final Process process) { final ProcessStepResult stepResult = new ProcessStepResult(); Result result = new Result<>(AcceptRecommendation.UNDEFINED); - if (!results.isStopped() && results.getResult(DocumentParseAction.class).isValid()) { - if (preCondtionsMatch(results)) { - final Result scenarioSelection = results.getResult(ScenarioSelectionAction.class); + if (!process.isStopped() && process.getResult(DocumentParseAction.class).isValid()) { + if (preCondtionsMatch(process)) { + final Result scenarioSelection = process.getResult(ScenarioSelectionAction.class); final Optional acceptMatch = scenarioSelection.getObject().getAcceptSelector(); - if (results.getResult(SchemaValidationAction.class).isValid() && acceptMatch.isPresent()) { - result = evaluateAcceptanceMatch(results, acceptMatch.get()); + if (process.getResult(SchemaValidationAction.class).isValid() && acceptMatch.isPresent()) { + result = evaluateAcceptanceMatch(process, acceptMatch.get()); } else { - result = evaluateSchemaAndSchematron(results); + result = evaluateSchemaAndSchematron(process); } } else { XMLSyntaxError xmlSyntaxError = new XMLSyntaxError(); @@ -71,8 +73,15 @@ public ProcessStepResult check(final Process results) { } private static XVRLReport generateXVRLReport(final Result currentResult) { - // TODO create report here - return XVRLBuilder.builder().name("Compute Acceptance Validator").addErrors(currentResult.getErrors()).build(); + return XVRLReportBuilder.builder() + .name("Compute Acceptance Validator") + .addErrors(currentResult.getErrors()) + .addDetections(Collections.singletonList(XVRLDetectionBuilder.builder() + .setSeverity(XVRLDetection.Severity.INFO) + .addMessageString(currentResult.getObject().name()) + .build())) + .setValid("" + currentResult.getErrors().isEmpty()) + .build(); } private static Result evaluateSchemaAndSchematron(final Process results) { @@ -95,11 +104,13 @@ private static boolean hasSchematronErrors(final Process results) { return !report.getAllErrors().isEmpty(); } - private static Result evaluateAcceptanceMatch(final Process results, final XPathSelector selector) { + private static Result evaluateAcceptanceMatch(final Process results, + final XPathSelector selector) { try { final Result report = results.getResult(CreateReportAction.class); selector.setContextItem(report.getObject()); - AcceptRecommendation effectiveBooleanValue = selector.effectiveBooleanValue() ? AcceptRecommendation.ACCEPTABLE : AcceptRecommendation.REJECT; + AcceptRecommendation effectiveBooleanValue = selector.effectiveBooleanValue() ? AcceptRecommendation.ACCEPTABLE + : AcceptRecommendation.REJECT; return new Result<>(effectiveBooleanValue); } catch (final SaxonApiException e) { final String msg = String.format("Error evaluating accept recommendation: %s", selector.getUnderlyingXPathContext().toString()); diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/CreateDocumentIdentificationAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/CreateDocumentIdentificationAction.java index 002f171..dff65cd 100644 --- a/src/main/java/de/kosit/validationtool/impl/tasks/CreateDocumentIdentificationAction.java +++ b/src/main/java/de/kosit/validationtool/impl/tasks/CreateDocumentIdentificationAction.java @@ -18,13 +18,17 @@ import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLDetectionBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.DocumentIdentificationType; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.xvrl.Document; +import de.kosit.validationtool.model.xvrl.XVRLDetection; import de.kosit.validationtool.model.xvrl.XVRLMetadata; import de.kosit.validationtool.model.xvrl.XVRLReport; +import java.util.Collections; + /** * Creates a document identification element for the report by using the generates hash. * @@ -34,25 +38,33 @@ public class CreateDocumentIdentificationAction implements CheckAction { @Override public ProcessStepResult check(final Process process) { - final DocumentIdentificationType i = new DocumentIdentificationType(); - final DocumentIdentificationType.DocumentHash h = new DocumentIdentificationType.DocumentHash(); - h.setHashAlgorithm(process.getInput().getDigestAlgorithm()); - h.setHashValue(process.getInput().getHashCode()); - i.setDocumentHash(h); - i.setDocumentReference(process.getInput().getName()); + final DocumentIdentificationType documentIdentificationType = new DocumentIdentificationType(); + final DocumentIdentificationType.DocumentHash documentHash = new DocumentIdentificationType.DocumentHash(); + documentHash.setHashAlgorithm(process.getInput().getDigestAlgorithm()); + documentHash.setHashValue(process.getInput().getHashCode()); + documentIdentificationType.setDocumentHash(documentHash); + documentIdentificationType.setDocumentReference(process.getInput().getName()); addDocumentIdentification(process); ProcessStepResult processStepResult = new ProcessStepResult(); processStepResult.setType(CreateDocumentIdentificationAction.class); - Result result = new Result<>(i); + Result result = new Result<>(documentIdentificationType); processStepResult.setResult(result); processStepResult.setReport(generateXVRLReport(result)); return processStepResult; } - private static XVRLReport generateXVRLReport(final Result currentResult) { - // TODO create report here - return XVRLBuilder.builder().name("CreateDocument Identification Validator").addErrors(currentResult.getErrors()).build(); + private static XVRLReport generateXVRLReport(final Result currentResult) { + DocumentIdentificationType result = currentResult.getObject(); + return XVRLReportBuilder.builder() + .name("CreateDocument Identification Validator") + .addErrors(currentResult.getErrors()) + .addDetections(Collections.singletonList(XVRLDetectionBuilder.builder() + .setSeverity(XVRLDetection.Severity.INFO) + .addMessageString(result.toString()).build())) + .setValid("" + currentResult.getErrors().isEmpty()) + .addDocumentIdentification(result.getDocumentReference()) + .build(); } private static void addDocumentIdentification(final Process transporter) { diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/CreateReportAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/CreateReportAction.java index 4a1de53..e144cc5 100644 --- a/src/main/java/de/kosit/validationtool/impl/tasks/CreateReportAction.java +++ b/src/main/java/de/kosit/validationtool/impl/tasks/CreateReportAction.java @@ -25,7 +25,9 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.util.JAXBSource; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLDetectionBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; +import de.kosit.validationtool.model.xvrl.XVRLDetection; import de.kosit.validationtool.model.xvrl.XVRLReport; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; @@ -205,8 +207,7 @@ public ProcessStepResult check(final Process process) { transformer.setURIResolver(scenario.getUriResolver()); if (scenario.getUnparsedTextURIResolver() != null) { - transformer.getUnderlyingController() - .setUnparsedTextURIResolver(scenario.getUnparsedTextURIResolver()); + transformer.getUnderlyingController().setUnparsedTextURIResolver(scenario.getUnparsedTextURIResolver()); } if (parsedDocument != null) { transformer.setParameter(new QName("input-document"), parsedDocument); @@ -233,8 +234,14 @@ public ProcessStepResult check(final Process process) { } private static XVRLReport generateXVRLReport(final Result currentResult) { - // TODO create report here - return XVRLBuilder.builder().name("Create Report Validator").addErrors(currentResult.getErrors()).build(); + return XVRLReportBuilder.builder() + .name("Create Report Validator") + .addErrors(currentResult.getErrors()) + .addDetections(currentResult.getObject() != null ? Collections.singletonList(XVRLDetectionBuilder.builder() + .setSeverity(XVRLDetection.Severity.INFO) + .addMessageString(currentResult.getObject().toString()).build()): null) + .setValid("" + currentResult.getErrors().isEmpty()) + .build(); } private XdmNode createErrorInformation(final Collection errors) throws SaxonApiException, SAXException { diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/DocumentParseAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/DocumentParseAction.java index a3c5f54..8c805ef 100644 --- a/src/main/java/de/kosit/validationtool/impl/tasks/DocumentParseAction.java +++ b/src/main/java/de/kosit/validationtool/impl/tasks/DocumentParseAction.java @@ -19,6 +19,8 @@ import java.io.IOException; import java.util.Collections; +import de.kosit.validationtool.impl.xvrl.XVRLDetectionBuilder; +import de.kosit.validationtool.model.xvrl.XVRLDetection; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -26,7 +28,7 @@ import de.kosit.validationtool.impl.input.XdmNodeInput; import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; -import de.kosit.validationtool.impl.xvrl.XVRLBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.reportInput.XMLSyntaxErrorSeverity; import de.kosit.validationtool.model.xvrl.XVRLReport; @@ -101,7 +103,13 @@ public ProcessStepResult check(final Process process) { } private static XVRLReport generateXVRLReport(final Result parserResult) { - // TODO create report here - return XVRLBuilder.builder().name("Document wellformedness Validator").addErrors(parserResult.getErrors()).build(); + return XVRLReportBuilder.builder() + .name("Document wellformedness Validator") + .addErrors(parserResult.getErrors()) + .addDetections(parserResult.getObject() != null ? Collections.singletonList(XVRLDetectionBuilder.builder() + .setSeverity(XVRLDetection.Severity.INFO) + .addMessageString(parserResult.getObject().toString()).build()) : null) + .setValid("" + parserResult.getErrors().isEmpty()) + .build(); } } diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/ScenarioSelectionAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/ScenarioSelectionAction.java index 151f6f0..6aa1a0b 100644 --- a/src/main/java/de/kosit/validationtool/impl/tasks/ScenarioSelectionAction.java +++ b/src/main/java/de/kosit/validationtool/impl/tasks/ScenarioSelectionAction.java @@ -16,22 +16,21 @@ package de.kosit.validationtool.impl.tasks; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - import de.kosit.validationtool.impl.Scenario; import de.kosit.validationtool.impl.ScenarioRepository; import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; +import de.kosit.validationtool.impl.xvrl.XVRLDetectionBuilder; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; -import de.kosit.validationtool.model.xvrl.Validator; import de.kosit.validationtool.model.xvrl.XVRLDetection; -import de.kosit.validationtool.model.xvrl.XVRLDigest; -import de.kosit.validationtool.model.xvrl.XVRLMetadata; import de.kosit.validationtool.model.xvrl.XVRLReport; - +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import net.sf.saxon.s9api.XdmNode; +import java.util.Collections; + /** * Identifiziert das der Eingabe entsprechende Szenario, sofern eines konfiguriert ist. Setzt das Fallback-Szenario, * wenn keines identifiziert werden konnte. @@ -62,39 +61,33 @@ public ProcessStepResult check(final Process results) { final ProcessStepResult result = new ProcessStepResult(); result.setResult(scenarioTypeResult); - result.setReport(generateXVRLReport(scenarioTypeResult)); + result.setReport(generateXVRLReport(scenarioTypeResult, results.getInput().getName())); result.setType(ScenarioSelectionAction.class); return result; } - private static XVRLReport generateXVRLReport(final Result scenarioTypeResult) { - final XVRLReport xvrlReport = new XVRLReport(); + private static XVRLReport generateXVRLReport(final Result scenarioTypeResult, String name) { + XVRLReportBuilder builder = XVRLReportBuilder.builder().name("Scenario-matcher"); - final XVRLMetadata reportMetadata = new XVRLMetadata(); - final Validator validator = new Validator(); - validator.setName("Scenario-matcher"); - reportMetadata.getValidators().add(validator); - xvrlReport.setMetadata(reportMetadata); - - final XVRLDigest xvrlDigest = new XVRLDigest(); - String valid = "true"; - final XVRLDetection xvrlDetection = new XVRLDetection(); if (scenarioTypeResult.getObject().isFallback()) { - valid = "false"; - xvrlDetection.setSeverity(XVRLDetection.Severity.ERROR); - // TODO results.getInput().getName() instead of "" - xvrlDetection.addMessageString(String.format("No valid scenario configuration found for %s", "")); + + XVRLDetection xvrlDetection= XVRLDetectionBuilder.builder() + .addMessageString(String.format("No valid scenario configuration found for %s", name)) + .setSeverity(XVRLDetection.Severity.ERROR) + .build(); + builder.setValid("false") + .addDetections(Collections.singletonList(xvrlDetection)); } else { - xvrlDetection.setCode("scenario-matched"); - xvrlDetection.setSeverity(XVRLDetection.Severity.INFO); - // TODO results.getInput().getName() - xvrlDetection.addMessageString(String.format("Scenario %s identified for %s", scenarioTypeResult.getObject().getName(), "")); + XVRLDetection xvrlDetection= XVRLDetectionBuilder.builder() + .addMessageString(String.format("Scenario %s identified for %s", scenarioTypeResult.getObject().getName(), name)) + .setSeverity(XVRLDetection.Severity.INFO) + .setCode("scenario-matched") + .build(); + builder.setValid("true") + .addDetections(Collections.singletonList(xvrlDetection)); } - xvrlDigest.setValid(valid); - xvrlReport.setDigest(xvrlDigest); - xvrlReport.getDetection().add(xvrlDetection); - return xvrlReport; + return builder.build(); } private Result determineScenario(final XdmNode document) { diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/SchemaValidationAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/SchemaValidationAction.java index d71edb3..5d20b2c 100644 --- a/src/main/java/de/kosit/validationtool/impl/tasks/SchemaValidationAction.java +++ b/src/main/java/de/kosit/validationtool/impl/tasks/SchemaValidationAction.java @@ -16,49 +16,40 @@ package de.kosit.validationtool.impl.tasks; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigInteger; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Validator; - -import org.apache.commons.io.FileUtils; -import org.xml.sax.SAXException; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; - import de.kosit.validationtool.api.Input; import de.kosit.validationtool.impl.CollectingErrorEventHandler; import de.kosit.validationtool.impl.Scenario; import de.kosit.validationtool.impl.input.AbstractInput; import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.ValidationResultsXmlSchema; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.reportInput.XMLSyntaxErrorSeverity; import de.kosit.validationtool.model.xvrl.Schema; -import de.kosit.validationtool.model.xvrl.XVRLDigest; -import de.kosit.validationtool.model.xvrl.XVRLMetadata; import de.kosit.validationtool.model.xvrl.XVRLReport; - +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; import net.sf.saxon.s9api.Processor; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.Serializer; import net.sf.saxon.s9api.XdmNode; +import org.apache.commons.io.FileUtils; +import org.xml.sax.SAXException; + +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Validator; +import java.io.*; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * Schema valiation of the {@link Input} with the schema of the supplied scenario. This implementation is based on JDK @@ -184,13 +175,6 @@ public ProcessStepResult check(final Process results) { } private static XVRLReport generateXVRLReport(final ValidationResultsXmlSchema result) { - // TODO create report here - final XVRLReport xvrlReport = new XVRLReport(); - - final XVRLMetadata reportMetadata = new XVRLMetadata(); - final de.kosit.validationtool.model.xvrl.Validator validator = new de.kosit.validationtool.model.xvrl.Validator(); - validator.setName("Schema Validator"); - reportMetadata.getValidators().add(validator); final List schemaList = new ArrayList<>(); result.getResource().forEach(resourceType -> { @@ -199,28 +183,28 @@ private static XVRLReport generateXVRLReport(final ValidationResultsXmlSchema re schema.setSchematypens(resourceType.getName()); schemaList.add(schema); }); - reportMetadata.getSchemas().addAll(schemaList); - xvrlReport.setMetadata(reportMetadata); + long errorCount = 0; + long fatalErrorCount = 0; - final XVRLDigest xvrlDigest = new XVRLDigest(); String valid = "true"; if (!result.getXmlSyntaxError().isEmpty()) { valid = "false"; - final long errorCount = result.getXmlSyntaxError().stream() + errorCount = result.getXmlSyntaxError().stream() .filter(xmlSyntaxError -> xmlSyntaxError.getSeverityCode() == XMLSyntaxErrorSeverity.SEVERITY_ERROR).count(); - xvrlDigest.setErrorCount(BigInteger.valueOf(errorCount)); - final long fatalErrorCount = result.getXmlSyntaxError().stream() + fatalErrorCount = result.getXmlSyntaxError().stream() .filter(xmlSyntaxError -> xmlSyntaxError.getSeverityCode() == XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR).count(); - xvrlDigest.setFatalErrorCount(BigInteger.valueOf(fatalErrorCount)); - - xvrlReport.addErrorDetectionsFromXMLSyntaxErrors(result.getXmlSyntaxError()); } - xvrlDigest.setValid(valid); - xvrlReport.setDigest(xvrlDigest); - - return xvrlReport; + XVRLReportBuilder builder = XVRLReportBuilder.builder() + .name("Schema Validator") + .addSchemas(schemaList) + .setValid(valid) + .setErrorCount(BigInteger.valueOf(errorCount)) + .setFatalErrorCount(BigInteger.valueOf(fatalErrorCount)) + .addErrorDetectionsFromXMLSyntaxErrors(result.getXmlSyntaxError()); + + return builder.build(); } private SourceProvider resolveSource(final Process results) throws IOException, SaxonApiException { diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/SchematronValidationAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/SchematronValidationAction.java index 0e69c14..bf27684 100644 --- a/src/main/java/de/kosit/validationtool/impl/tasks/SchematronValidationAction.java +++ b/src/main/java/de/kosit/validationtool/impl/tasks/SchematronValidationAction.java @@ -16,42 +16,35 @@ package de.kosit.validationtool.impl.tasks; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import javax.xml.transform.dom.DOMSource; - -import org.oclc.purl.dsdl.svrl.FailedAssert; -import org.oclc.purl.dsdl.svrl.SchematronOutput; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - import de.kosit.validationtool.impl.CollectingErrorEventHandler; import de.kosit.validationtool.impl.ConversionService; import de.kosit.validationtool.impl.Scenario; import de.kosit.validationtool.impl.Scenario.Transformation; import de.kosit.validationtool.impl.model.ProcessStepResult; import de.kosit.validationtool.impl.model.Result; +import de.kosit.validationtool.impl.xvrl.XVRLReportBuilder; import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron; import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron.Results; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.scenarios.ResourceType; import de.kosit.validationtool.model.xvrl.Schema; -import de.kosit.validationtool.model.xvrl.Validator; -import de.kosit.validationtool.model.xvrl.XVRLDigest; -import de.kosit.validationtool.model.xvrl.XVRLMetadata; import de.kosit.validationtool.model.xvrl.XVRLReport; - +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import net.sf.saxon.dom.NodeOverNodeInfo; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmDestination; import net.sf.saxon.s9api.XdmNode; import net.sf.saxon.s9api.XsltTransformer; +import org.oclc.purl.dsdl.svrl.FailedAssert; +import org.oclc.purl.dsdl.svrl.SchematronOutput; import org.oclc.purl.dsdl.svrl.Text; +import javax.xml.transform.dom.DOMSource; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + /** * Ausführung von konfigurierten Schematron Validierungen eines Szenarios. * @@ -127,13 +120,7 @@ public ProcessStepResult check(final Process process) { } private static XVRLReport generateXVRLReport(final List validationResult) { - // TODO create report here - final XVRLReport xvrlReport = new XVRLReport(); - - final XVRLMetadata reportMetadata = new XVRLMetadata(); - final Validator validator = new Validator(); - validator.setName("Schematron Validator"); - reportMetadata.getValidators().add(validator); + XVRLReportBuilder builder = XVRLReportBuilder.builder().name("Schematron Validator").setValid("true"); final List schemaList = new ArrayList<>(); validationResult.forEach(validationResultsSchematron -> { @@ -147,21 +134,15 @@ private static XVRLReport generateXVRLReport(final List getMessages(); @@ -58,26 +54,4 @@ default Location getErrorLocation() { default boolean hasErrors() { return getSeverity() == XVRLDetection.Severity.ERROR || getSeverity() == XVRLDetection.Severity.FATAL_ERROR; } - - default void addMessageString(String message) { - XVRLMessage messageObject = new XVRLMessage(); - messageObject.getContent().add(message); - getMessages().add(messageObject); - } - - default void addLocation(int lineNumber, int columnNumber, String xpath) { - Location location = new Location(); - location.setLine(BigInteger.valueOf(lineNumber)); - location.setColumn(BigInteger.valueOf(columnNumber)); - location.setXpath(xpath); - getLocations().add(location); - } - - default void addSeverityFromXmlError(XMLSyntaxError xmlSyntaxError) { - if (xmlSyntaxError.getSeverity() == SEVERITY_FATAL_ERROR) { - setSeverity(XVRLDetection.Severity.FATAL_ERROR); - } else { - setSeverity(XVRLDetection.Severity.ERROR); - } - } } diff --git a/src/main/java/de/kosit/validationtool/impl/xvrl/BaseReport.java b/src/main/java/de/kosit/validationtool/impl/xvrl/BaseReport.java index 82a9659..05032e2 100644 --- a/src/main/java/de/kosit/validationtool/impl/xvrl/BaseReport.java +++ b/src/main/java/de/kosit/validationtool/impl/xvrl/BaseReport.java @@ -16,12 +16,8 @@ package de.kosit.validationtool.impl.xvrl; -import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.xvrl.XVRLDetection; -import org.oclc.purl.dsdl.svrl.FailedAssert; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -37,40 +33,4 @@ default List getAllErrors() { default List getAllErrorDetections() { return getDetection().stream().filter(BaseDetection::hasErrors).collect(Collectors.toList()); } - - default void addErrorDetectionsFromXMLSyntaxErrors(Collection errors) { - if (errors == null) { - return; - } - List xvrlDetectionList = new ArrayList<>(errors.size()); - errors.forEach(xmlSyntaxError -> { - XVRLDetection xvrlDetection = new XVRLDetection(); - xvrlDetection.addSeverityFromXmlError(xmlSyntaxError); - xvrlDetection.addMessageString(xmlSyntaxError.getMessage()); - if (xmlSyntaxError.getRowNumber() != null && xmlSyntaxError.getColumnNumber() != null) { - xvrlDetection.addLocation(xmlSyntaxError.getRowNumber(), xmlSyntaxError.getColumnNumber(), null); - } - xvrlDetectionList.add(xvrlDetection); - }); - getDetection().addAll(xvrlDetectionList); - } - - default void addErrorDetectionsFromFailedAsserts(List failedAsserts) { - if (failedAsserts == null) { - return; - } - List xvrlDetectionList = new ArrayList<>(failedAsserts.size()); - failedAsserts.forEach(failedAssert -> { - XVRLDetection xvrlDetection = new XVRLDetection(); - xvrlDetection.setSeverity(XVRLDetection.Severity.ERROR); - xvrlDetection.addMessageString(getFailedAssertMessage(failedAssert)); - xvrlDetection.addLocation(0, 0, failedAssert.getLocation()); - xvrlDetectionList.add(xvrlDetection); - }); - getDetection().addAll(xvrlDetectionList); - } - - default String getFailedAssertMessage(FailedAssert failedAssert) { - return failedAssert.getText().getContent().stream().map(Object::toString).collect(Collectors.joining()); - } } diff --git a/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLBuilder.java b/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLBuilder.java deleted file mode 100644 index bcb67bb..0000000 --- a/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLBuilder.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2017-2021 Koordinierungsstelle für IT-Standards (KoSIT) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package de.kosit.validationtool.impl.xvrl; - -import java.math.BigInteger; -import java.util.Collection; - -import de.kosit.validationtool.model.reportInput.XMLSyntaxError; -import de.kosit.validationtool.model.reportInput.XMLSyntaxErrorSeverity; -import de.kosit.validationtool.model.xvrl.Validator; -import de.kosit.validationtool.model.xvrl.XVRLDetection; -import de.kosit.validationtool.model.xvrl.XVRLDigest; -import de.kosit.validationtool.model.xvrl.XVRLMetadata; -import de.kosit.validationtool.model.xvrl.XVRLReport; - -public class XVRLBuilder { - - final XVRLReport xvrlReport; - - private XVRLBuilder() { - this.xvrlReport = new XVRLReport(); - this.xvrlReport.setDigest(new XVRLDigest()); - this.xvrlReport.setMetadata(new XVRLMetadata()); - } - - public static XVRLBuilder builder() { - return new XVRLBuilder(); - } - - public XVRLBuilder addErrors(final Collection errors) { - if (errors == null) { - return this; - } - this.xvrlReport.getDigest().setErrorCount(BigInteger.valueOf(errors.stream().filter(XVRLBuilder::isError).count())); - this.xvrlReport.getDigest().setFatalErrorCount(BigInteger.valueOf(errors.stream().filter(XVRLBuilder::isFatalError).count())); - - errors.forEach(xmlSyntaxError -> { - final XVRLDetection xvrlDetection = new XVRLDetection(); - xvrlDetection.addSeverityFromXmlError(xmlSyntaxError); - xvrlDetection.addMessageString(xmlSyntaxError.getMessage()); - if (xmlSyntaxError.getRowNumber() != null && xmlSyntaxError.getColumnNumber() != null) { - xvrlDetection.addLocation(xmlSyntaxError.getRowNumber(), xmlSyntaxError.getColumnNumber(), null); - } - this.xvrlReport.getDetection().add(xvrlDetection); - }); - this.xvrlReport.getDigest().setValid("false"); - return this; - } - - private static boolean isFatalError(final XMLSyntaxError xmlSyntaxError) { - return xmlSyntaxError.getSeverityCode() == XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR; - } - - private static boolean isError(final XMLSyntaxError xmlSyntaxError) { - return xmlSyntaxError.getSeverityCode() == XMLSyntaxErrorSeverity.SEVERITY_ERROR; - } - - public XVRLReport build() { - return this.xvrlReport; - } - - public XVRLBuilder name(final String name) { - final Validator validator = new Validator(); - validator.setName(name); - this.xvrlReport.getMetadata().getValidators().add(validator); - return this; - } -} diff --git a/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLDetectionBuilder.java b/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLDetectionBuilder.java new file mode 100644 index 0000000..ea03fb6 --- /dev/null +++ b/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLDetectionBuilder.java @@ -0,0 +1,79 @@ +/* + * Copyright 2017-2021 Koordinierungsstelle für IT-Standards (KoSIT) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package de.kosit.validationtool.impl.xvrl; + +import de.kosit.validationtool.model.reportInput.XMLSyntaxError; +import de.kosit.validationtool.model.xvrl.Location; +import de.kosit.validationtool.model.xvrl.XVRLDetection; +import de.kosit.validationtool.model.xvrl.XVRLMessage; + +import java.math.BigInteger; + +import static de.kosit.validationtool.api.XmlError.Severity.SEVERITY_FATAL_ERROR; + +public class XVRLDetectionBuilder { + + final XVRLDetection xvrlDetection; + + private XVRLDetectionBuilder() { + this.xvrlDetection = new XVRLDetection(); + } + + public static XVRLDetectionBuilder builder() { + return new XVRLDetectionBuilder(); + } + + public XVRLDetectionBuilder addSeverityFromXmlError(XMLSyntaxError xmlSyntaxError) { + if (xmlSyntaxError.getSeverity() == SEVERITY_FATAL_ERROR) { + xvrlDetection.setSeverity(XVRLDetection.Severity.FATAL_ERROR); + } else { + xvrlDetection.setSeverity(XVRLDetection.Severity.ERROR); + } + + return this; + } + + public XVRLDetectionBuilder addMessageString(String message) { + XVRLMessage messageObject = new XVRLMessage(); + messageObject.getContent().add(message); + xvrlDetection.getMessages().add(messageObject); + return this; + } + + public XVRLDetectionBuilder addLocation(int lineNumber, int columnNumber, String xpath) { + Location location = new Location(); + location.setLine(BigInteger.valueOf(lineNumber)); + location.setColumn(BigInteger.valueOf(columnNumber)); + location.setXpath(xpath); + xvrlDetection.getLocations().add(location); + return this; + } + + public XVRLDetection build() { + return this.xvrlDetection; + } + + public XVRLDetectionBuilder setCode(String newCode) { + xvrlDetection.setCode(newCode); + return this; + } + + public XVRLDetectionBuilder setSeverity(XVRLDetection.Severity severity) { + xvrlDetection.setSeverity(severity); + return this; + } +} diff --git a/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLReportBuilder.java b/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLReportBuilder.java new file mode 100644 index 0000000..6796836 --- /dev/null +++ b/src/main/java/de/kosit/validationtool/impl/xvrl/XVRLReportBuilder.java @@ -0,0 +1,157 @@ +/* + * Copyright 2017-2021 Koordinierungsstelle für IT-Standards (KoSIT) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package de.kosit.validationtool.impl.xvrl; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import de.kosit.validationtool.model.reportInput.XMLSyntaxError; +import de.kosit.validationtool.model.reportInput.XMLSyntaxErrorSeverity; +import de.kosit.validationtool.model.xvrl.*; +import org.oclc.purl.dsdl.svrl.FailedAssert; + +public class XVRLReportBuilder { + + final XVRLReport xvrlReport; + + private XVRLReportBuilder() { + this.xvrlReport = new XVRLReport(); + this.xvrlReport.setDigest(new XVRLDigest()); + this.xvrlReport.setMetadata(new XVRLMetadata()); + } + + public static XVRLReportBuilder builder() { + return new XVRLReportBuilder(); + } + + public XVRLReportBuilder addErrors(final Collection errors) { + if (errors == null) { + return this; + } + this.xvrlReport.getDigest().setErrorCount(BigInteger.valueOf(errors.stream().filter(XVRLReportBuilder::isError).count())); + this.xvrlReport.getDigest().setFatalErrorCount(BigInteger.valueOf(errors.stream().filter(XVRLReportBuilder::isFatalError).count())); + + errors.forEach(xmlSyntaxError -> { + XVRLDetectionBuilder builder = XVRLDetectionBuilder.builder() + .addSeverityFromXmlError(xmlSyntaxError) + .addMessageString(xmlSyntaxError.getMessage()); + if (xmlSyntaxError.getRowNumber() != null && xmlSyntaxError.getColumnNumber() != null) { + builder.addLocation(xmlSyntaxError.getRowNumber(), xmlSyntaxError.getColumnNumber(), null); + } + this.xvrlReport.getDetection().add(builder.build()); + }); + this.xvrlReport.getDigest().setValid("false"); + return this; + } + + private static boolean isFatalError(final XMLSyntaxError xmlSyntaxError) { + return xmlSyntaxError.getSeverityCode() == XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR; + } + + private static boolean isError(final XMLSyntaxError xmlSyntaxError) { + return xmlSyntaxError.getSeverityCode() == XMLSyntaxErrorSeverity.SEVERITY_ERROR; + } + + public XVRLReport build() { + return this.xvrlReport; + } + + public XVRLReportBuilder name(final String name) { + final Validator validator = new Validator(); + validator.setName(name); + this.xvrlReport.getMetadata().getValidators().add(validator); + return this; + } + + public XVRLReportBuilder addDetections(List detections) { + if (detections == null) { + return this; + } + this.xvrlReport.getDetection().addAll(detections); + return this; + } + + public XVRLReportBuilder setValid(String isValid) { + this.xvrlReport.getDigest().setValid(isValid); + return this; + } + + public XVRLReportBuilder addSchemas(List schemaList) { + this.xvrlReport.getMetadata().getSchemas().addAll(schemaList); + return this; + } + + public XVRLReportBuilder addErrorDetectionsFromFailedAsserts(List failedAsserts) { + if (failedAsserts == null) { + return this; + } + List xvrlDetectionList = new ArrayList<>(failedAsserts.size()); + failedAsserts.forEach(failedAssert -> { + XVRLDetectionBuilder builder = XVRLDetectionBuilder.builder() + .setSeverity(XVRLDetection.Severity.ERROR) + .addMessageString(getFailedAssertMessage(failedAssert)) + .addLocation(0, 0, failedAssert.getLocation()); + xvrlDetectionList.add(builder.build()); + }); + this.xvrlReport.getDetection().addAll(xvrlDetectionList); + + return setErrorCount(BigInteger.valueOf(xvrlReport.getDetection().size())); + } + + private String getFailedAssertMessage(FailedAssert failedAssert) { + return failedAssert.getText().getContent().stream().map(Object::toString).collect(Collectors.joining()); + } + + public XVRLReportBuilder setErrorCount(BigInteger errorCount) { + this.xvrlReport.getDigest().setErrorCount(errorCount); + return this; + } + + public XVRLReportBuilder setFatalErrorCount(BigInteger errorCount) { + this.xvrlReport.getDigest().setFatalErrorCount(errorCount); + return this; + } + + public XVRLReportBuilder addErrorDetectionsFromXMLSyntaxErrors(Collection errors) { + if (errors == null) { + return this; + } + List xvrlDetectionList = new ArrayList<>(errors.size()); + errors.forEach(xmlSyntaxError -> { + XVRLDetectionBuilder builder = XVRLDetectionBuilder.builder() + .addSeverityFromXmlError(xmlSyntaxError) + .addMessageString(xmlSyntaxError.getMessage()); + if (xmlSyntaxError.getRowNumber() != null && xmlSyntaxError.getColumnNumber() != null) { + builder.addLocation(xmlSyntaxError.getRowNumber(), xmlSyntaxError.getColumnNumber(), null); + } + xvrlDetectionList.add(builder.build()); + }); + this.xvrlReport.getDetection().addAll(xvrlDetectionList); + return this; + + } + + public XVRLReportBuilder addDocumentIdentification(String documentReference) { + final Document document = new Document(); + document.setHref(documentReference); + this.xvrlReport.getMetadata().getDocuments().add(document); + return this; + } +} diff --git a/src/test/java/de/kosit/validationtool/impl/Helper.java b/src/test/java/de/kosit/validationtool/impl/Helper.java index 702f90e..fddf2d6 100644 --- a/src/test/java/de/kosit/validationtool/impl/Helper.java +++ b/src/test/java/de/kosit/validationtool/impl/Helper.java @@ -23,6 +23,9 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Paths; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import javax.xml.transform.stream.StreamSource; @@ -32,6 +35,7 @@ import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.tasks.*; import de.kosit.validationtool.impl.xml.ProcessorProvider; +import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron; import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.xvrl.XVRLReport; @@ -212,4 +216,14 @@ public static void setSchemaValidationResult(CheckAction.Process process, Result stepResult.setReport(new XVRLReport()); process.addStepResult(stepResult); } + + + public static void setSchematronResult(CheckAction.Process process, Result, XMLSyntaxError> schematronResult) { + ProcessStepResult stepResult = new ProcessStepResult(); + stepResult.setType(SchematronValidationAction.class); + stepResult.setResult(schematronResult); + stepResult.setReport(new XVRLReport()); + process.addStepResult(stepResult); + } + } diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java index c9e63fb..7af245e 100644 --- a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java +++ b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java @@ -122,7 +122,7 @@ public void testValidAcceptMatchOnSchemaFailed() { @Test public void testMissingSchemaCheck() { - final Process process = createProcess(null, Collections.emptyList()); + final Process process = createProcess(null, new Result<>(Collections.emptyList())); ProcessStepResult stepResult = this.action.check(process); // noinspection unchecked Result checkResult = (Result) stepResult.getResult(); diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/SchemaValidatorActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/SchemaValidatorActionTest.java index 69804ea..2473ab8 100644 --- a/src/test/java/de/kosit/validationtool/impl/tasks/SchemaValidatorActionTest.java +++ b/src/test/java/de/kosit/validationtool/impl/tasks/SchemaValidatorActionTest.java @@ -167,7 +167,7 @@ public void testProcessingError() throws IOException, SAXException { scenario.setSchema(schema); ProcessStepResult processStepResult = this.service.check(process); // noinspection unchecked - Result result = (Result)processStepResult.getResult(); + Result result = (Result) processStepResult.getResult(); assertThat(result).isNotNull(); assertThat(result.getErrors()).isNotEmpty(); } diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/SchematronValidationActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/SchematronValidationActionTest.java index d56e736..d7b6a6c 100644 --- a/src/test/java/de/kosit/validationtool/impl/tasks/SchematronValidationActionTest.java +++ b/src/test/java/de/kosit/validationtool/impl/tasks/SchematronValidationActionTest.java @@ -68,7 +68,8 @@ public void testProcessingError() throws IOException, SaxonApiException { scenario.setSchematronValidations(Collections.singletonList(new Transformation(exec, resourceType))); ProcessStepResult processStepResult = this.action.check(process); // noinspection unchecked - Result, XMLSyntaxError> result = (Result, XMLSyntaxError>)processStepResult.getResult(); + Result, XMLSyntaxError> result = (Result, XMLSyntaxError>) processStepResult + .getResult(); assertThat(result.getObject()).isNotNull(); assertThat(result.getErrors()).isNotEmpty(); } diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/TestProcessBuilder.java b/src/test/java/de/kosit/validationtool/impl/tasks/TestProcessBuilder.java index d26a4f1..182f352 100644 --- a/src/test/java/de/kosit/validationtool/impl/tasks/TestProcessBuilder.java +++ b/src/test/java/de/kosit/validationtool/impl/tasks/TestProcessBuilder.java @@ -63,8 +63,7 @@ public static Process createProcess(final Input input, final boolean parse) { return createProcess(input, parse, new XVRLMetadata()); } - public static Process createProcess(final Input input, final boolean parse, - final XVRLMetadata xvrlMetadata) { + public static Process createProcess(final Input input, final boolean parse, final XVRLMetadata xvrlMetadata) { final Process process = new Process(input, xvrlMetadata); if (parse) { Helper.setParserResult(process, process.getInput()); @@ -107,7 +106,9 @@ private static XdmNode createReport() { static Process createProcess(final boolean schemaValid, final boolean schematronValid) { final Result schemaResult = schemaValid ? new Result<>(true) : new Result<>(Collections.singletonList(new XMLSyntaxError())); - final List schematronResult = schematronValid ? Collections.emptyList() : createSchematronError(); + final Result, XMLSyntaxError> schematronResult = schematronValid ? + new Result<>(Collections.emptyList(), Collections.emptyList()) : + new Result, XMLSyntaxError>(createSchematronError()); return createProcess(schemaResult, schematronResult); } @@ -123,14 +124,13 @@ private static List createSchematronError() { } static Process createProcess(final Result schemaResult, - final Collection schematronResult) { - final CreateReportInput reportInput = new CreateReportInput(); - reportInput.getValidationResultsSchematron().addAll(schematronResult); - final Process process = createProcess(InputFactory.read("".getBytes(), "someCheck"), true, - new XVRLMetadata()); + final Result, XMLSyntaxError> schematronResult) { + final Process process = createProcess(InputFactory.read("".getBytes(), "someCheck"), true, new XVRLMetadata()); Helper.setSchemaValidationResult(process, schemaResult); + Helper.setSchematronResult(process, schematronResult); + Helper.setCreateReport(process, createReport()); return process;