Skip to content

Commit

Permalink
#80 Switched to List of Containers for Report and Result by Class
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Maza committed Jun 8, 2021
1 parent 290f7c2 commit e3ae4f2
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class InternalCheck extends DefaultCheck {
*/
@Override
public Result checkInput(final Input input) {
final CheckAction.Process process = new CheckAction.Process(input, createReport(), createXVRLXvrlReportSummary());
final CheckAction.Process<?, ?, ?> process = new CheckAction.Process<>(input, createReport(), createXVRLMetadata());
final Result result = runCheckInternal(process);
if (process.getAssertionResult() != null) {
this.checkAssertions += process.getAssertionResult().getObject();
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/de/kosit/validationtool/impl/DefaultCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ protected static CreateReportInput createReport() {
return type;
}

protected static XVRLReportSummary createXVRLXvrlReportSummary() {
final XVRLReportSummary xvrlReportSummary = new XVRLReportSummary();
protected static XVRLMetadata createXVRLMetadata() {
XVRLMetadata metadata = new XVRLMetadata();

Timestamp timestamp = new Timestamp();
Expand All @@ -114,8 +113,7 @@ protected static XVRLReportSummary createXVRLXvrlReportSummary() {
validator.setVersion(EngineInformation.getVersion());
metadata.getValidators().add(validator);

xvrlReportSummary.setMetadata(metadata);
return xvrlReportSummary;
return metadata;
}

protected boolean isSuccessful(final Map<String, Result> results) {
Expand All @@ -124,11 +122,11 @@ protected boolean isSuccessful(final Map<String, Result> results) {

@Override
public Result checkInput(final Input input) {
final Process checkProcess = new Process(input, createReport(), createXVRLXvrlReportSummary());
final Process checkProcess = new Process(input, createReport(), createXVRLMetadata());
return runCheckInternal(checkProcess);
}

protected Result runCheckInternal(final Process checkProcess) {
protected Result runCheckInternal(final Process<?, ?, ?> checkProcess) {
final long started = System.currentTimeMillis();
log.info("Checking content of {}", checkProcess.getInput().getName());
for (final CheckAction action : this.checkSteps) {
Expand All @@ -145,7 +143,7 @@ protected Result runCheckInternal(final Process checkProcess) {
return result;
}

private Result createResult(final Process t) {
private Result createResult(final Process<?, ?, ?> t) {
final DefaultResult result = new DefaultResult(t.getReport(), t.getAcceptStatus(), new HtmlExtractor(this.processor));
result.setWellformed(t.getParserResult().isValid());
result.setReportInput(t.getReportInput());
Expand All @@ -158,7 +156,7 @@ private Result createResult(final Process t) {
return result;
}

private Result createXVRLResult(final Process process) {
private Result createXVRLResult(final Process<?, ?, ?> process) {

final XVRLResult xvrlResult = new XVRLResult(process.getXvrlFinalReport(), process.getAcceptStatus(),
new HtmlExtractor(this.processor));
Expand Down
60 changes: 39 additions & 21 deletions src/main/java/de/kosit/validationtool/impl/tasks/CheckAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import de.kosit.validationtool.api.AcceptRecommendation;
import de.kosit.validationtool.api.Input;
import de.kosit.validationtool.impl.Scenario;
import de.kosit.validationtool.impl.model.ProcessStepResult;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.reportInput.CreateReportInput;
import de.kosit.validationtool.model.reportInput.ProcessingError;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import de.kosit.validationtool.model.xvrl.XVRLMetadata;
import de.kosit.validationtool.model.xvrl.XVRLReport;
import de.kosit.validationtool.model.xvrl.XVRLReportSummary;
import lombok.AccessLevel;
Expand All @@ -31,10 +33,8 @@
import net.sf.saxon.s9api.XdmNode;
import org.apache.commons.io.FilenameUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

/**
* Interface, welches von allen Prüfschritten implementiert wird. Der Parameter vom Typ {@link Process} dient dabei
Expand All @@ -51,11 +51,11 @@ public interface CheckAction {
*/
@Getter
@Setter
class Process {
class Process<C extends CheckAction, T, E> {

private XVRLReportSummary xvrlReportSummary;
private XVRLMetadata metadata;

private Map<Class<? extends CheckAction>, XVRLReport> xvrlReportMap = new HashMap<>();
private List<ProcessStepResult<C, T, E>> processStepResults = new ArrayList<>();

/** Das finale XVRL Ergebnis */
private XdmNode xvrlFinalReport;
Expand Down Expand Up @@ -84,29 +84,47 @@ class Process {
private Result<Boolean, XMLSyntaxError> schemaValidationResult;

public Process(final Input input) {
this(input, new CreateReportInput(), new XVRLReportSummary());
this(input, new CreateReportInput(), new XVRLMetadata());
}

public Process(final Input input, final CreateReportInput reportInput, final XVRLReportSummary xvrlXvrlReportSummary) {
public Process(final Input input, final CreateReportInput reportInput, final XVRLMetadata xvrlMetadata) {
this.input = input;
this.reportInput = reportInput;
this.xvrlReportSummary = xvrlXvrlReportSummary;
this.metadata = xvrlMetadata;
}

public void addReport(final Class<? extends CheckAction> callingAction, final XVRLReport xvrlReport) {
if (xvrlReportMap.get(callingAction) == null) {
xvrlReportMap.put(callingAction, xvrlReport);
xvrlReportSummary.getReports().add(xvrlReport);

Optional<ProcessStepResult<C, T, E>> optional = this.processStepResults.stream().filter(b -> b.getType().equals(callingAction))
.findFirst();

ProcessStepResult<C, T, E> processStepResult;
if (optional.isPresent()) {
processStepResult = optional.get();
processStepResult.setReport(xvrlReport);
} else {
processStepResult = new ProcessStepResult<>();
processStepResult.setType((Class<C>) callingAction);
processStepResult.setReport(xvrlReport);
this.processStepResults.add(processStepResult);
}
}

public XVRLReport getReport(final Class<? extends CheckAction> callingAction) {
XVRLReport xvrlReport = xvrlReportMap.get(callingAction);
if (xvrlReport == null) {
xvrlReport = new XVRLReport();
addReport(callingAction, xvrlReport);
}
return xvrlReport;
return this.processStepResults.stream().filter(b -> b.getType().equals(callingAction)).findFirst()
.orElseThrow(IllegalArgumentException::new).getReport();
}

public XVRLReportSummary getXvrlReportSummary() {
final XVRLReportSummary summary = new XVRLReportSummary();
summary.setMetadata(metadata);
summary.getReports().addAll(processStepResults.stream().map(ProcessStepResult::getReport).collect(Collectors.toList()));
return summary;
}

public Result<T, E> getResult(final Class<C> type) {
return this.processStepResults.stream().filter(b -> b.getType().equals(type)).findFirst()
.orElseThrow(IllegalArgumentException::new).getResult();
}

/**
Expand Down Expand Up @@ -144,7 +162,7 @@ public String getName() {
*
* @param results die Informationssammlung
*/
void check(Process results);
void check(Process<?, ?, ?> results);

/**
* Ermittlung, ob ein Schritt u.U. ausgelassen werden kann. Die Funktion wird vor der eigentlichen Prüfaktion
Expand All @@ -154,7 +172,7 @@ public String getName() {
* @param results die bisher gesammelten Information
* @return <code>true</code> wenn der Schritt ausgelassen werden soll
*/
default boolean isSkipped(final Process results) {
default boolean isSkipped(final Process<?, ?, ?> results) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class ComputeAcceptanceAction implements CheckAction {

@Override
public void check(final Process results) {
public void check(final Process<?, ?, ?> results) {
if (results.isStopped() && results.getParserResult().isValid()) {
// xml wurde aus irgendwelchen Gründen nicht korrekt verarbeitet, dann lassen wir es als undefined
return;
Expand All @@ -56,24 +56,24 @@ public void check(final Process results) {
}
}

private void evaluateSchemaAndSchematron(final Process results) {
private void evaluateSchemaAndSchematron(final Process<?, ?, ?> results) {
if (results.getSchemaValidationResult().isValid() && isSchematronValid(results)) {
results.setAcceptStatus(AcceptRecommendation.ACCEPTABLE);
} else {
results.setAcceptStatus(AcceptRecommendation.REJECT);
}
}

private static boolean isSchematronValid(final Process results) {
private static boolean isSchematronValid(final Process<?, ?, ?> results) {
return !hasSchematronErrors(results);
}

private static boolean hasSchematronErrors(final Process results) {
private static boolean hasSchematronErrors(final Process<?, ?, ?> results) {
return results.getReportInput().getValidationResultsSchematron().stream().map(e -> e.getResults().getSchematronOutput())
.flatMap(e -> e.getActivePatternAndFiredRuleAndFailedAssert().stream()).anyMatch(FailedAssert.class::isInstance);
}

private static void evaluateAcceptanceMatch(final Process results, final XPathSelector selector) {
private static void evaluateAcceptanceMatch(final Process<?, ?, ?> results, final XPathSelector selector) {
try {
selector.setContextItem(results.getReport());
results.setAcceptStatus(selector.effectiveBooleanValue() ? AcceptRecommendation.ACCEPTABLE : AcceptRecommendation.REJECT);
Expand All @@ -84,7 +84,7 @@ private static void evaluateAcceptanceMatch(final Process results, final XPathSe
}
}

private static boolean preCondtionsMatch(final Process results) {
private static boolean preCondtionsMatch(final Process<?, ?, ?> results) {
return results.getReport() != null && results.getSchemaValidationResult() != null && results.getScenarioSelectionResult() != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class CreateDocumentIdentificationAction implements CheckAction {

@Override
public void check(final Process transporter) {
public void check(final Process<?, ?, ?> transporter) {
final DocumentIdentificationType i = new DocumentIdentificationType();
final DocumentIdentificationType.DocumentHash h = new DocumentIdentificationType.DocumentHash();
h.setHashAlgorithm(transporter.getInput().getDigestAlgorithm());
Expand All @@ -39,7 +39,7 @@ public void check(final Process transporter) {
addDocumentIdentification(transporter);
}

private void addDocumentIdentification(Process transporter) {
private void addDocumentIdentification(Process<?, ?, ?> transporter) {
XVRLMetadata metadata = transporter.getXvrlReportSummary().getMetadata();
Document document = new Document();
document.setHref(transporter.getInput().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static XsltExecutable loadFromScenario(final Scenario object) {
}

@Override
public void check(final Process results) {
public void check(final Process<?, ?, ?> results) {
final DocumentBuilder documentBuilder = this.processor.newDocumentBuilder();
try {

Expand Down Expand Up @@ -223,7 +223,7 @@ private XdmNode createErrorInformation(final Collection<XMLSyntaxError> errors)
return contentHandler.getDocumentNode();
}

private static XsltExecutable getTransformation(final Process results) {
private static XsltExecutable getTransformation(final Process<?, ?, ?> results) {
return loadFromScenario(results.getScenarioSelectionResult().getObject());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static XsltExecutable loadFromScenario(final Scenario object) {
}

@Override
public void check(final Process results) {
public void check(final Process<?, ?, ?> results) {
final DocumentBuilder documentBuilder = this.processor.newDocumentBuilder();
try {

Expand Down Expand Up @@ -203,7 +203,7 @@ private XdmNode createErrorInformation(final Collection<XMLSyntaxError> errors)
return contentHandler.getDocumentNode();
}

private static XsltExecutable getTransformation(final Process results) {
private static XsltExecutable getTransformation(final Process<?, ?, ?> results) {
return loadFromScenario(results.getScenarioSelectionResult().getObject());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private boolean hasCompatibleConfiguration(final XdmNodeInput content) {
}

@Override
public void check(final Process results) {
public void check(final Process<?, ?, ?> results) {
final Result<XdmNode, XMLSyntaxError> parserResult = parseDocument(results.getInput());
final ValidationResultsWellformedness v = new ValidationResultsWellformedness();
results.setParserResult(parserResult);
Expand All @@ -103,7 +103,7 @@ public void check(final Process results) {
generateXVRLReport(results, parserResult);
}

private void generateXVRLReport(final Process results, final Result<XdmNode, XMLSyntaxError> parserResult) {
private void generateXVRLReport(final Process<?, ?, ?> results, final Result<XdmNode, XMLSyntaxError> parserResult) {
XVRLReport xvrlReport = new XVRLReport();

XVRLMetadata reportMetadata = new XVRLMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ScenarioSelectionAction implements CheckAction {
private final ScenarioRepository repository;

@Override
public void check(final Process results) {
public void check(final Process<?, ?, ?> results) {
final CreateReportInput report = results.getReportInput();
final Result<Scenario, String> scenarioTypeResult;

Expand All @@ -59,7 +59,7 @@ public void check(final Process results) {
generateXVRLReport(results, scenarioTypeResult);
}

private void generateXVRLReport(Process results, Result<Scenario, String> scenarioTypeResult) {
private void generateXVRLReport(Process<?, ?, ?> results, Result<Scenario, String> scenarioTypeResult) {
XVRLReport xvrlReport = new XVRLReport();

XVRLMetadata reportMetadata = new XVRLMetadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public InputStream openStream() throws IOException {
@Getter
private long inMemoryLimit = Long.parseLong(System.getProperty(LIMIT_PARAMETER, BA_LIMIT.toString())) * FileUtils.ONE_MB;

private Result<Boolean, XMLSyntaxError> validate(final Process results, final Scenario scenario) {
private Result<Boolean, XMLSyntaxError> validate(final Process<?, ?, ?> results, final Scenario scenario) {
log.debug("Validating document using scenario {}", scenario.getConfiguration().getName());
final CollectingErrorEventHandler errorHandler = new CollectingErrorEventHandler();
try ( final SourceProvider validateInput = resolveSource(results) ) {
Expand All @@ -165,7 +165,7 @@ private Result<Boolean, XMLSyntaxError> validate(final Process results, final Sc
}

@Override
public void check(final Process results) {
public void check(final Process<?, ?, ?> results) {
final CreateReportInput report = results.getReportInput();
final Scenario scenario = results.getScenarioSelectionResult().getObject();

Expand All @@ -181,7 +181,7 @@ public void check(final Process results) {
generateXVRLReport(results, result);
}

private void generateXVRLReport(Process results, ValidationResultsXmlSchema result) {
private void generateXVRLReport(Process<?, ?, ?> results, ValidationResultsXmlSchema result) {
XVRLReport xvrlReport = new XVRLReport();

XVRLMetadata reportMetadata = new XVRLMetadata();
Expand Down Expand Up @@ -220,7 +220,7 @@ private void generateXVRLReport(Process results, ValidationResultsXmlSchema resu
results.addReport(this.getClass(), xvrlReport);
}

private SourceProvider resolveSource(final Process results) throws IOException, SaxonApiException {
private SourceProvider resolveSource(final Process<?, ?, ?> results) throws IOException, SaxonApiException {
final SourceProvider source;
if (results.getInput() instanceof AbstractInput && (((AbstractInput) results.getInput()).supportsMultipleReads())) {
source = () -> results.getInput().getSource();
Expand All @@ -245,11 +245,11 @@ private SerializedDocument serialize(final Input input, final XdmNode object) th
}

@Override
public boolean isSkipped(final Process results) {
public boolean isSkipped(final Process<?, ?, ?> results) {
return hasNoSchema(results);
}

private static boolean hasNoSchema(final Process results) {
private static boolean hasNoSchema(final Process<?, ?, ?> results) {
return results.getScenarioSelectionResult() == null || results.getScenarioSelectionResult().getObject().getSchema() == null;
}

Expand Down
Loading

0 comments on commit e3ae4f2

Please sign in to comment.