Unverified Commit bf08549d authored by Maxime Lefrançois's avatar Maxime Lefrançois
Browse files

autoclose responses for themis and oops

parent 46a3e8eb
Pipeline #382 passed with stage
in 23 seconds
......@@ -30,7 +30,6 @@ import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.jena.rdf.model.Model;
......@@ -84,11 +83,9 @@ 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) {
report.getViolations().removeIf(v -> {
if (v instanceof UseOfDefinedDatatypeInDatatypeRestriction || v instanceof UseOfDefinedDatatypeInLiteral
|| v instanceof UseOfUndeclaredDatatype || v instanceof UseOfUnknownDatatype) {
return true;
}
return false;
......@@ -129,7 +126,7 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
}
public void checkOops() throws Exception {
if(SAREF.IGNORE_OOPS) {
if (SAREF.IGNORE_OOPS) {
return;
}
......@@ -144,8 +141,6 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
+ "<OntologyContent><![CDATA[" + onto + "]]></OntologyContent>" + "<Pitfalls></Pitfalls>"
+ "<OutputFormat>RDF/XML</OutputFormat>" + "</OOPSRequest>";
Object[] arrayData = new Object[0];
try {
......@@ -159,92 +154,78 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
Request request = new Request.Builder().url("http://oops.linkeddata.es/rest").method("POST", body)
.addHeader("Content-Type", "application/xml").build();
Response response;
try{
response = httpClient.newCall(request).execute();
}
catch (SocketTimeoutException e){
httpClient = new OkHttpClient().newBuilder().readTimeout(10, TimeUnit.SECONDS).build();
try (Response response = httpClient.newCall(request).execute();) {
try{
response = httpClient.newCall(request).execute();
}
catch (SocketTimeoutException f){
httpClient = new OkHttpClient().newBuilder().readTimeout(20, TimeUnit.SECONDS).build();
response = httpClient.newCall(request).execute();
if (response.code() != 200) {
throw new SAREFPipelineException("response", "Unexpected response code " + response.code());
}
}
if (response.code() != 200) {
throw new SAREFPipelineException("response", "Unexpected response code " + response.code());
}
String result = response.body().string();
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 result = response.body().string();
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, 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);
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));
if (!oopsErrors.isEmpty()) {
String data = oopsErrors.stream().map(e -> e.toString())
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
logWarning(getMessage(MESSAGE.oops, data));
}
} catch (SocketTimeoutException e) {
logWarning(getMessage(MESSAGE.oopsError), e);
}
} catch (IOException | SAREFPipelineException e) {
logWarning(getMessage(MESSAGE.oopsError), e);
}
......
......@@ -159,8 +159,7 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
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();
try {
Response response = httpClient.newCall(request).execute();
try (Response response = httpClient.newCall(request).execute();) {
if (response.code() != 200) {
throw new SAREFPipelineException("response", "Unexpected response code " + response.code());
}
......
......@@ -38,16 +38,17 @@ public class ThemisManager {
// Parser that produces DOM object trees from XML content
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// API to obtain DOM Document instance
try {
try(StringReader reader = new StringReader(xmlString)) {
// Create DocumentBuilder with default configuration
DocumentBuilder builder = factory.newDocumentBuilder();
// Parse the content to Document object
Document doc = builder.parse(new InputSource(new StringReader(xmlString)));
Document doc = builder.parse(new InputSource(reader));
return doc;
} catch (Exception e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
......
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