-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#79 Actions generate XVRL output (WiP)
- Loading branch information
Mohamed Maza
committed
Jun 2, 2021
1 parent
35129b9
commit 89c1485
Showing
21 changed files
with
774 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
src/main/java/de/kosit/validationtool/impl/XVRLResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* 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; | ||
|
||
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; | ||
import lombok.Setter; | ||
import net.sf.saxon.dom.NodeOverNodeInfo; | ||
import net.sf.saxon.s9api.XdmNode; | ||
import org.oclc.purl.dsdl.svrl.FailedAssert; | ||
import org.oclc.purl.dsdl.svrl.SchematronOutput; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class XVRLResult implements Result { | ||
|
||
/** Der generierte Report. */ | ||
@Getter | ||
private final XdmNode report; | ||
|
||
/** Die vom Validator erstelle interne Berichts-'Vorstufe' */ | ||
@Getter | ||
@Setter(AccessLevel.PACKAGE) | ||
private XVRLReportSummary reportSummary; | ||
|
||
/** Das evaluierte Ergebnis. */ | ||
@Getter | ||
private final AcceptRecommendation acceptRecommendation; | ||
|
||
private final HtmlExtractor htmlExtraction; | ||
|
||
@Setter(AccessLevel.PACKAGE) | ||
@Getter | ||
private List<XmlError> schemaViolations; | ||
|
||
@Getter | ||
@Setter(AccessLevel.PACKAGE) | ||
private List<SchematronOutput> schematronResult; | ||
|
||
@Getter | ||
@Setter | ||
private boolean processingSuccessful; | ||
|
||
@Getter | ||
@Setter | ||
private boolean wellformed; | ||
|
||
public XVRLResult(final XdmNode report, final AcceptRecommendation recommendation, final HtmlExtractor htmlExtractor) { | ||
this.report = report; | ||
this.acceptRecommendation = recommendation; | ||
this.htmlExtraction = htmlExtractor; | ||
} | ||
|
||
@Override | ||
public List<String> getProcessingErrors() { | ||
return XVRLUtil.getAllErrors(reportSummary); | ||
} | ||
|
||
/** | ||
* Gibt den Report als W3C-{@link Document} zurück. | ||
* | ||
* @return der Report | ||
*/ | ||
@Override | ||
public Document getReportDocument() { | ||
return (Document) NodeOverNodeInfo.wrap(getReport().getUnderlyingNode()); | ||
} | ||
|
||
/** | ||
* Schnellzugriff auf die Empfehlung zur Weiterverarbeitung des Dokuments. | ||
* | ||
* @return true wenn {@link AcceptRecommendation#ACCEPTABLE} | ||
*/ | ||
@Override | ||
public boolean isAcceptable() { | ||
return isProcessingSuccessful() && AcceptRecommendation.ACCEPTABLE.equals(this.acceptRecommendation); | ||
} | ||
|
||
@Override | ||
public boolean isSchemaValid() { | ||
return getSchemaViolations() != null && getSchemaViolations().isEmpty(); | ||
} | ||
|
||
/** | ||
* Extrahiert evtl. im Report vorhandene HTML-Fragmente als String. | ||
* | ||
* @return Liste mit HTML Strings. | ||
*/ | ||
public List<String> extractHtmlAsString() { | ||
return this.htmlExtraction.extractAsString(getReport()); | ||
} | ||
|
||
/** | ||
* Extrahiert evtl. im Report vorhandene HTML-Fragmente. | ||
* | ||
* @return Liste mit HTML Nodes. | ||
*/ | ||
public List<XdmNode> extractHtml() { | ||
return this.htmlExtraction.extract(getReport()); | ||
} | ||
|
||
/** | ||
* Extrahiert evtl. im Report vorhandene HTML-Fragmente als {@link Element}. | ||
* | ||
* @return Liste mit HTML Elementen. | ||
*/ | ||
public List<Element> extractHtmlAsElement() { | ||
return this.htmlExtraction.extractAsElement(getReport()); | ||
} | ||
|
||
/** | ||
* Gibt alle Schematron-Ergebnisse vom Typ {@link FailedAssert} zurück. | ||
* | ||
* @return die {@link FailedAssert} | ||
*/ | ||
@Override | ||
public List<FailedAssert> getFailedAsserts() { | ||
return getSchematronResult() != null | ||
? getSchematronResult().stream().flatMap(e -> e.getActivePatternAndFiredRuleAndFailedAssert().stream()) | ||
.filter(FailedAssert.class::isInstance).map(FailedAssert.class::cast).collect(Collectors.toList()) | ||
: Collections.emptyList(); | ||
} | ||
|
||
private boolean isSchematronEvaluated() { | ||
return getSchematronResult() != null | ||
&& getSchematronResult().stream().noneMatch(e -> e.getActivePatternAndFiredRuleAndFailedAssert().isEmpty()); | ||
} | ||
|
||
@Override | ||
public boolean isSchematronValid() { | ||
return isSchematronEvaluated() && getFailedAsserts().isEmpty(); | ||
} | ||
} |
Oops, something went wrong.