Commit 2b0a3b7a authored by Maxime Lefrançois's avatar Maxime Lefrançois

Merge branch 'master' of gitlab.emse.fr:saref/saref-pipeline

parents 735dae1e ec184135
Pipeline #4203 passed with stage
in 2 minutes
/* /*
* Copyright 2020 ETSI * Copyright 2020 ETSI
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors * 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 * may be used to endorse or promote products derived from this software without
* specific prior written permission. * specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * 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, * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * 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 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * 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 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package fr.emse.gitlab.saref.checkers; package fr.emse.gitlab.saref.checkers;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import fr.emse.gitlab.saref.managers.ThemisManager;
import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.Model;
import org.semanticweb.owl.explanation.api.Explanation; import org.semanticweb.owl.explanation.api.Explanation;
import org.semanticweb.owl.explanation.api.ExplanationGenerator; import org.semanticweb.owl.explanation.api.ExplanationGenerator;
...@@ -48,18 +49,21 @@ import org.semanticweb.owlapi.profiles.violations.UseOfUnknownDatatype; ...@@ -48,18 +49,21 @@ import org.semanticweb.owlapi.profiles.violations.UseOfUnknownDatatype;
import fr.emse.gitlab.saref.SAREFPipelineException; import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.managers.OntologyManager; import fr.emse.gitlab.saref.managers.OntologyManager;
import fr.emse.gitlab.saref.managers.OopsManager;
import fr.emse.gitlab.saref.managers.RepositoryManager; import fr.emse.gitlab.saref.managers.RepositoryManager;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import org.semanticweb.owlapi.reasoner.TimeOutException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/** /**
* Checks TS 103 673 Clause 9.4.5: OWL Profile, Consistency, and Satisfiability * Checks TS 103 673 Clause 9.4.5: OWL Profile, Consistency, and Satisfiability
* of Classes * of Classes
* *
*/ */
public class Clause_9_4_5_Checker extends AbstractClauseChecker { public class Clause_9_4_5_Checker extends AbstractClauseChecker {
...@@ -121,7 +125,7 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker { ...@@ -121,7 +125,7 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
try { try {
checkOops(); checkOops();
} catch (Exception ex) { } catch (Exception ex) {
logWarning(getMessage(MESSAGE.oopsError), ex); logWarning(getMessage(MESSAGE.oopsError), ex);
} }
} }
...@@ -139,6 +143,7 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker { ...@@ -139,6 +143,7 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
+ "<OutputFormat>RDF/XML</OutputFormat>" + "</OOPSRequest>"; + "<OutputFormat>RDF/XML</OutputFormat>" + "</OOPSRequest>";
Object[] arrayData = new Object[0]; Object[] arrayData = new Object[0];
try { try {
...@@ -152,45 +157,94 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker { ...@@ -152,45 +157,94 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
Request request = new Request.Builder().url("http://oops.linkeddata.es/rest").method("POST", body) Request request = new Request.Builder().url("http://oops.linkeddata.es/rest").method("POST", body)
.addHeader("Content-Type", "application/xml").build(); .addHeader("Content-Type", "application/xml").build();
Response response = httpClient.newCall(request).execute(); Response response;
if (response.code() != 200) {
throw new SAREFPipelineException("response", "Unexpected response code " + response.code()); try{
response = httpClient.newCall(request).execute();
} }
catch (SocketTimeoutException e){
String result = response.body().string();
String[] results = result.split("\\n"); httpClient = new OkHttpClient().newBuilder().readTimeout(10, TimeUnit.SECONDS).build();
List<String> pureData = new ArrayList<String>(); try{
for (int i = 0; i < results.length; i++) { response = httpClient.newCall(request).execute();
pureData.add(results[i]); }
catch (SocketTimeoutException f){
httpClient = new OkHttpClient().newBuilder().readTimeout(20, TimeUnit.SECONDS).build();
response = httpClient.newCall(request).execute();
}
} }
arrayData = pureData.toArray(); // response into array
} catch (IOException | SAREFPipelineException e) {
logWarning(getMessage(MESSAGE.oopsError), e);
}
int count = OopsManager.counter(arrayData); if (response.code() != 200) {
throw new SAREFPipelineException("response", "Unexpected response code " + response.code());
}
ArrayList<ArrayList<String>> result = OopsManager.getData(arrayData); String result = response.body().string();
int s = 0; Document doc = ThemisManager.convertStringToXMLDocument(result);
NodeList nodeList = doc.getElementsByTagName("rdf:Description");
ArrayList<String> oopsErrors = new ArrayList<String>();
for (int temp = 0; temp < nodeList.getLength(); temp++){
org.w3c.dom.Node node = nodeList.item(temp);
if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
Element element = (Element) node;
if (((Element) node).getElementsByTagName("oops:hasCode").item(0) != null) {
if (((Element) node).getElementsByTagName("oops:hasName").item(0) != null) {
String code = element.getElementsByTagName("oops:hasCode").item(0).getTextContent();
String name = element.getElementsByTagName("oops:hasName").item(0).getTextContent();
String description = element.getElementsByTagName("oops:hasDescription").item(0).getTextContent();
String affected = "";
NodeList affectedElements = element.getElementsByTagName("oops:hasAffectedElement");
if (affectedElements != null) {
for (int k = 0; k < affectedElements.getLength(); k++) {
if (k == 0) {
affected += "\"" + affectedElements.item(k).getTextContent() + "\"";
} else {
affected += " ; \"" + affectedElements.item(k).getTextContent() + "\"";
}
}
}
String oopsError = String.format("Code: %s, Name: %s, Description: %s, Affected Elements: %s", code, name, description, affected);
oopsErrors.add(oopsError);
}
else{
String code = element.getElementsByTagName("oops:hasCode").item(0).getTextContent();
String description = element.getElementsByTagName("oops:hasDescription").item(0).getTextContent();
String affected = "";
NodeList affectedElements = element.getElementsByTagName("oops:hasAffectedElement");
if (affectedElements != null) {
for (int k = 0; k < affectedElements.getLength(); k++) {
if (k == 0) {
affected += "\"" + affectedElements.item(k).getTextContent() + "\"";
} else {
affected += " ; \"" + affectedElements.item(k).getTextContent() + "\"";
}
}
}
String oopsError = String.format("Code: %s, Description: %s, Affected Elements: %s", code, description, affected);
oopsErrors.add(oopsError);
}
}
}
}
if (!oopsErrors.isEmpty()) {
String data = oopsErrors.stream().map(e -> e.toString())
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
logWarning(getMessage(MESSAGE.oops, data));
ArrayList<String> results = new ArrayList<String>(); }
while (s < count) {
String data = result.get(0).get(s).concat("-") + result.get(1).get(s).concat(".") + result.get(2).get(s) + "Affected Elements: " + result.get(3).get(s);
results.add(data);
s++;
}
String printData = results.stream().map(e -> e.toString()) } catch (IOException | SAREFPipelineException e) {
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n")); logWarning(getMessage(MESSAGE.oopsError), e);
if (count != 0) {
logWarning(getMessage(MESSAGE.oops, printData));
} }
} }
......
/* /*
* Copyright 2020 ETSI * Copyright 2020 ETSI
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors * 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 * may be used to endorse or promote products derived from this software without
* specific prior written permission. * specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * 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, * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * 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 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * 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 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package fr.emse.gitlab.saref.checkers; package fr.emse.gitlab.saref.checkers;
...@@ -101,14 +101,14 @@ public class Clause_9_5_Checker extends AbstractClauseChecker { ...@@ -101,14 +101,14 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
return; return;
} }
readTests(); // generates the RDF model for the tests readTests(); // generates the RDF model for the tests
try { try {
callThemis(); // uses the RDF model for the tests and sends it to ThemisOWL profile, consistency, lack of pitfalls and class satisfiability callThemis(); // uses the RDF model for the tests and sends it to ThemisOWL profile, consistency, lack of pitfalls and class satisfiability
testsRDFaGenerator(); // this generates the html file with rdfa embedded. testsRDFaGenerator(); // this generates the html file with rdfa embedded.
} catch (Exception ex) { } catch (Exception ex) {
logWarning(getMessage(MESSAGE.themis), ex); logWarning(getMessage(MESSAGE.themis), ex);
} }
} catch (IOException ex) { } catch (IOException ex) {
logError(getMessage(MESSAGE.ioexception)); logError(getMessage(MESSAGE.ioexception));
} }
......
/*
* 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.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<String> affectedElements = new ArrayList<String>();
ArrayList<ArrayList<String>> elements = new ArrayList<ArrayList<String>>();
elements.add(getID);
elements.add(getName);
elements.add(getInfo);
elements.add(affectedElements);
String affected = "";
for (int i = 0; i < data.length; 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);
}
if (i>0 && i < data.length-1) {
String prove = data[i - 1].toString().replaceAll(" ", "");
String prove2 = data[i + 1].toString().replaceAll(" ", "");
if (data2.startsWith("<oops:hasAffectedElement")) {
if (!prove.startsWith("<oops:hasAffectedElement")) {
String[] data3 = data2.split("(<|>)");
affected += data3[2];
}
else if (!prove2.startsWith("<oops:hasAffectedElement")){
String[] data3 = data2.split("(<|>)");
affected += ", " + data3[2];
affectedElements.add(affected);
elements.set(3, affectedElements);
affected = "";
}
else{
String[] data3 = data2.split("(<|>)");
affected += ", " + data3[2];
}
}
}
}
return elements;
}
public static int counter(Object[] data) {
int counter = 0;
for (int i = 0; i < data.length; i++) {
String data2 = data[i].toString().replaceAll(" ", "");
if (data2.startsWith("<oops:hasCode")) {
counter++;
}
}
return counter;
}
}
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