mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
Moved validation tool one level up, as it is now the sole content of this repository
This commit is contained in:
parent
7383efd257
commit
9ad51731ab
97 changed files with 260 additions and 315 deletions
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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.model;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.xml.validation.Schema;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.ScenarioRepository;
|
||||
import de.kosit.validationtool.model.scenarios.*;
|
||||
|
||||
import net.sf.saxon.s9api.XPathExecutable;
|
||||
import net.sf.saxon.s9api.XPathSelector;
|
||||
import net.sf.saxon.s9api.XsltExecutable;
|
||||
|
||||
/**
|
||||
* Eine Basis-Klasse für Szenarien. Wiederverwendbare Objekte mit Bezug zum Szenario werden hier gecached. Die Klasse
|
||||
* stellt im eigentlichen Sinne eine Erweiterung der durch JAXB generierten Strukturen dar.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public abstract class BaseScenario {
|
||||
|
||||
private XPathExecutable xPathExecutable;
|
||||
|
||||
private Schema schema;
|
||||
|
||||
private List<Transformation> schematronValidations;
|
||||
|
||||
private ContentRepository repository;
|
||||
|
||||
private Transformation reportTransformation;
|
||||
|
||||
/**
|
||||
* Gibt eine Transformation zurück.
|
||||
* @return initialisierte Transformation
|
||||
*/
|
||||
public Transformation getReportTransformation() {
|
||||
if (reportTransformation == null) {
|
||||
final ResourceType resource = getCreateReport().getResource();
|
||||
final XsltExecutable executable = repository.loadXsltScript(URI.create(resource.getLocation()));
|
||||
reportTransformation = new Transformation(executable, resource);
|
||||
}
|
||||
return reportTransformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lieferrt das Schema zu diesem Szenario.
|
||||
* @return das passende Schema
|
||||
*/
|
||||
public Schema getSchema() {
|
||||
if (schema == null) {
|
||||
final List<String> schemaResources = getValidateWithXmlSchema().getResource().stream().map(r -> r.getLocation())
|
||||
.collect(Collectors.toList());
|
||||
schema = repository.createSchema(schemaResources);
|
||||
}
|
||||
return schema;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialisiert das Szenario auf Basis eines [@link ContentRepository}
|
||||
* @param repository das Repository mit den Szenario-Artefakten
|
||||
* @param lazy optionales lazy loading der XML-Artefakte
|
||||
* @return true wenn erfolgreich
|
||||
*/
|
||||
public boolean initialize(ContentRepository repository, boolean lazy) {
|
||||
this.repository = repository;
|
||||
if (!lazy) {
|
||||
getSchema();
|
||||
getSelector();
|
||||
getSchematronValidations();
|
||||
getReportTransformation();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefer eine Liste mit Schematron Validierungs-Transformationen
|
||||
* @return liste mit initialisierten Transformationsinformationen
|
||||
*/
|
||||
public List<Transformation> getSchematronValidations() {
|
||||
if (schematronValidations == null) {
|
||||
schematronValidations = new ArrayList<>();
|
||||
getValidateWithSchematron().forEach(v -> {
|
||||
if (v.isPsvi()) {
|
||||
throw new NotImplementedException("This implemenation does not support PSVI usage");
|
||||
}
|
||||
final XsltExecutable xsltExecutable = repository.loadXsltScript(URI.create(v.getResource().getLocation()));
|
||||
schematronValidations.add(new Transformation(xsltExecutable, v.getResource()));
|
||||
});
|
||||
}
|
||||
return schematronValidations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Der XPath-Selector zur Identifikation des Scenarios.
|
||||
*
|
||||
* @return vorbereiteten selector
|
||||
* @see {@link ScenarioRepository#selectScenario(Document)}.
|
||||
*/
|
||||
public XPathSelector getSelector() {
|
||||
if (xPathExecutable == null) {
|
||||
final Map<String, String> namespaces = getNamespace().stream().collect(Collectors.toMap(NamespaceType::getPrefix, NamespaceType::getValue));
|
||||
xPathExecutable = repository.createXPath(getMatch(), namespaces);
|
||||
}
|
||||
return xPathExecutable.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter aus dem schema.
|
||||
*
|
||||
* @return xpath match
|
||||
*/
|
||||
public abstract String getMatch();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema.
|
||||
*
|
||||
* @return {@link List} of {@link NamespaceType}
|
||||
*/
|
||||
public abstract List<NamespaceType> getNamespace();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema.
|
||||
*
|
||||
* @return Validierungsanweisungen
|
||||
*/
|
||||
public abstract ValidateWithXmlSchema getValidateWithXmlSchema();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema.
|
||||
*
|
||||
* @return Validierungsanweisungne
|
||||
*/
|
||||
public abstract List<ValidateWithSchematron> getValidateWithSchematron();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema.
|
||||
*
|
||||
* @return report informationen
|
||||
*/
|
||||
public abstract CreateReportType getCreateReport();
|
||||
|
||||
/**
|
||||
* Laufzeitinformationen über eine Transformation.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class Transformation {
|
||||
|
||||
private XsltExecutable executable;
|
||||
|
||||
private ResourceType resourceType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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.model;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxErrorSeverity;
|
||||
|
||||
/**
|
||||
* Basis-Klasse für Syntax-Error. Wird über die JAXB-generierte Klasse
|
||||
* {@link de.kosit.validationtool.model.reportInput.XMLSyntaxError} erweitert.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public abstract class BaseXMLSyntaxError {
|
||||
|
||||
/**
|
||||
* Logged den Syntax-Fehler über einen definierten Logger.
|
||||
*
|
||||
* @param logger der Logger
|
||||
*/
|
||||
public void log(Logger logger) {
|
||||
String msgTemplate = "{} At row {} at pos {}";
|
||||
Object[] params = { getMessage(), getRowNumber(), getColumnNumber() };
|
||||
if (getSeverity() == XMLSyntaxErrorSeverity.SEVERITY_WARNING) {
|
||||
logger.warn(msgTemplate, params);
|
||||
} else {
|
||||
logger.error(msgTemplate, params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s At row %s at pos %s", getMessage(), getRowNumber(), getColumnNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter aus dem schema
|
||||
*
|
||||
* @return Spalte des Fehlers
|
||||
*/
|
||||
public abstract Integer getColumnNumber();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema
|
||||
*
|
||||
* @return Zeile des Fehlers
|
||||
*/
|
||||
public abstract Integer getRowNumber();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema
|
||||
*
|
||||
* @return Fehlermeldung
|
||||
*/
|
||||
public abstract String getMessage();
|
||||
|
||||
/**
|
||||
* Getter aus dem schema
|
||||
*
|
||||
* @return severity
|
||||
*/
|
||||
public abstract XMLSyntaxErrorSeverity getSeverity();
|
||||
}
|
||||
80
src/main/java/de/kosit/validationtool/impl/model/Result.java
Normal file
80
src/main/java/de/kosit/validationtool/impl/model/Result.java
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Ein Ergebnisobjekte, dass das eigentliche Ergebnis hält und optional auch verschiedene Fehlerobjekte.
|
||||
*
|
||||
* @param <T> der Typ des Ergebnis-Objekts
|
||||
* @param <E> der Typ des Fehler-Objekts
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Result<T, E> {
|
||||
|
||||
private T object;
|
||||
|
||||
private Collection<E> errors = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Erzeugt ein neues Ergebnis mit Fehler
|
||||
*
|
||||
* @param errors die Fehler
|
||||
*/
|
||||
public Result(Collection<E> errors) {
|
||||
this(null, errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt ein neues Ergebnis mit einem Ergebnisobjekt
|
||||
*
|
||||
* @param o
|
||||
*/
|
||||
public Result(T o) {
|
||||
this(o, Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt an, ob das Ergebnis valide, also ohne Fehler ist.
|
||||
*
|
||||
* @return true wenn erfolgreich
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return object != null && errors.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeigt an, ob das Ergebnis nicht valide ist, als entsprechend Fehler gesammelt wurden.
|
||||
*
|
||||
* @return true wenn erfolgreich wenn Fehler vorhanden sind.
|
||||
*/
|
||||
public boolean isInvalid() {
|
||||
return !isValid();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue