瀏覽代碼

Adding some exceptions when no data is returned for some of the queries.

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

+ 14 - 8
src/main/java/ua/be/wee/model/repository/PMRepository.java

@@ -37,7 +37,7 @@ public class PMRepository {
 		return list;
 	}
 
-	public PM getPM(String pmiri) {
+	public PM getPM(String pmiri) throws Exception {
 		String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
 				+ "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n"
 				+ "PREFIX obj: <http://ua.be/sdo2l/vocabulary/formalisms/object_diagram#>\n"
@@ -47,13 +47,19 @@ public class PMRepository {
 				+ "  	owl:sameAs <" + pmiri + "> .\n"
 				+ "}";
 		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
-		PM pm = new PM();
-		QuerySolution soln = results.nextSolution();
-		RDFNode iri = soln.get("?pm");
-		RDFNode name = soln.get("?pmName");
-		pm.setIri(iri.toString());
-		pm.setName(name.toString());
-		return pm;
+		
+		if (results.hasNext()) {
+			PM pm = new PM();
+			QuerySolution soln = results.nextSolution();
+			RDFNode iri = soln.get("?pm");
+			RDFNode name = soln.get("?pmName");
+			pm.setIri(iri.toString());
+			pm.setName(name.toString());
+			return pm;
+		} else {
+			throw new Exception("No data returned by query: \n" + query );
+		}
+		
 	}
 
 	public List<Pair<String,String>> findNextNodes(String iri) {

+ 1 - 1
src/main/java/ua/be/wee/model/repository/PTRepository.java

@@ -483,7 +483,7 @@ public class PTRepository {
 	}
 
 	
-	public List<StartTraceEvent> getStartTraceEvents() {
+	public List<StartTraceEvent> getStartTraceEvents() throws Exception {
 		List<StartTraceEvent> list = new ArrayList<StartTraceEvent>();
 		String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
 				+ "PREFIX tr: <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#>\n"