Skip to content

Commit 9b56a57

Browse files
author
Mohamed Maza
committed
#79 Refactored to remove Util class
1 parent 8aeaf6c commit 9b56a57

13 files changed

+236
-195
lines changed

Diff for: src/main/java/de/kosit/validationtool/impl/DefaultCheck.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.stream.Collectors;
2727

2828
import de.kosit.validationtool.impl.tasks.*;
29-
import de.kosit.validationtool.impl.xvrl.XVRLUtil;
3029
import de.kosit.validationtool.impl.xvrl.XmlErrorImpl;
3130
import de.kosit.validationtool.model.xvrl.*;
3231
import lombok.Getter;
@@ -87,7 +86,6 @@ public DefaultCheck(final Processor processor, final Configuration... configurat
8786
this.checkSteps.add(new SchemaValidationAction(processor));
8887
this.checkSteps.add(new SchematronValidationAction(this.conversionService));
8988
this.checkSteps.add(new ValidateReportInputAction(this.conversionService, SchemaProvider.getReportInputSchema()));
90-
this.checkSteps.add(new ValidateXVRLReportSummaryAction(this.conversionService, SchemaProvider.getXVRLSchema()));
9189
this.checkSteps.add(new CreateReportAction(processor, this.conversionService));
9290
this.checkSteps.add(new ComputeAcceptanceAction());
9391
}
@@ -142,7 +140,7 @@ protected Result runCheckInternal(final Process checkProcess) {
142140
checkProcess.setFinished(true);
143141
log.info("Finished check of {} in {}ms\n", checkProcess.getInput().getName(), System.currentTimeMillis() - started);
144142
Result result = createResult(checkProcess);
145-
Result xvrlResult = createXVRLResult(checkProcess);
143+
createXVRLResult(checkProcess);
146144
return result;
147145
}
148146

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

170168
xvrlResult.setReportSummary(process.getXvrlReportSummary());
171-
xvrlResult.setSchemaViolations(convertErrorsFromXVRLDetections(XVRLUtil.getAllErrorDetections(process.getXvrlReportSummary())));
169+
xvrlResult.setSchemaViolations(convertErrorsFromXVRLDetections(process.getXvrlReportSummary().getAllErrorDetections()));
172170

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

175-
// TODO MM add SchematronResult
176-
// XVRLReport schematronValidationReport = process.getReport(SchematronValidationAction.class);
177-
// xvrlResult.setSchematronResult(t.getReportInput().getValidationResultsSchematron().stream()
178-
// .filter(e -> e.getResults() != null).map(e ->
179-
// e.getResults().getSchematronOutput()).collect(Collectors.toList()));
180-
181173
return xvrlResult;
182174
}
183175

Diff for: src/main/java/de/kosit/validationtool/impl/XVRLResult.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
import de.kosit.validationtool.api.AcceptRecommendation;
2020
import de.kosit.validationtool.api.Result;
2121
import de.kosit.validationtool.api.XmlError;
22-
import de.kosit.validationtool.impl.HtmlExtractor;
23-
import de.kosit.validationtool.impl.xvrl.XVRLUtil;
24-
import de.kosit.validationtool.model.reportInput.CreateReportInput;
2522
import de.kosit.validationtool.model.xvrl.XVRLReportSummary;
2623
import lombok.AccessLevel;
2724
import lombok.Getter;
@@ -78,7 +75,7 @@ public XVRLResult(final XdmNode report, final AcceptRecommendation recommendatio
7875

7976
@Override
8077
public List<String> getProcessingErrors() {
81-
return XVRLUtil.getAllErrors(reportSummary);
78+
return reportSummary.getAllErrors();
8279
}
8380

8481
/**

Diff for: src/main/java/de/kosit/validationtool/impl/tasks/DocumentParseAction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collections;
2222
import java.util.stream.Collectors;
2323

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

129-
XVRLUtil.addErrorDetectionsFromXMLSyntaxErrors(xvrlReport, parserResult.getErrors());
128+
xvrlReport.addErrorDetectionsFromXMLSyntaxErrors(parserResult.getErrors());
130129
}
131130
xvrlDigest.setValid(valid);
132131
xvrlReport.setDigest(xvrlDigest);

Diff for: src/main/java/de/kosit/validationtool/impl/tasks/ScenarioSelectionAction.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package de.kosit.validationtool.impl.tasks;
1818

19-
import de.kosit.validationtool.impl.xvrl.XVRLUtil;
2019
import de.kosit.validationtool.model.xvrl.*;
2120
import lombok.RequiredArgsConstructor;
2221
import lombok.extern.slf4j.Slf4j;
@@ -75,12 +74,11 @@ private void generateXVRLReport(Process results, Result<Scenario, String> scenar
7574
if (scenarioTypeResult.getObject().isFallback()) {
7675
valid = "false";
7776
xvrlDetection.setSeverity(XVRLDetection.Severity.ERROR);
78-
XVRLUtil.addMessageString(xvrlDetection,
79-
String.format("No valid scenario configuration found for %s", results.getInput().getName()));
77+
xvrlDetection.addMessageString(String.format("No valid scenario configuration found for %s", results.getInput().getName()));
8078
} else {
8179
xvrlDetection.setCode("scenario-matched");
8280
xvrlDetection.setSeverity(XVRLDetection.Severity.INFO);
83-
XVRLUtil.addMessageString(xvrlDetection,
81+
xvrlDetection.addMessageString(
8482
String.format("Scenario %s identified for %s", scenarioTypeResult.getObject().getName(), results.getInput().getName()));
8583
}
8684
xvrlDigest.setValid(valid);

Diff for: src/main/java/de/kosit/validationtool/impl/tasks/SchemaValidationAction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import javax.xml.transform.stream.StreamSource;
3232
import javax.xml.validation.Validator;
3333

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

216-
XVRLUtil.addErrorDetectionsFromXMLSyntaxErrors(xvrlReport, result.getXmlSyntaxError());
215+
xvrlReport.addErrorDetectionsFromXMLSyntaxErrors(result.getXmlSyntaxError());
217216
}
218217
xvrlDigest.setValid(valid);
219218
xvrlReport.setDigest(xvrlDigest);

Diff for: src/main/java/de/kosit/validationtool/impl/tasks/SchematronValidationAction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import javax.xml.transform.dom.DOMSource;
2525

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

131-
XVRLUtil.addErrorDetectionsFromFailedAsserts(xvrlReport, output.getFailedAsserts());
130+
xvrlReport.addErrorDetectionsFromFailedAsserts(output.getFailedAsserts());
132131
});
133132
reportMetadata.getSchemas().addAll(schemaList);
134133
xvrlReport.setMetadata(reportMetadata);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2017-2021 Koordinierungsstelle für IT-Standards (KoSIT)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.kosit.validationtool.impl.xvrl;
18+
19+
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
20+
import de.kosit.validationtool.model.xvrl.Location;
21+
import de.kosit.validationtool.model.xvrl.XVRLDetection;
22+
import de.kosit.validationtool.model.xvrl.XVRLMessage;
23+
24+
import java.math.BigInteger;
25+
import java.util.List;
26+
import java.util.stream.Collectors;
27+
28+
import static de.kosit.validationtool.api.XmlError.Severity.SEVERITY_FATAL_ERROR;
29+
30+
public interface BaseDetection {
31+
32+
List<XVRLMessage> getMessages();
33+
34+
List<Location> getLocations();
35+
36+
XVRLDetection.Severity getSeverity();
37+
38+
void setSeverity(XVRLDetection.Severity value);
39+
40+
default List<String> getAllMessages() {
41+
return getMessages().stream().flatMap(message -> message.getMessageStrings().stream()).collect(Collectors.toList());
42+
}
43+
44+
default String getErrorMessage() {
45+
if (getMessages().isEmpty()) {
46+
return null;
47+
}
48+
return getMessages().get(0).getContent().stream().map(Object::toString).collect(Collectors.joining());
49+
}
50+
51+
default Location getErrorLocation() {
52+
if (getLocations().isEmpty()) {
53+
return null;
54+
}
55+
return getLocations().get(0);
56+
}
57+
58+
default boolean hasErrors() {
59+
return getSeverity() == XVRLDetection.Severity.ERROR || getSeverity() == XVRLDetection.Severity.FATAL_ERROR;
60+
}
61+
62+
default void addMessageString(String message) {
63+
XVRLMessage messageObject = new XVRLMessage();
64+
messageObject.getContent().add(message);
65+
getMessages().add(messageObject);
66+
}
67+
68+
default void addLocation(int lineNumber, int columnNumber, String xpath) {
69+
Location location = new Location();
70+
location.setLine(BigInteger.valueOf(lineNumber));
71+
location.setColumn(BigInteger.valueOf(columnNumber));
72+
location.setXpath(xpath);
73+
getLocations().add(location);
74+
}
75+
76+
default void addSeverityFromXmlError(XMLSyntaxError xmlSyntaxError) {
77+
if (xmlSyntaxError.getSeverity() == SEVERITY_FATAL_ERROR) {
78+
setSeverity(XVRLDetection.Severity.FATAL_ERROR);
79+
} else {
80+
setSeverity(XVRLDetection.Severity.ERROR);
81+
}
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2017-2021 Koordinierungsstelle für IT-Standards (KoSIT)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.kosit.validationtool.impl.xvrl;
18+
19+
import java.util.List;
20+
import java.util.stream.Collectors;
21+
22+
public interface BaseMessage {
23+
24+
List<Object> getContent();
25+
26+
default List<String> getMessageStrings() {
27+
return getContent().stream().map(Object::toString).collect(Collectors.toList());
28+
}
29+
}

Diff for: src/main/java/de/kosit/validationtool/impl/xvrl/BaseReport.java

+57-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,61 @@
1616

1717
package de.kosit.validationtool.impl.xvrl;
1818

19-
public class BaseReport {
19+
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
20+
import de.kosit.validationtool.model.xvrl.XVRLDetection;
21+
import org.oclc.purl.dsdl.svrl.FailedAssert;
22+
23+
import java.util.ArrayList;
24+
import java.util.Collection;
25+
import java.util.List;
26+
import java.util.stream.Collectors;
27+
28+
public interface BaseReport {
29+
30+
List<XVRLDetection> getDetection();
31+
32+
default List<String> getAllErrors() {
33+
return getDetection().stream().filter(BaseDetection::hasErrors).flatMap(xvrlDetection -> xvrlDetection.getAllMessages().stream())
34+
.collect(Collectors.toList());
35+
}
36+
37+
default List<XVRLDetection> getAllErrorDetections() {
38+
return getDetection().stream().filter(BaseDetection::hasErrors).collect(Collectors.toList());
39+
}
40+
41+
default void addErrorDetectionsFromXMLSyntaxErrors(Collection<XMLSyntaxError> errors) {
42+
if (errors == null) {
43+
return;
44+
}
45+
List<XVRLDetection> xvrlDetectionList = new ArrayList<>(errors.size());
46+
errors.forEach(xmlSyntaxError -> {
47+
XVRLDetection xvrlDetection = new XVRLDetection();
48+
xvrlDetection.addSeverityFromXmlError(xmlSyntaxError);
49+
xvrlDetection.addMessageString(xmlSyntaxError.getMessage());
50+
if (xmlSyntaxError.getRowNumber() != null && xmlSyntaxError.getColumnNumber() != null) {
51+
xvrlDetection.addLocation(xmlSyntaxError.getRowNumber(), xmlSyntaxError.getColumnNumber(), null);
52+
}
53+
xvrlDetectionList.add(xvrlDetection);
54+
});
55+
getDetection().addAll(xvrlDetectionList);
56+
}
57+
58+
default void addErrorDetectionsFromFailedAsserts(List<FailedAssert> failedAsserts) {
59+
if (failedAsserts == null) {
60+
return;
61+
}
62+
List<XVRLDetection> xvrlDetectionList = new ArrayList<>(failedAsserts.size());
63+
failedAsserts.forEach(failedAssert -> {
64+
XVRLDetection xvrlDetection = new XVRLDetection();
65+
xvrlDetection.setSeverity(XVRLDetection.Severity.ERROR);
66+
xvrlDetection.addMessageString(getFailedAssertMessage(failedAssert));
67+
xvrlDetection.addLocation(0, 0, failedAssert.getLocation());
68+
xvrlDetectionList.add(xvrlDetection);
69+
});
70+
getDetection().addAll(xvrlDetectionList);
71+
}
72+
73+
default String getFailedAssertMessage(FailedAssert failedAssert) {
74+
return failedAssert.getText().getContent().stream().map(Object::toString).collect(Collectors.joining());
75+
}
2076
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2017-2021 Koordinierungsstelle für IT-Standards (KoSIT)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.kosit.validationtool.impl.xvrl;
18+
19+
import de.kosit.validationtool.model.xvrl.XVRLDetection;
20+
import de.kosit.validationtool.model.xvrl.XVRLReport;
21+
22+
import java.util.List;
23+
import java.util.stream.Collectors;
24+
25+
public interface BaseReportSummary {
26+
27+
List<XVRLReport> getReports();
28+
29+
default List<String> getAllErrors() {
30+
return getReports().stream().flatMap(xvrlReport -> xvrlReport.getAllErrors().stream()).collect(Collectors.toList());
31+
}
32+
33+
default List<XVRLDetection> getAllErrorDetections() {
34+
return getReports().stream().flatMap(xvrlReport -> xvrlReport.getAllErrorDetections().stream()).collect(Collectors.toList());
35+
}
36+
}

0 commit comments

Comments
 (0)