Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
///**
// *
// */
//package fr.emse.gitlab.saref.tests;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.OutputStream;
//import java.nio.file.Path;
//import java.nio.file.Paths;
//import java.util.HashMap;
//import java.util.HashSet;
//import java.util.Map;
//import java.util.Set;
//
//import javax.xml.bind.JAXBContext;
//import javax.xml.bind.JAXBException;
//import javax.xml.bind.Marshaller;
//
//import org.apache.jena.rdf.model.Model;
//import org.apache.jena.rdf.model.Resource;
//import org.apache.jena.riot.Lang;
//import org.apache.jena.riot.RDFDataMgr;
//import org.apache.jena.riot.RDFFormat;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.topbraid.jenax.util.JenaUtil;
//import org.topbraid.shacl.validation.ValidationUtil;
//import org.topbraid.shacl.vocabulary.SH;
//
//import com.fasterxml.jackson.core.sym.Name;
//
//import fr.emse.gitlab.saref.testsuites.TestCase;
//import fr.emse.gitlab.saref.testsuites.TestSuite;
//
///**
// * @author Omar Qawasmeh
// *
// *
// */
//public class ShaclTests {
//
// // private static Logger logger = LoggerFactory.getLogger(Main.class);
//
// public static boolean checkShaclShape(File dataTtl, TestCase tstCase, TestSuite tstSuite, String projectID,
// String projectName) throws FileNotFoundException {
// boolean testResults = true;
//
// // File fileData = new File(dataTtl); // from String to file
// FileInputStream fisDataTtl = new FileInputStream(dataTtl); // from File
// // to FIS
//
// tstCase.setClassName(ShaclTests.class.getName());
// tstCase.setName(new Object() {
// }.getClass().getEnclosingMethod().getName());
//
// try {
//
// Model dataModel = JenaUtil.createDefaultModel(); // data model
// dataModel.read(fisDataTtl, "", Lang.TURTLE.getLabel()); // read the
// // FIS as
// // data
// // model
// // (fisDataTtl)
//
// String shapeTtl = "sarefShape.ttl"; // shape file, fixed.
// // String shapeTtl = "src/main/resources/sarefShape.ttl"; /* shape
// // file, fixed. */
//
// Model shapeModel = JenaUtil.createDefaultModel();
// shapeModel.read(shapeTtl);
//
// Resource reportResource = ValidationUtil.validateModel(dataModel, shapeModel, true);
//
// boolean sameFormat = reportResource.getProperty(SH.conforms).getBoolean();
//
// // logger.trace("Conforms = " + sameFormat);
//
// if (!sameFormat) {
//
// // System.err.println("Errorr! check your ttl format");
// tstCase.setStatus("danger");
// // tstCase.setSystemErr(new String[] { "Your Ttl file violates
// // the Shacl shape format" });
// tstCase.setSystemErr("Your ontology file is missing some metadata");
//
// String report = "shacl-report.ttl";
//
// File reportFile = new File(report);
//
// reportFile.createNewFile();
//
// OutputStream reportOutputStream = new FileOutputStream(reportFile);
// RDFDataMgr.write(reportOutputStream, reportResource.getModel(), RDFFormat.TURTLE);
//
// // Path reportPath = Paths.get(reportOutputStream.toString());
// // System.err.println(reportFile.getAbsolutePath());
//// tstCase.setInfo("You can download the report shape at: \n \n" + "http://saref.gitlab.emse.fr/-/"
//// + projectName + "/-/jobs/" + projectID + "/artifacts/shacl-report.ttl");
//
// // tstSuite.setTestcase(new TestCase[] { tstCase });
// // tstSuite.jaxbObjectToXML(tstSuite);
//
// testResults = false;
//
// // System.exit(42);
//
// } else {
// // System.out.println("Turtle format is ok");
// // tstCase.setSystemOut(new String[] { "Your Ttl file is
// // complete and it follows our shacl shape." });
// tstCase.setSystemOut("Your ontology file contains all the required metadata");
// tstCase.setStatus("success");
// testResults = true;
//
// }
// } catch (Throwable t) {
// testResults = false;
// tstCase.setStatus("danger");
// tstCase.setSystemErr("Your ontology file is missing some metadata");
//
// // tstCase.setSystemErr(new String[] { "Your Ttl file violates the
// // Shacl shape format" });
// // System.err.println(t.getMessage());
// // logger.error(t.getMessage());
// }
//
// return testResults;
//
// }
//
//}