Skip to content
Snippets Groups Projects
Commit 3fe37802 authored by David Gnabasik's avatar David Gnabasik
Browse files

Worked on ShaclValidationManager.

parent ddb520ba
No related branches found
No related tags found
No related merge requests found
......@@ -37,9 +37,8 @@ import java.nio.file.Paths;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import com.fasterxml.jackson.core.type.TypeReference;
//import java.util.HashMap;
import org.apache.commons.lang3.StringEscapeUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.mines_stetienne.ci.saref.SAREFPipelineException;
......@@ -52,7 +51,7 @@ public class ShaclValidationManager {
private static String VALIDATOR_URL = "http://localhost:8080/shacl/";
private final String TEXT_TURTLE = "text/turtle";
private final String JSON_FORMAT = "application/json";
private final String JSON_FORMAT = "application/json"; // application/x-www-form-urlencoded
private final String STRING_FORMAT = "STRING";
private String ontologyToValidate; // file:///home/davidgnabasik/dev/real_saref4auto/ontology/saref4auto.ttl or URL
......@@ -177,7 +176,7 @@ public class ShaclValidationManager {
try {
String fileStr = new String(Files.readAllBytes(Paths.get(readingFile)));
RuleSet ruleSet = new RuleSet();
ruleSet.setRuleSet(fileStr.replaceAll("[\n]","\r\n")); // still need to json-escape.
ruleSet.setRuleSet(fileStr); //.replaceAll("[\n]","\r\n"));
this.shaclFileList.add(readingFile);
this.ruleSetList.add(ruleSet);
} catch (IOException ex) {
......@@ -200,7 +199,7 @@ public class ShaclValidationManager {
try {
String fileStr = new String(Files.readAllBytes(Paths.get(this.ontologyToValidate)));
this.validationRequest = new ValidationRequest();
this.validationRequest.setContentToValidate(fileStr.replaceAll("[\n]","\r\n")); // still need to json-escape.
this.validationRequest.setContentToValidate(fileStr); // .replaceAll("[\n]","\r\n"));
this.validationRequest.setExternalRules(this.ruleSetList);
} catch (IOException ex) {
throw new SAREFPipelineException("ShaclValidationManager", "Unable to read ontology file: " + this.ontologyToValidate);
......@@ -238,17 +237,14 @@ public class ShaclValidationManager {
try {
createValidationRequest(shaclFileList);
//String json = this.objectMapper.writeValueAsString(this.validationRequest);
//String escapedJson = StringEscapeUtils.escapeJson(json);
//Map<String, Object> postMap = this.objectMapper.convertValue(this.validationRequest, new TypeReference<Map<String, Object>>() {});
Map<String, Object> data = new HashMap<>();
data.put("fistname", "admin");
System.out.println("ValidateOntologyWithShacl...");//<<<
String jsonStr = this.objectMapper.writeValueAsString(this.validationRequest);
String escapedJson = StringEscapeUtils.escapeJson(jsonStr);
System.out.println(escapedJson);//<<<
HttpRequest request = HttpRequest.newBuilder()
.header("Content-Type", TEXT_TURTLE) // application/x-www-form-urlencoded
.header("Content-Type", JSON_FORMAT)
.uri(URI.create(VALIDATOR_URL + "any/upload")) // any/api/validate
.POST(ofForm(data))
.POST(HttpRequest.BodyPublishers.ofString(jsonStr)) // escapedJson
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
......
server_unavailable=The validation server is unavailable at `%s`
ioexception=Error while accessing the local file system
missing=The shacl directory should contain at least one file. This file shall conform to the pattern specification as defined in clause 9.4.6 in TS 103 673.
one=If a shacl directory exists, it should contain at least one shapes.ttl file.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment