Skip to content

Commit

Permalink
#79 Refactored to remove Util class
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Maza committed Jun 7, 2021
1 parent 8aeaf6c commit 9b56a57
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 195 deletions.
12 changes: 2 additions & 10 deletions src/main/java/de/kosit/validationtool/impl/DefaultCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.stream.Collectors;

import de.kosit.validationtool.impl.tasks.*;
import de.kosit.validationtool.impl.xvrl.XVRLUtil;
import de.kosit.validationtool.impl.xvrl.XmlErrorImpl;
import de.kosit.validationtool.model.xvrl.*;
import lombok.Getter;
Expand Down Expand Up @@ -87,7 +86,6 @@ public DefaultCheck(final Processor processor, final Configuration... configurat
this.checkSteps.add(new SchemaValidationAction(processor));
this.checkSteps.add(new SchematronValidationAction(this.conversionService));
this.checkSteps.add(new ValidateReportInputAction(this.conversionService, SchemaProvider.getReportInputSchema()));
this.checkSteps.add(new ValidateXVRLReportSummaryAction(this.conversionService, SchemaProvider.getXVRLSchema()));
this.checkSteps.add(new CreateReportAction(processor, this.conversionService));
this.checkSteps.add(new ComputeAcceptanceAction());
}
Expand Down Expand Up @@ -142,7 +140,7 @@ protected Result runCheckInternal(final Process checkProcess) {
checkProcess.setFinished(true);
log.info("Finished check of {} in {}ms\n", checkProcess.getInput().getName(), System.currentTimeMillis() - started);
Result result = createResult(checkProcess);
Result xvrlResult = createXVRLResult(checkProcess);
createXVRLResult(checkProcess);
return result;
}

Expand All @@ -168,16 +166,10 @@ private Result createXVRLResult(final Process process) {
xvrlResult.setWellformed("true".equals(parserReport.getDigest().getValid()));

xvrlResult.setReportSummary(process.getXvrlReportSummary());
xvrlResult.setSchemaViolations(convertErrorsFromXVRLDetections(XVRLUtil.getAllErrorDetections(process.getXvrlReportSummary())));
xvrlResult.setSchemaViolations(convertErrorsFromXVRLDetections(process.getXvrlReportSummary().getAllErrorDetections()));

xvrlResult.setProcessingSuccessful(!process.isStopped() && process.isFinished());

// TODO MM add SchematronResult
// XVRLReport schematronValidationReport = process.getReport(SchematronValidationAction.class);
// xvrlResult.setSchematronResult(t.getReportInput().getValidationResultsSchematron().stream()
// .filter(e -> e.getResults() != null).map(e ->
// e.getResults().getSchematronOutput()).collect(Collectors.toList()));

return xvrlResult;
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/de/kosit/validationtool/impl/XVRLResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
import de.kosit.validationtool.api.AcceptRecommendation;
import de.kosit.validationtool.api.Result;
import de.kosit.validationtool.api.XmlError;
import de.kosit.validationtool.impl.HtmlExtractor;
import de.kosit.validationtool.impl.xvrl.XVRLUtil;
import de.kosit.validationtool.model.reportInput.CreateReportInput;
import de.kosit.validationtool.model.xvrl.XVRLReportSummary;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -78,7 +75,7 @@ public XVRLResult(final XdmNode report, final AcceptRecommendation recommendatio

@Override
public List<String> getProcessingErrors() {
return XVRLUtil.getAllErrors(reportSummary);
return reportSummary.getAllErrors();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.stream.Collectors;

import de.kosit.validationtool.impl.xvrl.XVRLUtil;
import de.kosit.validationtool.model.xvrl.Validator;
import de.kosit.validationtool.model.xvrl.XVRLDigest;
import de.kosit.validationtool.model.xvrl.XVRLMetadata;
Expand Down Expand Up @@ -126,7 +125,7 @@ private void generateXVRLReport(final Process results, final Result<XdmNode, XML
.filter(xmlSyntaxError -> xmlSyntaxError.getSeverityCode() == XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR).count();
xvrlDigest.setFatalErrorCount(BigInteger.valueOf(fatalErrorCount));

XVRLUtil.addErrorDetectionsFromXMLSyntaxErrors(xvrlReport, parserResult.getErrors());
xvrlReport.addErrorDetectionsFromXMLSyntaxErrors(parserResult.getErrors());
}
xvrlDigest.setValid(valid);
xvrlReport.setDigest(xvrlDigest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package de.kosit.validationtool.impl.tasks;

import de.kosit.validationtool.impl.xvrl.XVRLUtil;
import de.kosit.validationtool.model.xvrl.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -75,12 +74,11 @@ private void generateXVRLReport(Process results, Result<Scenario, String> scenar
if (scenarioTypeResult.getObject().isFallback()) {
valid = "false";
xvrlDetection.setSeverity(XVRLDetection.Severity.ERROR);
XVRLUtil.addMessageString(xvrlDetection,
String.format("No valid scenario configuration found for %s", results.getInput().getName()));
xvrlDetection.addMessageString(String.format("No valid scenario configuration found for %s", results.getInput().getName()));
} else {
xvrlDetection.setCode("scenario-matched");
xvrlDetection.setSeverity(XVRLDetection.Severity.INFO);
XVRLUtil.addMessageString(xvrlDetection,
xvrlDetection.addMessageString(
String.format("Scenario %s identified for %s", scenarioTypeResult.getObject().getName(), results.getInput().getName()));
}
xvrlDigest.setValid(valid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Validator;

import de.kosit.validationtool.impl.xvrl.XVRLUtil;
import de.kosit.validationtool.model.reportInput.XMLSyntaxErrorSeverity;
import de.kosit.validationtool.model.xvrl.Schema;
import de.kosit.validationtool.model.xvrl.XVRLDigest;
Expand Down Expand Up @@ -213,7 +212,7 @@ private void generateXVRLReport(Process results, ValidationResultsXmlSchema resu
.filter(xmlSyntaxError -> xmlSyntaxError.getSeverityCode() == XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR).count();
xvrlDigest.setFatalErrorCount(BigInteger.valueOf(fatalErrorCount));

XVRLUtil.addErrorDetectionsFromXMLSyntaxErrors(xvrlReport, result.getXmlSyntaxError());
xvrlReport.addErrorDetectionsFromXMLSyntaxErrors(result.getXmlSyntaxError());
}
xvrlDigest.setValid(valid);
xvrlReport.setDigest(xvrlDigest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import javax.xml.transform.dom.DOMSource;

import de.kosit.validationtool.impl.xvrl.XVRLUtil;
import de.kosit.validationtool.model.scenarios.ResourceType;
import de.kosit.validationtool.model.xvrl.*;
import org.oclc.purl.dsdl.svrl.SchematronOutput;
Expand Down Expand Up @@ -128,7 +127,7 @@ private void generateXVRLReport(Process results, List<ValidationResultsSchematro
schema.setVersion(output.getSchemaVersion());
schemaList.add(schema);

XVRLUtil.addErrorDetectionsFromFailedAsserts(xvrlReport, output.getFailedAsserts());
xvrlReport.addErrorDetectionsFromFailedAsserts(output.getFailedAsserts());
});
reportMetadata.getSchemas().addAll(schemaList);
xvrlReport.setMetadata(reportMetadata);
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/de/kosit/validationtool/impl/xvrl/BaseDetection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 java.util.List;
import java.util.stream.Collectors;

import static de.kosit.validationtool.api.XmlError.Severity.SEVERITY_FATAL_ERROR;

public interface BaseDetection {

List<XVRLMessage> getMessages();

List<Location> getLocations();

XVRLDetection.Severity getSeverity();

void setSeverity(XVRLDetection.Severity value);

default List<String> getAllMessages() {
return getMessages().stream().flatMap(message -> message.getMessageStrings().stream()).collect(Collectors.toList());
}

default String getErrorMessage() {
if (getMessages().isEmpty()) {
return null;
}
return getMessages().get(0).getContent().stream().map(Object::toString).collect(Collectors.joining());
}

default Location getErrorLocation() {
if (getLocations().isEmpty()) {
return null;
}
return getLocations().get(0);
}

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);
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/de/kosit/validationtool/impl/xvrl/BaseMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.util.List;
import java.util.stream.Collectors;

public interface BaseMessage {

List<Object> getContent();

default List<String> getMessageStrings() {
return getContent().stream().map(Object::toString).collect(Collectors.toList());
}
}
58 changes: 57 additions & 1 deletion src/main/java/de/kosit/validationtool/impl/xvrl/BaseReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,61 @@

package de.kosit.validationtool.impl.xvrl;

public class BaseReport {
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;

public interface BaseReport {

List<XVRLDetection> getDetection();

default List<String> getAllErrors() {
return getDetection().stream().filter(BaseDetection::hasErrors).flatMap(xvrlDetection -> xvrlDetection.getAllMessages().stream())
.collect(Collectors.toList());
}

default List<XVRLDetection> getAllErrorDetections() {
return getDetection().stream().filter(BaseDetection::hasErrors).collect(Collectors.toList());
}

default void addErrorDetectionsFromXMLSyntaxErrors(Collection<XMLSyntaxError> errors) {
if (errors == null) {
return;
}
List<XVRLDetection> 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<FailedAssert> failedAsserts) {
if (failedAsserts == null) {
return;
}
List<XVRLDetection> 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.xvrl.XVRLDetection;
import de.kosit.validationtool.model.xvrl.XVRLReport;

import java.util.List;
import java.util.stream.Collectors;

public interface BaseReportSummary {

List<XVRLReport> getReports();

default List<String> getAllErrors() {
return getReports().stream().flatMap(xvrlReport -> xvrlReport.getAllErrors().stream()).collect(Collectors.toList());
}

default List<XVRLDetection> getAllErrorDetections() {
return getReports().stream().flatMap(xvrlReport -> xvrlReport.getAllErrorDetections().stream()).collect(Collectors.toList());
}
}
Loading

0 comments on commit 9b56a57

Please sign in to comment.