瀏覽代碼

- Adding the setting of the endpoint by the RestControllers without the
need to start the web interface.

Lucas Albertins 2 年之前
父節點
當前提交
ff06aa7c9b

+ 9 - 0
src/main/java/ua/be/wee/controller/rest/NodeController.java

@@ -3,12 +3,14 @@ package ua.be.wee.controller.rest;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RestController;
 
 import ua.be.wee.model.nodes.Node;
+import ua.be.wee.model.repository.FusekiWrapper;
 import ua.be.wee.model.repository.NodeRespository;
 
 @RestController
@@ -17,6 +19,13 @@ public class NodeController {
 	@Autowired
 	private NodeRespository nodesRepo;
 	
+	@Autowired
+	public NodeController(@Value("${endpoint}")final String endpoint) throws Exception {
+		if (FusekiWrapper.getInstance().getServiceURI() == null) {
+			FusekiWrapper.getInstance().setServiceURI(endpoint);
+		}
+	} 
+	
 	@CrossOrigin
 	@GetMapping("/nodes/{pmIRI}")
 	public List<Node> all(@PathVariable String pmIRI) throws Exception {

+ 9 - 1
src/main/java/ua/be/wee/controller/rest/PMController.java

@@ -3,6 +3,7 @@ package ua.be.wee.controller.rest;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -23,6 +24,13 @@ public class PMController {
 	
 	@Autowired
 	private NodeRespository nodesRepo;
+	
+	@Autowired
+	public PMController(@Value("${endpoint}")final String endpoint) throws Exception {
+		if (FusekiWrapper.getInstance().getServiceURI() == null) {
+			FusekiWrapper.getInstance().setServiceURI(endpoint);
+		}
+	} 
 
 	@CrossOrigin
 	@GetMapping("/pms")
@@ -44,7 +52,7 @@ public class PMController {
 	
 	@CrossOrigin
 	@PutMapping("/endpoint")
-	public boolean setEndpoint(@RequestBody String url) {
+	public boolean setEndpoint(@RequestBody String url) throws Exception {
 		FusekiWrapper.getInstance().setServiceURI(url);
 		return FusekiWrapper.getInstance().testEndpoint();
 	}

+ 11 - 1
src/main/java/ua/be/wee/controller/rest/PTController.java

@@ -3,6 +3,7 @@ package ua.be.wee.controller.rest;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import ua.be.wee.model.pt.Event;
 import ua.be.wee.model.pt.StartTraceEvent;
+import ua.be.wee.model.repository.FusekiWrapper;
 import ua.be.wee.model.repository.PTRepository;
 
 @RestController
@@ -18,9 +20,17 @@ public class PTController {
 	@Autowired
 	private PTRepository ptRepository;
 	
+	
+	@Autowired
+	public PTController(@Value("${endpoint}")final String endpoint) throws Exception {
+		if (FusekiWrapper.getInstance().getServiceURI() == null) {
+			FusekiWrapper.getInstance().setServiceURI(endpoint);
+		}
+	} 
+			
 	@CrossOrigin
 	@GetMapping("/traces")
-	public List<StartTraceEvent> allPTs() {
+	public List<StartTraceEvent> allPTs() throws Exception {
 		return ptRepository.getStartTraceEvents();
 	}
 	

+ 6 - 72
src/main/java/ua/be/wee/model/repository/FusekiWrapper.java

@@ -1,7 +1,5 @@
 package ua.be.wee.model.repository;
 
-import java.io.IOException;
-
 import org.apache.jena.query.QueryExecution;
 import org.apache.jena.query.ResultSet;
 import org.apache.jena.rdfconnection.RDFConnectionFuseki;
@@ -18,7 +16,13 @@ public class FusekiWrapper {
 	
 	private String serviceURI;
 	
+
+	public String getServiceURI() {
+		return serviceURI;
+	}
+
 	private FusekiWrapper() {
+		
 	}
 	
 	public static FusekiWrapper getInstance() {
@@ -62,53 +66,6 @@ public class FusekiWrapper {
 
 	}
 	
-
-//
-//	private static void uploadRDF(File rdf, String serviceURI)
-//			throws IOException {
-//
-//		// parse the file
-//		Model m = ModelFactory.createDefaultModel();
-//		try (FileInputStream in = new FileInputStream(rdf)) {
-//			m.read(in, null, "RDF/XML");
-//		}
-//
-//		// upload the resulting model
-////		DatasetAccessor accessor = DatasetAccessorFactory
-////				.createHTTP(serviceURI);
-////		accessor.putModel(m);
-//	}
-	
-	
-
-//	private static void execSelectAndPrint(String serviceURI, String queryStr) {
-//		
-//		QueryExecution q = QueryExecutionFactory.sparqlService(serviceURI,
-//				queryStr);
-//		ResultSet results = q.execSelect();
-//
-//		ResultSetFormatter.out(System.out, results);
-//
-//		while (results.hasNext()) {
-//			QuerySolution soln = results.nextSolution();
-//			RDFNode x = soln.get("?pm");
-//			System.out.println(x);
-//		}
-//	}
-//
-//	private static void execSelectAndProcess(String serviceURI, String query) {
-//		QueryExecution q = QueryExecutionFactory.sparqlService(serviceURI,
-//				query);
-//		ResultSet results = q.execSelect();
-//
-//		while (results.hasNext()) {
-//			QuerySolution soln = results.nextSolution();
-//			// assumes that you have an "?x" in your query
-//			RDFNode x = soln.get("x");
-//			System.out.println(x);
-//		}
-//	}
-	
 	public boolean testEndpoint() {
 		String query = "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n" 
 				+ "SELECT ?pm WHERE {\n"
@@ -123,27 +80,4 @@ public class FusekiWrapper {
 		}
 		return execSelect.hasNext();
 	}
-
-	public static void main(String[] argv) throws IOException {
-		// uploadRDF(new File("test.rdf"), );
-//		execSelectAndPrint(
-//				"http://localhost:3030/Drivetrain",
-//				"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
-//				+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
-//				+ "PREFIX wf: <http://ua.be/sdo2l/vocabulary/workflow#>\n"
-//				+ "SELECT ?pm ?nodes WHERE {\n"
-//				+ "  ?pm a wf:Workflow .\n"
-//				+ "  ?pm wf:coordinates ?nodes .\n"
-//				+ "}");
-
-//		execSelectAndProcess(
-//				"http://localhost:3030/Drivetrain",
-//				"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
-//				+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
-//				+ "PREFIX wf: <http://ua.be/sdo2l/vocabulary/workflow#>\n"
-//				+ "SELECT ?pm ?nodes WHERE {\n"
-//				+ "  ?pm a wf:Workflow .\n"
-//				+ "  ?pm wf:coordinates ?nodes .\n"
-//				+ "}");
-	}
 }

+ 1 - 1
src/main/resources/application.properties

@@ -1,5 +1,5 @@
 server.port=8081
 base_url=http://localhost:8081/
 spring.application.name=wee
-endpoint=http://localhost:3030/joeri
+endpoint=http://localhost:3030/SystemDesignOntology2Layers
 storageURL=http://localhost:5000