Skip to content

Commit

Permalink
#79 Fill the Step-Reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Maza committed Jun 29, 2021
1 parent 0317080 commit fed6c94
Show file tree
Hide file tree
Showing 25 changed files with 451 additions and 340 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -104,9 +103,15 @@ public ProcessStepResult check(final Process results) {
return processStepResult;
}

private static XVRLReport generateXVRLReport(final Result<Integer, XMLSyntaxError> parserResult) {
// TODO create report here
return XVRLBuilder.builder().name("Assertions Validator").addErrors(parserResult.getErrors()).build();
private static XVRLReport generateXVRLReport(final Result<Integer, XMLSyntaxError> 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<AssertionType> findAssertions(final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +75,9 @@ public ProcessStepResult check(final Process results) {

private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError> 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) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/kosit/validationtool/cmd/InternalCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +59,10 @@ public ProcessStepResult check(final Process results) {

private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,6 +69,10 @@ public ProcessStepResult check(final Process results) {

private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,7 +73,11 @@ public ProcessStepResult check(final Process results) {

private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,7 +66,11 @@ public ProcessStepResult check(final Process results) {

private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError> 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
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/de/kosit/validationtool/impl/DefaultCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<AcceptRecommendation, XMLSyntaxError> result = new Result<>(AcceptRecommendation.UNDEFINED);
if (!results.isStopped() && results.getResult(DocumentParseAction.class).isValid()) {
if (preCondtionsMatch(results)) {
final Result<Scenario, String> scenarioSelection = results.getResult(ScenarioSelectionAction.class);
if (!process.isStopped() && process.getResult(DocumentParseAction.class).isValid()) {
if (preCondtionsMatch(process)) {
final Result<Scenario, String> scenarioSelection = process.getResult(ScenarioSelectionAction.class);
final Optional<XPathSelector> 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();
Expand All @@ -71,8 +73,15 @@ public ProcessStepResult check(final Process results) {
}

private static XVRLReport generateXVRLReport(final Result<AcceptRecommendation, XMLSyntaxError> 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<AcceptRecommendation, XMLSyntaxError> evaluateSchemaAndSchematron(final Process results) {
Expand All @@ -95,11 +104,13 @@ private static boolean hasSchematronErrors(final Process results) {
return !report.getAllErrors().isEmpty();
}

private static Result<AcceptRecommendation, XMLSyntaxError> evaluateAcceptanceMatch(final Process results, final XPathSelector selector) {
private static Result<AcceptRecommendation, XMLSyntaxError> evaluateAcceptanceMatch(final Process results,
final XPathSelector selector) {
try {
final Result<XdmNode, XMLSyntaxError> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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<Object, XMLSyntaxError> result = new Result<>(i);
Result<DocumentIdentificationType, XMLSyntaxError> result = new Result<>(documentIdentificationType);
processStepResult.setResult(result);
processStepResult.setReport(generateXVRLReport(result));
return processStepResult;
}

private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError> currentResult) {
// TODO create report here
return XVRLBuilder.builder().name("CreateDocument Identification Validator").addErrors(currentResult.getErrors()).build();
private static XVRLReport generateXVRLReport(final Result<DocumentIdentificationType, XMLSyntaxError> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -233,8 +234,14 @@ public ProcessStepResult check(final Process process) {
}

private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError> 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<XMLSyntaxError> errors) throws SaxonApiException, SAXException {
Expand Down
Loading

0 comments on commit fed6c94

Please sign in to comment.