Commit 74d639f1 authored by lefranois's avatar lefranois

Merge branch 'SalvaBranch2' into 'master'

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

See merge request saref/saref-pipeline!5
parents d1a1595b b2e5c160
......@@ -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>
......
......@@ -32,8 +32,11 @@ import java.nio.file.Path;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
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 +64,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 +121,15 @@ public class Clause_9_3_Checker extends AbstractClauseChecker {
});
}
private void requirementsRDFaGenerator() throws SAREFPipelineException, IOException{
String categoryChanger = "";
String repoName = project.getName();
String href = project.getNamespace();
File reqCSV = new File(repository.getDirectory(), "/requirements/requirements.csv");
File versionSite = new File(siteManager.siteDir, version.getVersionPath());
FileUtils.forceMkdir(versionSite);
File reqHTML = new File(versionSite, "requirements.html");
GenerateRDFaManager.GenerateRDFa(categoryChanger, repoName, href, reqCSV, reqHTML, "requirements");
}
}
......@@ -25,9 +25,14 @@
*/
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 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;
......@@ -37,7 +42,13 @@ import org.semanticweb.owlapi.profiles.OWLProfileReport;
import fr.emse.gitlab.saref.SAREFPipelineException;
import fr.emse.gitlab.saref.managers.OntologyManager;
import fr.emse.gitlab.saref.managers.OopsManager;
import fr.emse.gitlab.saref.managers.RepositoryManager;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
* Checks TS 103 673 Clause 9.4.5: OWL Profile, Consistency, and Satisfiability
......@@ -47,7 +58,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;
}
/**
......@@ -64,12 +75,12 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
}
final OWLProfileReport report = new OWL2DLProfile().checkOntology(ontology);
if(!report.getViolations().isEmpty()) {
if (!report.getViolations().isEmpty()) {
String violations = report.getViolations().stream().map(Object::toString)
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
logError(getMessage(MESSAGE.profile, violations));
}
OntologyManager ontologyManager = pipeline.getOntologyManager();
Set<Explanation<OWLAxiom>> incExplanation = ontologyManager.getInconsistenceExplanations(ontology, errorLogger);
......@@ -80,7 +91,7 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
} else {
ExplanationGenerator<OWLAxiom> generator = ontologyManager.getExplanationGenerator(ontology);
ontology.classesInSignature().forEach(c -> {
if(c.isOWLNothing()) {
if (c.isOWLNothing()) {
return;
}
Set<Explanation<OWLAxiom>> incExplanation2 = ontologyManager.getIncoherenceExplanations(generator, c);
......@@ -88,10 +99,78 @@ public class Clause_9_4_5_Checker extends AbstractClauseChecker {
String explanation = incExplanation2.stream().map(e -> e.getAxioms().toString())
.collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
logError(getMessage(MESSAGE.satisfiable, c, explanation));
}
});
}
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().replaceAll("]]", "] ]");
String xmlRequest = "<?xml version='1.0' encoding='UTF-8'?>" + "<OOPSRequest>" + "<OntologyURI></OntologyURI>"
+ "<OntologyContent><![CDATA[" + onto + "]]></OntologyContent>" + "<Pitfalls>10</Pitfalls>"
+ "<OutputFormat>RDF/XML</OutputFormat>" + "</OOPSRequest>";
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; 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) {
logWarning(getMessage(MESSAGE.oopsError));
}
int count = OopsManager.counter(arrayData);
ArrayList<ArrayList<String>> result = OopsManager.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) {
logWarning(getMessage(MESSAGE.oops, printData));
}
}
}
......@@ -25,17 +25,42 @@
*/
package fr.emse.gitlab.saref.checkers;
import java.io.ByteArrayOutputStream;
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.util.ArrayList;
import java.util.Optional;
import java.util.stream.Collectors;
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.commons.io.FileUtils;
import org.apache.jena.rdf.model.Model;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
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.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
* Checks TS 103 673 Clause 9.5: Ontology tests
......@@ -47,7 +72,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 +92,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));
}
......@@ -76,11 +103,11 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
String directories = Files.walk(path).filter(p -> {
try {
return p.toFile().isDirectory() && !Files.isSameFile(path, p);
} catch(IOException ex) {
} catch (IOException ex) {
return false;
}
}).map(p -> p.toString()).collect(Collectors.joining(", "));
if(directories.length()>0) {
if (directories.length() > 0) {
logWarning(getMessage(MESSAGE.directories, directories));
}
......@@ -91,10 +118,10 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
return false;
}
}).map(p -> p.getFileName().toString()).collect(Collectors.joining(", "));
if(nonCsv.length()>0) {
if (nonCsv.length() > 0) {
logError(getMessage(MESSAGE.csv, nonCsv));
}
boolean containsFile = Files.walk(path, 1).anyMatch(p -> {
return csvMatcher.matches(p);
});
......@@ -123,4 +150,99 @@ public class Clause_9_5_Checker extends AbstractClauseChecker {
});
}
public void checkThemis() throws SAREFPipelineException {
File versionSite = new File(siteManager.siteDir, version.getVersionPath());
File tHTML = new File(versionSite, "tests.html");
DocumentSource source = new FileDocumentSource(tHTML);
Any23 runner = new Any23();
try(ByteArrayOutputStream out = new ByteArrayOutputStream(); TripleHandler handler = new RDFXMLWriter(out);) {
runner.extract(source, handler);
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);
}
if (!res.isEmpty()) {
String data = result.stream().map(e -> e.toString()).collect(Collectors.joining("\n- ", "\n\n- ", "\n\n"));
logWarning(getMessage(MESSAGE.themis, data));
}
} catch (ExtractionException | IOException | TripleHandlerException e) {
logWarning(getMessage(MESSAGE.themisError));
}
}
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.replaceAll("\\\"", "\\\\\"").replaceAll("\"", "\\\"").replaceAll("\t", " ") + "\"],"
+ "\"testfile\":[\"" + xmlData.replaceAll("\\\"", "\\\\\"").replaceAll("\"", "\\\"").replaceAll("\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();
Document doc = ThemisManager.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) {
logWarning(getMessage(MESSAGE.themisError));
}
return res;
}
private void testsRDFaGenerator() throws SAREFPipelineException, IOException {
if(pipeline.ignoreSite) {
return;
}
String categoryChanger = "";
String repoName = project.getName();
String href = project.getNamespace();
File testCSV = new File(repository.getDirectory(), "/tests/tests.csv");
File versionSite = new File(siteManager.siteDir, version.getVersionPath());
FileUtils.forceMkdir(versionSite);
File testHTML = new File(versionSite, "tests.html");
GenerateRDFaManager.GenerateRDFa(categoryChanger, repoName, href, testCSV, testHTML, "tests");
}
}
......@@ -45,7 +45,7 @@ public class SAREFNamedGraph {
return false;
if (getClass() != obj.getClass())
return false;
SAREFTerm other = (SAREFTerm) obj;
SAREFNamedGraph other = (SAREFNamedGraph) obj;
if (iri == null) {
if (other.iri != null)
return false;
......
/*
* 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 com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import fr.emse.gitlab.saref.Main;
import org.apache.commons.io.IOUtils;
import org.eclipse.jgit.util.StringUtils;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class GenerateRDFaManager {
public static void GenerateRDFa(String categoryChanger, String repoName, String href, File CSV, File HTML,
String identifier) {
String row = "";
try (FileWriter htmlWriter = new FileWriter(HTML);
BufferedReader csvReader = new BufferedReader(new FileReader(CSV));) {
String header = IOUtils.toString(Main.class.getClassLoader().getResourceAsStream("themis/header.html"),
StandardCharsets.UTF_8);
String body = IOUtils.toString(Main.class.getClassLoader().getResourceAsStream("themis/body.html"),
StandardCharsets.UTF_8);
String footer = IOUtils.toString(Main.class.getClassLoader().getResourceAsStream("themis/footer.html"),
StandardCharsets.UTF_8);
header = header.replaceAll("@ontologyName", repoName).replaceAll("@href", href + "/" + identifier + "/");
body = body.replaceAll("@docType", StringUtils.capitalize(identifier)).replaceAll("@ontologyName",
repoName);
htmlWriter.write(header);
htmlWriter.write(body);
List<String[]> allData = readDataFromCustomSeperator(CSV);
if (identifier.equals("requirements")) {
for (String[] data : allData) {
if (data[1].equals("Category")) {
continue;
} else {
if (categoryChanger.equals("") || categoryChanger.equals(data[1])
|| !data[1].equals("Category")) {
if (!categoryChanger.equals(data[1]) && !categoryChanger.equals("Category")) {
if (categoryChanger.equals("")) {
categoryChanger = data[1];
} else {
categoryChanger = data[1];
String endTableData = "</table> \n" + "\n" + "<p>\n" + "</p>\n" + "\n";
htmlWriter.write(endTableData);
}
categoryChanger = data[1];
String entrytoTable2 = "<table align=\"center\" border=\"1\" prefix=\"vtc: https://w3id.org/def/vtc#\">\n";
htmlWriter.write(entrytoTable2);
String category = "<caption>Requirements for the \"" + categoryChanger
+ "\" category</caption>\n";
htmlWriter.write(category);
String entry = "<tr>\n" + " <th>Id</th>\n" + " <th>Requirement</th>\n"
+ " </tr>\n" + "\n" + "<tr id=\"" + data[0] + "\" resource=\"requirement/"
+ data[0] + "\" typeof=\"vtc:Requirement\" property=\"vtc:category\" content=\""
+ data[1] + "\">\n" + " <td property=\"vtc:requirementId\">" + data[0]
+ "</td>\n" + " <td property=\"dc:description\">" + data[2] + "</td>\n"
+ " </tr>\n" + "\n";
htmlWriter.write(entry);
} else {
categoryChanger = data[1];
String entry = "<tr id=\"" + data[0] + "\" resource=\"requirement/" + data[0]
+ "\" typeof=\"vtc:Requirement\" property=\"vtc:category\" content=\"" + data[1]
+ "\">\n" + " <td property=\"vtc:requirementId\">" + data[0] + "</td>\n"
+ " <td property=\"dc:description\">" + data[2] + "</td>\n" + " </tr>\n"
+ "\n";
htmlWriter.write(entry);
}
}
}
}
} else {
for (String[] data : allData) {
if (data[2].equals("Category")) {
continue;
} else {
if (categoryChanger.equals("") || categoryChanger.equals(data[2])
|| !data[2].equals("Category")) {
if (!categoryChanger.equals(data[2]) && !categoryChanger.equals("Category")) {
if (categoryChanger.equals("")) {
categoryChanger = data[2];
} else {
categoryChanger = data[2];
String endTableData2 = "</table> \n" + "\n" + "<p>\n" + "</p>\n" + "\n";
htmlWriter.write(endTableData2);
}
categoryChanger = data[2];
String entrytoTable2 = "<table align=\"center\" border=\"1\" prefix=\"vtc: https://w3id.org/def/vtc#\">\n";
htmlWriter.write(entrytoTable2);
String category = "<caption>Tests for the \"" + categoryChanger
+ "\" category</caption>\n";
htmlWriter.write(category);
if (!data[1].isEmpty()) {
String entry = "<tr>\n" + " <th>Id</th>\n" + " <th>Requirement</th>\n"
+ " <th>Test</th>\n" + " </tr>\n" + "\n" + "<tr id=\"" + data[1]
+ "\" resource=\"testCaseDesign/" + data[0]
+ "\" typeof=\"vtc:TestCaseDesign\">\n" + " <td property=\"vtc:testId\">"
+ data[0] + "</td>\n"
+ " <td><span property=\"vtc:comesFromRequirement\" href=\"requirement/"
+ data[1] + "\"><a href=\"requirements.html#" + data[1] + "\">"
+ data[1] + "</a></span></td>\n"
+ " <td property=\"vtc:desiredBehaviour\">" + data[3] + "</td>\n"
+ " </tr>\n" + "\n";
htmlWriter.write(entry);
} else {
String entry = "<tr>\n" + " <th>Id</th>\n" + " <th>Test</th>\n" + " </tr>\n"
+ "\n" + "<tr resource=\"testCaseDesign/" + data[0]
+ "\" typeof=\"vtc:TestCaseDesign\">\n" + " <td property=\"vtc:testId\">"
+ data[0] + "</td>\n" + " <td property=\"vtc:desiredBehaviour\">"
+ data[3] + "</td>\n" + " </tr>\n" + "\n";
htmlWriter.write(entry);
}
} else {
categoryChanger = data[2];
String entry = "<tr resource=\"testCaseDesign/" + data[0]
+ "\" typeof=\"vtc:TestCaseDesign\">\n" + " <td property=\"vtc:testId\">"
+ data[0] + "</td>\n"
+ " <td><span property=\"vtc:comesFromRequirement\" href=\"requirement/"
+ data[1] + "\"><a href=\"requirements.html#" + data[1] + "\">"
+ data[1] + "</a></span></td>\n" + " <td property=\"vtc:desiredBehaviour\">"
+ data[3] + "</td>\n" + " </tr>\n" + "\n";
htmlWriter.write(entry);
}
}
}
}
}
String endTableData = "</table> \n" + "\n" + "<p>\n" + "</p>\n" + "\n";
htmlWriter.write(endTableData);
htmlWriter.write(footer);
} catch (IOException e) {
e.printStackTrace();
}
}
public static List<String[]> readDataFromCustomSeperator(File file) {
CSVParser parser = new CSVParserBuilder().withSeparator(';').withQuoteChar('"').build();
try (FileReader filereader = new FileReader(file);
CSVReader csvReader = new CSVReaderBuilder(filereader).withCSVParser(parser).build();) {
// Read all data at once
List<String[]> allData = csvReader.readAll();
return allData;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
/*
* 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<ArrayList<String>> elements = new ArrayList<ArrayList<String>>();
elements.add(getID);
elements.add(getName);
elements.add(getInfo);
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);
}
}
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;
}
}
......@@ -26,20 +26,14 @@
package fr.emse.gitlab.saref.managers;