#21 Umsetzung der API Rückgabe, erste version

This commit is contained in:
Andreas Penski (init) 2019-05-17 11:21:22 +02:00 committed by Andreas Penski
parent a424fbbcfe
commit ab31ed71b1
21 changed files with 532 additions and 147 deletions

View file

@ -0,0 +1,21 @@
package de.kosit.validationtool.api;
/**
* Status der Empfehlung.
*/
public enum AcceptRecommendation {
/**
* Nicht definiert, weil eine Evaluierung nicht durchgeführt wurde, oder nicht durchgeführt werden konnte.
*/
UNDEFINED,
/**
* Das Dokument ist gemäß Konfiguration valide und kann akzeptiert werden.
*/
ACCEPTABLE,
/**
* Das Dokuemnt ist gemäß Konfiguration invalide und sollte NICHT akzeptiert werden.
*/
REJECT
}

View file

@ -24,9 +24,6 @@ import java.util.stream.Collectors;
import org.w3c.dom.Document;
import net.sf.saxon.dom.NodeOverNodeInfo;
import net.sf.saxon.s9api.XdmNode;
/**
* Zentrale Schnittstellendefinition für das Prüf-Tool.
@ -42,10 +39,10 @@ public interface Check {
* @param input die Resource / XML-Datei, die geprüft werden soll.
* @return ein Ergebnis-{@link Document} (readonly)
*/
default Document check(Input input) {
final XdmNode node = checkInput(input);
default Document check(final Input input) {
final Result result = checkInput(input);
// readonly view of the document!!!
return (Document) NodeOverNodeInfo.wrap(node.getUnderlyingNode());
return result.getReportDocument();
}
/**
@ -54,7 +51,7 @@ public interface Check {
* @param input die Resource / XML-Datei, die geprüft werden soll.
* @return ein Ergebnis-{@link Document}
*/
XdmNode checkInput(Input input);
Result checkInput(Input input);
/**
* Führt eine Prüfung im Batch-Mode durch. Die Default-Implementierung führt die Prüfung sequentiell aus. Die Ergebnis
@ -63,7 +60,7 @@ public interface Check {
* @param input die Eingabe
* @return Liste mit Ergebnis-Dokumenten (readonly)
*/
default List<Document> check(List<Input> input) {
default List<Document> check(final List<Input> input) {
return input.stream().map(this::check).collect(Collectors.toList());
}
@ -73,8 +70,9 @@ public interface Check {
* @param input die Eingabe
* @return Liste mit Ergebnis-Dokumenten
*/
default List<XdmNode> checkInput(List<Input> input) {
default List<Result> checkInput(final List<Input> input) {
return input.stream().map(this::checkInput).collect(Collectors.toList());
}
}

View file

@ -0,0 +1,44 @@
package de.kosit.validationtool.api;
import org.w3c.dom.Document;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.sf.saxon.dom.NodeOverNodeInfo;
import net.sf.saxon.s9api.XdmNode;
/**
* API Rückgabe Objekt des Ergebnisses des Validierungsprozesses.
*
* @author Andreas Penski
*/
@Getter
@RequiredArgsConstructor
public class Result {
/** Der generierte Report. */
private final XdmNode report;
/** Das evaluierte Ergebnis. */
private final AcceptRecommendation acceptRecommendation;
/**
* Gibt den Report als W3C-{@link Document} zurück.
*
* @return der Report
*/
public Document getReportDocument() {
return (Document) NodeOverNodeInfo.wrap(getReport().getUnderlyingNode());
}
/**
* Schnellzugriff auf die Empfehlung zur Weiterverarbeitung des Dokuments.
*
* @return true wenn {@link AcceptRecommendation#ACCEPTABLE}
*/
public boolean isAcceptable() {
return AcceptRecommendation.ACCEPTABLE.equals(acceptRecommendation);
}
}