Commit 012f43d1 authored by Salva5297's avatar Salva5297

Added Themis, OOPS and RDFaGenerator Services to clauses 9.3, 9.4.5, 9.5 to the new code

parent d1a1595b
......@@ -176,6 +176,30 @@
<version>11</version>
</dependency>
<dependency>
<groupId>org.apache.any23</groupId>
<artifactId>apache-any23-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-api</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.1</version>
</dependency>
</dependencies>
<build>
......
......@@ -34,6 +34,7 @@ import java.util.stream.Collectors;
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;
/**
......@@ -61,6 +62,7 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
try {
checkExists(dir.toPath());
checkFirstLine(dir.toPath());
requirementsRDFaGenerator();
} catch (IOException ex) {
logError(getMessage(MESSAGE.ioexception), ex);
}
......@@ -117,4 +119,20 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
});
}
private void requirementsRDFaGenerator() throws SAREFPipelineException{
String categoryChanger = "";
String repoName = project.getName();
String href = project.getNamespace();
File reqCSV = new File(repository.getDirectory(),"/requirements/requirements.csv");
File reqHTML = new File(repository.getDirectory(), "/target/site/requirements.html");
GenerateRDFaManager manager = new GenerateRDFaManager();
manager.GenerateRDFaManager(categoryChanger, repoName, href, reqCSV, reqHTML, "requirements");
}
}
......@@ -25,9 +25,16 @@
*/
package fr.emse.gitlab.saref.checkers;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import fr.emse.gitlab.saref.SAREFPipeline;
import fr.emse.gitlab.saref.managers.OopsManager;
import org.apache.jena.rdf.model.Model;
import org.semanticweb.owl.explanation.api.Explanation;
import org.semanticweb.owl.explanation.api.ExplanationGenerator;
import org.semanticweb.owlapi.model.OWLAxiom;
......@@ -39,6 +46,8 @@ import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.managers.OntologyManager;
import fr.emse.gitlab.saref.managers.RepositoryManager;
import okhttp3.*;
/**
* Checks TS 103 673 Clause 9.4.5: OWL Profile, Consistency, and Satisfiability
* of Classes
......@@ -47,7 +56,7 @@ import fr.emse.gitlab.saref.managers.RepositoryManager;
public class Clause_9_4_5_Checker extends AbstractClauseChecker {
private static enum MESSAGE {
profile, consistent, satisfiable;
profile, consistent, satisfiable, oops, oopsError;
}
/**
......@@ -92,6 +101,91 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
}
});
}
checkOops();
}
public void checkOops() throws SAREFPipelineException{
ByteArrayOutputStream out = new ByteArrayOutputStream();
String onto = "";
Model model = version.getModel();
model.write(out,"RDF/XML"); // write in string and then replace
onto = out.toString().replace("]]","] ]");
String xmlRequest = "<?xml version='1.0' encoding='UTF-8'?>" +
"<OOPSRequest>" +
"<OntologyURI></OntologyURI>" +
"<OntologyContent><![CDATA[" + onto + "]]></OntologyContent>" +
"<Pitfalls>10</Pitfalls>" +
"<OutputFormat>RDF/XML</OutputFormat>" +
"</OOPSRequest>";
OopsManager manager = new OopsManager();
ArrayList<ArrayList<String>> res = new ArrayList<ArrayList<String>>();
Object[] arrayData = new Object[0];
try{
OkHttpClient httpClient = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(xmlRequest, mediaType);
Request request = new Request.Builder()
.url("http://oops.linkeddata.es/rest")
.method("POST", body)
.addHeader("Content-Type", "application/xml")
.build();
Response response = httpClient.newCall(request).execute();
String result = response.body().string();
String[] results = result.split("\\n");
List<String> pureData = new ArrayList<String>();
for(int i=0; i<results.length-1;i++){
if(results[i].startsWith("<")) {
for(int j=i; j<results.length;j++){
pureData.add(results[j]);
}
}
}
arrayData = pureData.toArray(); // response into array
}
catch (IOException e) {
log(getMessage(MESSAGE.oopsError), SAREFPipeline.Mode.RELEASE, SAREFPipeline.Mode.PORTAL);
}
int count = manager.counter(arrayData);
ArrayList<ArrayList<String>> result = manager.getData(arrayData);
int s = 0;
ArrayList<String> results = new ArrayList<String>();
while(s < count) {
String data = result.get(0).get(s)+result.get(1).get(s)+result.get(2).get(s);
results.add(data);
s++;
}
String printData = results.stream().map(e -> e.toString()).collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
if(count!=0) {
log(getMessage(MESSAGE.oops, printData), SAREFPipeline.Mode.RELEASE, SAREFPipeline.Mode.PORTAL);
}
}
}
......@@ -25,17 +25,32 @@
*/
package fr.emse.gitlab.saref.checkers;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.io.*;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Optional;
import java.util.stream.Collectors;
import fr.emse.gitlab.saref.SAREFPipeline;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.entities.SAREFRepository;
import fr.emse.gitlab.saref.entities.SAREFVersion;
import fr.emse.gitlab.saref.managers.DatasetManager;
import fr.emse.gitlab.saref.managers.GenerateRDFaManager;
import fr.emse.gitlab.saref.managers.RepositoryManager;
import fr.emse.gitlab.saref.managers.ThemisManager;
import okhttp3.*;
import org.apache.any23.Any23;
import org.apache.any23.extractor.ExtractionException;
import org.apache.any23.source.DocumentSource;
import org.apache.any23.source.FileDocumentSource;
import org.apache.any23.writer.RDFXMLWriter;
import org.apache.any23.writer.TripleHandler;
import org.apache.any23.writer.TripleHandlerException;
import org.apache.jena.rdf.model.Model;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* Checks TS 103 673 Clause 9.5: Ontology tests
......@@ -47,7 +62,7 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
private static final String FIRST_LINE = "Id;Requirement;Category;Test";
private static enum MESSAGE {
directories, csv, missing, ioexception, line;
directories, csv, missing, ioexception, line, themis, themisError;
}
/**
......@@ -67,6 +82,8 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
try {
checkExists(dir.toPath());
checkFirstLine(dir.toPath());
testsRDFaGenerator();
checkThemis();
} catch (IOException ex) {
logError(getMessage(MESSAGE.ioexception));
}
......@@ -123,4 +140,128 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
});
}
public void checkThemis() throws SAREFPipelineException {
try {
File tHTML = new File(repository.getDirectory(),"target/site/tests.html");
Any23 runner = new Any23();
ByteArrayOutputStream out = new ByteArrayOutputStream();
DocumentSource source = new FileDocumentSource(tHTML);
TripleHandler handler = new RDFXMLWriter(out);
runner.extract(source, handler);
handler.close();
String xmlData = out.toString();
ArrayList<String []> res = makeCall(xmlData,repository,datasetManager,version);
ArrayList<String> result = new ArrayList<String>();
for(int i = 0; i < res.size(); i++){
String response = res.get(i)[0]+", "+res.get(i)[1]+", "+res.get(i)[2];
result.add(response);
}
String data = result.stream().map(e -> e.toString()).collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
if(!res.isEmpty()) {
log(getMessage(MESSAGE.themis, data), SAREFPipeline.Mode.RELEASE, SAREFPipeline.Mode.RELEASE, SAREFPipeline.Mode.PORTAL);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ExtractionException | UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
log(getMessage(MESSAGE.themisError), SAREFPipeline.Mode.RELEASE, SAREFPipeline.Mode.RELEASE, SAREFPipeline.Mode.PORTAL);
} catch (TripleHandlerException e) {
e.printStackTrace();
}
}
public ArrayList<String []> makeCall(String xmlData, SAREFRepository repository, DatasetManager datasetManager, SAREFVersion version) throws SAREFPipelineException {
ArrayList<String []> res = new ArrayList<String []>();
try{
ByteArrayOutputStream out = new ByteArrayOutputStream();
String onto = "";
Model model = version.getModel();
model.write(out,"RDF/XML");
onto = out.toString();
OkHttpClient httpClient = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
String jsonRequest = "{\"ontologiesCode\":[\"" +
onto.replace("\\\"", "\\\\\"").replace("\"", "\\\"").replace("\t"," ") +
"\"]," + "\"testfile\":[\"" +
xmlData.replace("\\\"", "\\\\\"").replace("\"", "\\\"").replace("\t"," ") +
"\"]," + "\"format\":\"junit\"}";
RequestBody body = RequestBody.create(jsonRequest, mediaType);
Request request = new Request.Builder()
.url("http://themis.linkeddata.es/rest/api/results")
.method("POST", body)
.addHeader("accept", "application/json")
.addHeader("Content-Type", "application/json")
.build();
Response response = httpClient.newCall(request).execute();
String result = response.body().string();
ThemisManager manager = new ThemisManager();
Document doc = manager.convertStringToXMLDocument(result);
NodeList nodeList = doc.getElementsByTagName("testcase");
for (int temp = 0; temp < nodeList.getLength(); temp++) {
org.w3c.dom.Node node = nodeList.item(temp);
String [] part = new String[3];
if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
Element element = (Element) node;
part[0] = ""+element.getAttributeNode("id");
part[1] = ""+element.getAttributeNode("name");
part[2] = ""+((Element) node).getElementsByTagName("error").item(0).getAttributes().getNamedItem("message");
res.add(part);
}
}
} catch (IOException e) {
log(getMessage(MESSAGE.themisError), SAREFPipeline.Mode.RELEASE, SAREFPipeline.Mode.RELEASE, SAREFPipeline.Mode.PORTAL);
}
return res;
}
private void testsRDFaGenerator() throws SAREFPipelineException{
String categoryChanger = "";
String repoName = project.getName();
String href = project.getNamespace();
File testCSV = new File(repository.getDirectory(),"/tests/tests.csv");
File testHTML = new File(repository.getDirectory(), "/target/site/tests.html");
GenerateRDFaManager manager = new GenerateRDFaManager();
manager.GenerateRDFaManager(categoryChanger, repoName, href, testCSV, testHTML, "tests");
}
}
package fr.emse.gitlab.saref.managers;
import java.util.ArrayList;
public class OopsManager {
public static ArrayList<ArrayList<String>> getData(Object[] data){
ArrayList<String> getID = new ArrayList<String>();
ArrayList<String> getName = new ArrayList<String>();
ArrayList<String> getInfo = new ArrayList<String>();
ArrayList<ArrayList<String>> elements = new ArrayList<ArrayList<String>>();
elements.add(getID);
elements.add(getName);
elements.add(getInfo);
for(int i=0; i<data.length-1;i++) {
String data2 = data[i].toString().replaceAll(" ","");
if(data2.startsWith("<oops:hasCode")){
String[] data3 = data2.split("(<|>)");
getID.add(data3[2]);
elements.set(0, getID);
}
else if(data2.startsWith("<oops:hasName")){
String[] data3 = data2.split("(<|>)");
getName.add(data3[2]);
elements.set(1, getName);
}
else if(data2.startsWith("<oops:hasDescription")){
String[] data3 = data2.split("(<|>)");
getInfo.add(data3[2]);
elements.set(2, getInfo);
}
}
return elements;
}
public static int counter(Object[] data){
int counter = 0;
for(int i=0; i<data.length-1;i++){
String data2 = data[i].toString().replaceAll(" ","");
if(data2.startsWith("<oops:hasCode")){
counter++;
}
}
return counter;
}
}
package fr.emse.gitlab.saref.managers;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
public class ThemisManager {
public static Document convertStringToXMLDocument(String xmlString)
{
//Parser that produces DOM object trees from XML content
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//API to obtain DOM Document instance
try
{
//Create DocumentBuilder with default configuration
DocumentBuilder builder = factory.newDocumentBuilder();
//Parse the content to Document object
Document doc = builder.parse(new InputSource(new StringReader(xmlString)));
return doc;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
}
profile=The ontology in the ontology document shall satisfy the OWL2 DL profile. Violations are: %s
consistent=The ontology in the ontology document shall be Consistent. Violations are: %s
satisfiable=OWL Class %s declared in the ontology document should be satisfiable. Violations are: %s
oops=OOPS found some problems. Violations are: %s
oopsError=OOPS error. The service can be under maintenance.
\ No newline at end of file
......@@ -3,3 +3,5 @@ line=The `tests` specification shall be a CSV (Comma-Separated Values) file enco
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 can be under maintenance.
\ No newline at end of file
<body class="gantry g-helium-style site com_content view-article no-layout no-task dir-ltr itemid-217 outline-19 g-offcanvas-left g-default g-style-preset1">
<div id="g-offcanvas" data-g-offcanvas-swipe="1" data-g-offcanvas-css3="1">
<div class="g-grid">
<div class="g-block size-100">
<div class="g-content g-particle">
<div id="g-mobilemenu-container" data-g-menu-breakpoint="48rem"></div>
</div>
</div>
</div>
</div>
<div id="g-page-surround">
<div class="g-offcanvas-hide g-offcanvas-toggle" data-offcanvas-toggle-aria-controls="g-offcanvas" aria-expanded="false"><i class="fa fa-fw fa-bars"></i></div>
<section id="g-navigation">
<div class="g-container">
<div class="g-grid">
<div class="g-block size-17">
<div class="g-content g-particle">
<a href="" title="" rel="home" class="g-logo g-logo-helium">
<img src="static/images/logo-l.png" alt="" />
</a>
</div>
</div>
<div class="g-block size-50">
<div class="g-content g-particle">
<nav class="g-main-nav" role="navigation" data-g-hover-expand="true">
<ul class="g-toplevel">
<li class="g-menu-item g-menu-item-type-component g-menu-item-217 active g-standard">
<a class="g-menu-item-container" href="index.html"><span class="g-menu-item-content"><span class="g-menu-item-title">Home</span></span></a>
</li>
<li class="g-menu-item g-menu-item-type-component g-menu-item-242 g-standard">
<a class="g-menu-item-container" href="core/"><span class="g-menu-item-content"><span class="g-menu-item-title">SAREF core</span></span></a>
</li>
<li class="g-menu-item g-menu-item-type-component g-menu-item-242 g-standard">
<a class="g-menu-item-container" href="resources.html"><span class="g-menu-item-content"><span class="g-menu-item-title">Resources</span></span></a>
</li>
<li class="g-menu-item g-menu-item-type-component g-menu-item-242 g-standard">
<a class="g-menu-item-container" href="https://forge.etsi.org/gitlab/SAREF/"><span class="g-menu-item-content"><span class="g-menu-item-title">Participate</span></span></a>
</li>
<li class="g-menu-item g-menu-item-type-component g-menu-item-242 g-standard">
<a class="g-menu-item-container" href=""><span class="g-menu-item-content"><span class="g-menu-item-title">About us</span></span></a>
</li>
<li class="g-menu-item g-menu-item-type-component g-menu-item-242 g-standard">
<a class="g-menu-item-container" href="https://www.etsi.org/committee/smartm2m"><span class="g-menu-item-content"><span class="g-menu-item-title">SmartM2M</span></span></a>
</li>
</ul>
</nav>
</div>
</div>
<div class="g-block g-social-header size-33">
<div class="g-content g-particle">
<div class="g-social">
<a target="_blank" href="https://twitter.com/ETSI_STANDARDS" title="" aria-label="">
<span class="fa fa-twitter fa-fw"></span>
<span class="g-social-text"></span>
</a>
<a target="_blank" href="https://www.facebook.com/etsi.standards" title="" aria-label="">
<span class="fa fa-facebook-official"></span>
<span class="g-social-text"></span>
</a>
<a target="_blank" href="https://www.linkedin.com/company/etsi?trk=biz-companies-cym" title="" aria-label="">
<span class="fa fa-linkedin-square"></span>
<span class="g-social-text"></span>
</a>
<a target="_blank" href="https://www.youtube.com/user/ETSIstandards" title="" aria-label="">
<span class="fa fa-youtube-play"></span>
<span class="g-social-text"></span>
</a>
</div>
</div>
</div>
</div>
</div>
</section>
<header id="g-header">
<div class="g-container">
<div class="g-block size-100">
<div class="g-content g-particle">
<h1><a id="user-content-smart-applications-reference-ontology-and-extensions" class="anchor" href="#smart-applications-reference-ontology-and-extensions" aria-hidden="true">
<span aria-hidden="true" class="octicon octicon-link"></span>
</a>SAREF Pipeline @docType</h1>
</div>
</div>
</div>
</header>
<h1 align="center">@ontologyName</h1>
\ No newline at end of file
</div>
<footer id="g-footer">
<div class="g-container">
<div class="g-grid">
<div class="g-block size-15">
<div class="g-content g-particle">
<a href="https://www.etsi.org/" title="" class="g-logo g-logo-helium">
<img src="https://forge.etsi.org/files/ETSI-Logo_BW_S_Office1.png" alt="" />
</a>
</div>
</div>
<div class="g-block size-20">
<div class="g-content g-particle">© ETSI 2020<br /><a style="font-size:10pt; color:white" href="https://www.etsi.org/">Visit ETSI website for more information on Terms &amp; Conditions.</a></div>
</div>
<div class="g-block g-horizontalmenu size-40">
<div class="g-content g-particle">
<nav class="g-main-nav" role="navigation" data-g-hover-expand="true">
<ul class="g-toplevel">
<li class="g-menu-item g-menu-item-type-component g-menu-item-245 g-standard ">
<a class="g-menu-item-container" href="index.php/legal-matters">
<span class="g-menu-item-content">
<span class="g-menu-item-title">Legal matters</span>
</span>
</a>
</li>
<li class="g-menu-item g-menu-item-type-url g-menu-item-247 g-standard ">
<a class="g-menu-item-container" href="mailto:cti_support@etsi.org?subject=[SAREF]">
<span class="g-menu-item-content">
<span class="g-menu-item-title">Contact &amp; Support</span>
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
<div class="g-block size-25">
<div class="g-content g-particle">
<div class="">
<div class="g-totop">
<a href="#" id="g-totop" rel="nofollow">Back to top <i class="fa fa-chevron-up fa-fw"></i></a>
</div>
</div>
</div>
</div>
</div>
</div>
</footer>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8" />
<meta name="generator" content="SPARQL-Generate" />
<title>SAREF pipeline report</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"/>
<link href="static/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
<link href="static/media/gantry5/assets/css/font-awesome.min.css" rel="stylesheet" />
<link href="static/media/gantry5/engines/nucleus/css-compiled/nucleus.css" rel="stylesheet" />
<link href="static/templates/g5_helium/custom/css-compiled/helium_19.css" rel="stylesheet" />
<link href="static/media/gantry5/assets/css/bootstrap-gantry.css" rel="stylesheet" />
<link href="static/media/gantry5/engines/nucleus/css-compiled/joomla.css" rel="stylesheet" />
<link href="static/media/jui/css/icomoon.css" rel="stylesheet" />
<link href="static/templates/g5_helium/custom/css-compiled/helium-joomla_19.css" rel="stylesheet" />
<link href="static/templates/g5_helium/custom/css-compiled/custom_19.css" rel="stylesheet" />
<link href="static/jqtree/jqtree.css" rel="stylesheet"/>
<script src="static/templates/g5_helium/js/jui/jquery.min.js?06eedc97766b70aa1fa0e80231495faa"></script>
<script src="static/media/jui/js/jquery-noconflict.js?06eedc97766b70aa1fa0e80231495faa"></script>
<script src="static/media/jui/js/jquery-migrate.min.js?06eedc97766b70aa1fa0e80231495faa"></script>
<script src="static/media/system/js/caption.js?06eedc97766b70aa1fa0e80231495faa"></script>
<script src="static/media/jui/js/bootstrap.min.js?06eedc97766b70aa1fa0e80231495faa"></script>
<script src="static/templates/g5_helium/js/juitabs.js"></script>
<script>
jQuery(window).on('load', function() {
new JCaption('img.caption');
});
</script>
<title>@ontologyName</title>
<base href="@href" />
</head>
\ 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