Commit 91403ce3 authored by Maxime Lefrançois's avatar Maxime Lefrançois

removed dependency any23

parent b2e5c160
......@@ -176,7 +176,7 @@
<version>11</version>
</dependency>
<dependency>
<!-- <dependency>
<groupId>org.apache.any23</groupId>
<artifactId>apache-any23-core</artifactId>
<version>2.0</version>
......@@ -186,7 +186,7 @@
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-api</artifactId>
<version>4.0.2</version>
</dependency>
</dependency> -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
......
......@@ -26,18 +26,28 @@
package fr.emse.gitlab.saref.checkers;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.stream.Collectors;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.DCTerms;
import org.apache.jena.vocabulary.RDF;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import fr.emse.gitlab.saref.SAREF;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.managers.GenerateRDFaManager;
import fr.emse.gitlab.saref.managers.RepositoryManager;
import fr.emse.gitlab.saref.utils.Languages;
import fr.emse.gitlab.saref.vocabs.VTC;
/**
* Checks TS 103 673 Clause 9.3: Ontology requirements
......@@ -48,7 +58,7 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
private static final String FIRST_LINE = "Id;Category;Requirement";
private static enum MESSAGE {
directories, csv, missing, ioexception, line;
missing, ioexception, line;
}
public Clause_9_3_Checker(RepositoryManager repositoryManager) {
......@@ -62,66 +72,48 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
return;
}
try {
checkExists(dir.toPath());
checkFirstLine(dir.toPath());
File file = new File(dir, "requirements.csv");
if (!file.exists()) {
logError(getMessage(MESSAGE.missing));
return;
}
List<String> lines = FileUtils.readLines(file, StandardCharsets.UTF_8);
if (lines.size() < 1 || !lines.get(0).equals(FIRST_LINE)) {
logError(getMessage(MESSAGE.line));
return;
}
readRequirements();
requirementsRDFaGenerator();
} catch (IOException ex) {
logError(getMessage(MESSAGE.ioexception), ex);
}
}
private void checkExists(Path path) throws IOException {
String directories = Files.walk(path).filter(p -> {
try {
return p.toFile().isDirectory() && !Files.isSameFile(path, p);
} catch(IOException ex) {
return false;
}
}).map(p -> p.toString()).collect(Collectors.joining(", "));
if(directories.length()>0) {
logWarning(getMessage(MESSAGE.directories, directories));
}
String nonCsv = Files.walk(path, 1).filter(p -> {
try {
return p.toFile().isFile() && !SAREF.CSV_MATCHER.matches(p) && !p.toFile().getName().startsWith(".");
} catch (Exception ex) {
return false;
}
}).map(p -> p.getFileName().toString()).collect(Collectors.joining(", "));
if(nonCsv.length()>0) {
logError(getMessage(MESSAGE.csv, nonCsv));
}
boolean containsFile = Files.walk(path, 1).anyMatch(p -> {
return SAREF.CSV_MATCHER.matches(p);
});
if (!containsFile) {
logWarning(getMessage(MESSAGE.missing));
public void readRequirements() throws SAREFPipelineException {
Model requirements = version.getRequirements();
File file = new File(repository.getDirectory(), "requirements/requirements.csv");
CSVParser parser = new CSVParserBuilder().withSeparator(';').withQuoteChar('"').build();
try (FileReader filereader = new FileReader(file);
CSVReader csvReader = new CSVReaderBuilder(filereader).withCSVParser(parser).build()) {
csvReader.forEach(row -> {
String id = row[0]; // WATR-1
Resource resource = requirements.getResource(String.format("%srequirements#%s", version.getIRI(), id));
String category = row[1]; // Water infrastructure
String requirement = row[2]; // Which assets compose a water distribution infrastructure? ...
requirements.add(resource, RDF.type, VTC.Requirement);
requirements.add(resource, VTC.requirementId, id);
requirements.add(resource, VTC.category, category);
requirements.add(resource, DCTerms.description, requirement);
});
} catch (Exception e) {
logWarning(getMessage(MESSAGE.ioexception), e);
}
}
private void checkFirstLine(Path path) throws IOException {
Files.walk(path).filter(p -> {
return SAREF.CSV_MATCHER.matches(p);
}).forEach(p -> {
Optional<String> firstLine;
try {
firstLine = Files.lines(p).findFirst();
if (!firstLine.isPresent()) {
logError(getMessage(MESSAGE.line, p.getFileName()));
} else {
if (!firstLine.get().equals(FIRST_LINE)) {
logError(getMessage(MESSAGE.line, p.getFileName()));
}
}
} catch (IOException e) {
logError(getMessage(MESSAGE.ioexception), e);
}
});
}
private void requirementsRDFaGenerator() throws SAREFPipelineException, IOException{
private void requirementsRDFaGenerator() throws SAREFPipelineException, IOException {
if (pipeline.ignoreSite) {
return;
}
String categoryChanger = "";
String repoName = project.getName();
String href = project.getNamespace();
......@@ -130,6 +122,17 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
FileUtils.forceMkdir(versionSite);
File reqHTML = new File(versionSite, "requirements.html");
GenerateRDFaManager.GenerateRDFa(categoryChanger, repoName, href, reqCSV, reqHTML, "requirements");
Model model = version.getRequirements();
for (Languages l : Languages.values()) {
String fileName = String.format("requirements.%s", l.getExt());
File file = new File(versionSite, fileName);
try (FileOutputStream fos = new FileOutputStream(file)) {
model.write(fos, l.getLang());
} catch (IOException ex) {
String msg = getMessage(MESSAGE.ioexception, ex);
errorLogger.warn(msg, ex);
}
}
}
}
......@@ -39,6 +39,10 @@ import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.profiles.OWL2DLProfile;
import org.semanticweb.owlapi.profiles.OWLProfileReport;
import org.semanticweb.owlapi.profiles.violations.UseOfDefinedDatatypeInDatatypeRestriction;
import org.semanticweb.owlapi.profiles.violations.UseOfDefinedDatatypeInLiteral;
import org.semanticweb.owlapi.profiles.violations.UseOfUndeclaredDatatype;
import org.semanticweb.owlapi.profiles.violations.UseOfUnknownDatatype;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.managers.OntologyManager;
......@@ -75,6 +79,15 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
}
final OWLProfileReport report = new OWL2DLProfile().checkOntology(ontology);
report.getViolations().removeIf(v->{
if(v instanceof UseOfDefinedDatatypeInDatatypeRestriction
|| v instanceof UseOfDefinedDatatypeInLiteral
|| v instanceof UseOfUndeclaredDatatype
|| v instanceof UseOfUnknownDatatype) {
return true;
}
return false;
});
if (!report.getViolations().isEmpty()) {
String violations = report.getViolations().stream().map(Object::toString)
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
......@@ -133,7 +146,10 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
.addHeader("Content-Type", "application/xml").build();
Response response = httpClient.newCall(request).execute();
if (response.code() != 200) {
throw new SAREFPipelineException("response", "Unexpected response code " + response.code());
}
String result = response.body().string();
String[] results = result.split("\\n");
......@@ -148,8 +164,8 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
arrayData = pureData.toArray(); // response into array
} catch (IOException e) {
logWarning(getMessage(MESSAGE.oopsError));
} catch (IOException | SAREFPipelineException e) {
logWarning(getMessage(MESSAGE.oopsError), e);
}
int count = OopsManager.counter(arrayData);
......
......@@ -35,6 +35,10 @@ import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.parameters.Imports;
import org.semanticweb.owlapi.profiles.OWL2DLProfile;
import org.semanticweb.owlapi.profiles.OWLProfileReport;
import org.semanticweb.owlapi.profiles.violations.UseOfDefinedDatatypeInDatatypeRestriction;
import org.semanticweb.owlapi.profiles.violations.UseOfDefinedDatatypeInLiteral;
import org.semanticweb.owlapi.profiles.violations.UseOfUndeclaredDatatype;
import org.semanticweb.owlapi.profiles.violations.UseOfUnknownDatatype;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.SAREFExample;
......@@ -67,6 +71,16 @@ public class Clause_9_6_4_Checker extends AbstractClauseChecker {
}
final OWLProfileReport report = new OWL2DLProfile().checkOntology(ontology);
report.getViolations().removeIf(v->{
if(v instanceof UseOfDefinedDatatypeInDatatypeRestriction
|| v instanceof UseOfDefinedDatatypeInLiteral
|| v instanceof UseOfUndeclaredDatatype
|| v instanceof UseOfUnknownDatatype) {
return true;
}
return false;
});
if(!report.getViolations().isEmpty()) {
String violations = report.getViolations().stream().map(Object::toString)
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
......
......@@ -30,9 +30,13 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.vocabulary.DCTerms;
import org.eclipse.jgit.lib.Ref;
import fr.emse.gitlab.saref.utils.Languages;
import fr.emse.gitlab.saref.vocabs.VTC;
public class SAREFVersion extends SAREFNamedGraph implements SAREFProject {
......@@ -44,6 +48,8 @@ public class SAREFVersion extends SAREFNamedGraph implements SAREFProject {
private final Map<String, SAREFExample> examples = new HashMap<>();
private final Set<SAREFTerm> definedTerms = new HashSet<>();
private final Set<SAREFTerm> usedTerms = new HashSet<>();
private final Model requirements = ModelFactory.createDefaultModel();
private final Model tests = ModelFactory.createDefaultModel();
public SAREFVersion(SAREFRepository repository, SAREFVersionName versionName, Ref developRef, Ref prereleaseRef,
Ref releaseRef) {
......@@ -53,6 +59,10 @@ public class SAREFVersion extends SAREFNamedGraph implements SAREFProject {
this.developRef = developRef;
this.prereleaseRef = prereleaseRef;
this.releaseRef = releaseRef;
requirements.setNsPrefix(VTC.PREFIX, VTC.NS);
requirements.setNsPrefix("dcterms", DCTerms.NS);
tests.setNsPrefix(VTC.PREFIX, VTC.NS);
}
public SAREFRepository getRepository() {
......@@ -142,6 +152,14 @@ public class SAREFVersion extends SAREFNamedGraph implements SAREFProject {
public void usesTerm(SAREFTerm term) {
usedTerms.add(term);
}
public Model getRequirements() {
return requirements;
}
public Model getTests() {
return tests;
}
@Override
public String toString() {
......
......@@ -52,7 +52,7 @@ public class GenerateRDFaManager {
String footer = IOUtils.toString(Main.class.getClassLoader().getResourceAsStream("themis/footer.html"),
StandardCharsets.UTF_8);
header = header.replaceAll("@ontologyName", repoName).replaceAll("@href", href + "/" + identifier + "/");
header = header.replaceAll("@ontologyName", repoName).replaceAll("@href", href + identifier + "#");
body = body.replaceAll("@docType", StringUtils.capitalize(identifier)).replaceAll("@ontologyName",
repoName);
......
......@@ -29,9 +29,6 @@ import java.io.IOException;
import java.util.Set;
import java.util.function.Supplier;
import org.apache.jena.vocabulary.OWL;
import org.apache.jena.vocabulary.OWL2;
import org.apache.jena.vocabulary.RDF;
import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owl.explanation.api.Explanation;
import org.semanticweb.owl.explanation.api.ExplanationGenerator;
......@@ -68,7 +65,6 @@ import fr.emse.gitlab.saref.SAREFPipeline;
import fr.emse.gitlab.saref.SAREFPipeline.Mode;
import fr.emse.gitlab.saref.entities.SAREFExample;
import fr.emse.gitlab.saref.entities.SAREFVersion;
import fr.emse.gitlab.saref.entities.SAREFVersionName;
import fr.emse.gitlab.saref.managers.parsers.JenaModelDocumentFormatFactory;
import fr.emse.gitlab.saref.managers.parsers.SourceOntologyParser;
......@@ -118,8 +114,13 @@ public class OntologyManager extends SAREFErrorLogger {
}
public OWLOntology loadOntology(SAREFVersion version, Logger logger) {
IRI iri = IRI.create(version.getIRI());
OWLOntology ontology = ONTOLOGY_MANAGER.getOntology(iri);
if(ontology != null) {
return ontology;
}
try {
return ONTOLOGY_MANAGER.loadOntologyFromOntologyDocument(IRI.create(version.getIRI()));
return ONTOLOGY_MANAGER.loadOntologyFromOntologyDocument(iri);
} catch (OWLOntologyCreationException ex) {
log(logger, getMessage(MESSAGE.loading_error), ex, Mode.DEVELOP, Mode.RELEASE, Mode.PORTAL);
return null;
......@@ -127,6 +128,11 @@ public class OntologyManager extends SAREFErrorLogger {
}
public OWLOntology loadOntology(SAREFExample example, Logger logger) {
IRI iri = IRI.create(example.getIRI());
OWLOntology ontology = ONTOLOGY_MANAGER.getOntology(iri);
if(ontology != null) {
return ontology;
}
try {
return ONTOLOGY_MANAGER.loadOntologyFromOntologyDocument(IRI.create(example.getIRI()));
} catch (OWLOntologyCreationException ex) {
......
/*
* Copyright 2020 ETSI
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package fr.emse.gitlab.saref.vocabs;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
/**
*
* @author Maxime Lefrançois
*
*/
public class VTC {
public static final String PREFIX = "vtc";
public static final String NS = "https://w3id.org/def/vtc#";
public static final Property category = ResourceFactory.createProperty(NS, "category");
public static final Property requirementId = ResourceFactory.createProperty(NS, "requirementId");
public static final Resource Requirement = ResourceFactory.createResource(NS + "Requirement");
public static final Resource TestCaseDesign = ResourceFactory.createResource(NS + "TestCaseDesign");
public static final Property comesFromRequirement = ResourceFactory.createProperty(NS, "comesFromRequirement");
public static final Property desiredBehaviour = ResourceFactory.createProperty(NS, "desiredBehaviour");
public static final Property testId = ResourceFactory.createProperty(NS, "testId");
}
......@@ -58,6 +58,7 @@ TEMPLATE <header.rqg>( st:call-template(<ontology/title.rqg>, ?onto ) , ?pathToS
{
TEMPLATE <ontology/contributors.rqg>( ?onto ) .
}
<dt>Ontology requirements and tests</dt><dd><a href='requirements'>requirements</a> and <a href='tests'>tests</a></dd>
{
TEMPLATE {
......
......@@ -9,4 +9,5 @@ log4j.logger.SAREF=WARN
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=## %-5p in %c%n%n%m%n%n
#log4j.appender.stdout.layout.ConversionPattern=## %-5p in %c%n%n%m%n%n
log4j.appender.stdout.layout.ConversionPattern=## %-5p in %c%n%n%m%nIn %C:%L:%M%n%n
missing=The `requirements` directory should contain at least one file with the `.csv` extension. This file shall conform to the requirements specification as defined in clause 9.3.2 in TS 103 673.
line=The requirements specification file %s shall be a CSV (Comma-Separated Values) file encoded in UTF-8. The first line of the file shall be the following: `Id;Category;Requirement`
ioexception=Error while checking the `requirements` directory
directories=There should not be directories in the `requirements` directory. Their content will be ignored. Got: %s
csv=Every requirement document shall have the extension `.csv`. The following documents violate this clause: %s
missing=The `requirements` directory should contain a file `requirements.csv`. This file shall conform to the requirements specification as defined in clause 9.3.2 in TS 103 673.
line=The requirements specification file shall be a CSV (Comma-Separated Values) file encoded in UTF-8. The first line of the file shall be the following: `Id;Category;Requirement`
ioexception=Error while checking the `requirements` directory
\ No newline at end of file
missing=The `tests` directory should contain at least one file with the `.csv` extension. This file shall conform to the requirements specification as defined in clause 9.5.2 in TS 103 673.
missing=The `tests` directory should contain a file `tests.csv`. This file shall conform to the requirements specification as defined in clause 9.5.2 in TS 103 673.
line=The `tests` specification shall be a CSV (Comma-Separated Values) file encoded in UTF-8. The first line of the file shall be the following: `Id;Requirement;Category;Test`
ioexception=Error while checking the `tests` directory
directories=There should not be directories in the `tests` directory. Their content will be ignored.
csv=Every test document shall have the extension `.csv`. The following documents violate this clause: %s
themis=OOPS found some problems. Violations are: %s
themisError=Themis error. The service may be under maintenance.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment