Browse Source

Adding support to concurrent flows in WEE.

Lucas Albertins 2 years ago
parent
commit
0578fb66d7

+ 4 - 4
src/main/java/ua/be/wee/controller/EnactmentControllerMVC.java

@@ -114,7 +114,7 @@ public class EnactmentControllerMVC {
 		} else {
 			PM pm = controller.getPM(pmiri);			
 			PT trace = controller.createTrace(pm);
-			List<Pair<String,String>> iris = controller.findNextNodes(pm.getInitial().getIri());
+			List<Pair<String,String>> iris = controller.findNextNodes(pm.getInitial().getIri(), trace.getIri());
 			List<PMTrigger> acts = findElements(pm, iris);
 			model.addAttribute("error", false);
 			request.getSession().setAttribute("pm", pm);
@@ -144,7 +144,7 @@ public class EnactmentControllerMVC {
 			trace.setPmEnacted(pm);
 			List <Node> endActs = new ArrayList<Node>();
 			if (events.size() == 1) {
-				List<Pair<String,String>> iris = controller.findNextNodes(pm.getInitial().getIri());
+				List<Pair<String,String>> iris = controller.findNextNodes(pm.getInitial().getIri(), trace.getIri());
 				List<PMTrigger> acts = findElements(pm, iris);
 				request.getSession().setAttribute("acts",acts);
 				
@@ -153,7 +153,7 @@ public class EnactmentControllerMVC {
 				List<PMTrigger> acts = new ArrayList<PMTrigger>();
 				if (events.get(events.size()-1) instanceof EndActivityEvent) {
 					EndActivityEvent last = (EndActivityEvent)events.get(events.size()-1);
-					List<Pair<String,String>> iris = controller.findNextNodes(last.getRelatesTo().getIri());
+					List<Pair<String,String>> iris = controller.findNextNodes(last.getRelatesTo().getIri(), trace.getIri());
 					acts = findElements(pm, iris);
 				}
 				
@@ -261,7 +261,7 @@ public class EnactmentControllerMVC {
 			}
 		}	
 
-    	List<Pair<String,String>> iris = controller.findNextNodes(p.getIri());
+    	List<Pair<String,String>> iris = controller.findNextNodes(p.getIri(), pt.getIri());
         acts.addAll(findElements(pm, iris));
 
     	request.getSession().setAttribute("trace", pt);

+ 2 - 3
src/main/java/ua/be/wee/model/EnactmentController.java

@@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import ua.be.wee.model.nodes.Activity;
-import ua.be.wee.model.nodes.Artifact;
 import ua.be.wee.model.nodes.ports.ControlInputPort;
 import ua.be.wee.model.nodes.ports.ControlOutputPort;
 import ua.be.wee.model.pm.PM;
@@ -40,8 +39,8 @@ public class EnactmentController {
 		return pm;
 	}
 
-	public List<Pair<String,String>> findNextNodes(String iri) {
-		return pmRepo.findNextNodes(iri); 
+	public List<Pair<String,String>> findNextNodes(String iri, String trace) throws Exception {
+		return pmRepo.findNextNodes(iri, trace); 
 	}
 
 	public PT createTrace(PM pm) throws Exception {

+ 7 - 9
src/main/java/ua/be/wee/model/nodes/ForkNode.java

@@ -2,26 +2,24 @@ package ua.be.wee.model.nodes;
 
 import java.util.List;
 
-import javax.persistence.CascadeType;
 import javax.persistence.Entity;
 import javax.persistence.OneToMany;
-import javax.persistence.OneToOne;
 
 @Entity
-public class ForkNode extends Node {
+public class ForkJoinNode extends Node {
 
-	@OneToOne(cascade = CascadeType.ALL)
-	private Node previous;
+	@OneToMany
+	private List<Node> previousNodes;
 	
 	@OneToMany
 	private List<Node> nextNodes;
 
-	public Node getPrevious() {
-		return previous;
+	public List<Node> getPrevious() {
+		return previousNodes;
 	}
 
-	public void setPrevious(Node previous) {
-		this.previous = previous;
+	public void setPrevious(List<Node> previous) {
+		this.previousNodes = previous;
 	}
 
 	public List<Node> getNextNodes() {

+ 0 - 35
src/main/java/ua/be/wee/model/nodes/JoinNode.java

@@ -1,35 +0,0 @@
-package ua.be.wee.model.nodes;
-
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.OneToMany;
-import javax.persistence.OneToOne;
-
-@Entity
-public class JoinNode extends Node {
-	
-	@OneToMany
-	private List<Node> previousNodes;
-	
-	@OneToOne(cascade = CascadeType.ALL)
-	private Node next;
-
-	public List<Node> getPreviousNodes() {
-		return previousNodes;
-	}
-
-	public void setPreviousNodes(List<Node> previousNodes) {
-		this.previousNodes = previousNodes;
-	}
-
-	public Node getNext() {
-		return next;
-	}
-
-	public void setNext(Node next) {
-		this.next = next;
-	}
-
-}

+ 1 - 2
src/main/java/ua/be/wee/model/nodes/Node.java

@@ -17,9 +17,8 @@ import ua.be.wee.model.NamedElement;
 		  @Type(value = Activity.class), 
 		  @Type(value = Artifact.class),
 		  @Type(value = FinalNode.class),
-		  @Type(value = ForkNode.class),
+		  @Type(value = ForkJoinNode.class),
 		  @Type(value = InitialNode.class),
-		  @Type(value = JoinNode.class)
 		})
 @Entity
 public abstract class Node implements NamedElement {

+ 11 - 70
src/main/java/ua/be/wee/model/repository/NodeRespository.java

@@ -12,9 +12,8 @@ import org.springframework.stereotype.Repository;
 import ua.be.wee.model.nodes.Activity;
 import ua.be.wee.model.nodes.Artifact;
 import ua.be.wee.model.nodes.FinalNode;
-import ua.be.wee.model.nodes.ForkNode;
+import ua.be.wee.model.nodes.ForkJoinNode;
 import ua.be.wee.model.nodes.InitialNode;
-import ua.be.wee.model.nodes.JoinNode;
 import ua.be.wee.model.nodes.Node;
 import ua.be.wee.model.nodes.ports.ControlInputPort;
 import ua.be.wee.model.nodes.ports.ControlOutputPort;
@@ -64,83 +63,25 @@ public class NodeRespository {
 				updateInitialNode(nodes, (InitialNode) node);
 			} else if (node instanceof FinalNode) {
 				updateFinalNode(nodes, (FinalNode) node);
-			} else if (node instanceof ForkNode) {
-				updateForkNode(nodes, (ForkNode) node);
-			} else if (node instanceof JoinNode) {
-				updateJoinNode(nodes, (JoinNode) node);
+			} else if (node instanceof ForkJoinNode) {
+				updateForkJoinNode(nodes, (ForkJoinNode) node);
 			}
 		}
 
 	}
 
-	private void updateJoinNode(List<Node> nodes, JoinNode node) {
+	private void updateForkJoinNode(List<Node> nodes, ForkJoinNode node) {
 		String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
-				+ "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n" + "SELECT ?next ?nodetype ?act\n"
-				+ "WHERE { \n" + "  ?node owl:sameAs<" + node.getIri() + ">.\n" + "  ?node pm:ctrlTo ?next.\n"
-				+ "  ?next a ?nodetype ;\n"
-				+ "	FILTER (?nodetype in (pm:CtrlOutputPort, pm:Initial, pm:Final,pm:Fork, pm:Join)) \n"
-				+ "	OPTIONAL {\n" + "		?next pm:ofActivity ?act .\n" + "	}\n" + "}";
-		List<Node> list = new ArrayList<Node>();
-		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
-		while (results.hasNext()) {
-			QuerySolution soln = results.nextSolution();
-			RDFNode type = soln.get("?nodetype");
-			String nextIri;
-			if (type.toString().equals(Node.CTRL_OUTPUT_PORT_IRI)) {
-				nextIri = soln.get("?act").toString();
-			} else {
-				nextIri = soln.get("?next").toString();
-			}
-			for (Node node2 : nodes) {
-				if (node2.getIri().equals(nextIri)) {
-					list.add(node2);
-				}
-			}
-		}
-		node.setPreviousNodes(list);
-		
-		
-		query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
 				+ "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n" 
 				+ "SELECT ?next ?nodetype ?act\n"
 				+ "WHERE { \n" + "  ?node owl:sameAs<" + node.getIri() + ">.\n" 
 				+ "  ?node pm:ctrlFrom ?next.\n"
 				+ "  ?next a ?nodetype ;\n"
-				+ "	FILTER (?nodetype in (pm:CtrlOutputPort,pm:Fork, pm:Join, pm:Initial)) \n" 
-				+ "	OPTIONAL {\n"
-				+ "		?next pm:ofActivity ?act .\n" + "	}\n" + "}";
-		results = FusekiWrapper.getInstance().execQuery(query);
-		while (results.hasNext()) {
-			QuerySolution soln = results.nextSolution();
-			RDFNode type = soln.get("?nodetype");
-			String nextIri;
-			if (type.toString().equals(Node.CTRL_OUTPUT_PORT_IRI)) {
-				nextIri = soln.get("?act").toString();
-			} else {
-				nextIri = soln.get("?next").toString();
-			}
-			for (Node node2 : nodes) {
-				if (node2.getIri().equals(nextIri)) {
-					node.setNext(node2);
-					break;
-				}
-			}
-		}
-
-		
-	}
-
-	private void updateForkNode(List<Node> nodes, ForkNode node) {
-		String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
-				+ "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n" 
-				+ "SELECT ?next ?nodetype ?act\n"
-				+ "WHERE { \n" + "  ?node owl:sameAs<" + node.getIri() + ">.\n" 
-				+ "  ?node pm:ctrlFrom ?next.\n"
-				+ "  ?next a ?nodetype ;\n"
-				+ "	FILTER (?nodetype in (pm:CtrlOutputPort,pm:Fork, pm:Join, pm:Initial)) \n" 
+				+ "	FILTER (?nodetype in (pm:CtrlOutputPort,pm:ForkJoin, pm:Initial)) \n" 
 				+ "	OPTIONAL {\n"
 				+ "		?next pm:ofActivity ?act .\n" + "	}\n" + "}";
 		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
+		List<Node> list = new ArrayList<Node>();
 		while (results.hasNext()) {
 			QuerySolution soln = results.nextSolution();
 			RDFNode type = soln.get("?nodetype");
@@ -152,19 +93,19 @@ public class NodeRespository {
 			}
 			for (Node node2 : nodes) {
 				if (node2.getIri().equals(nextIri)) {
-					node.setPrevious(node2);
-					break;
+					list.add(node2);
 				}
 			}
 		}
+		node.setPrevious(list);
 
 		query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
 				+ "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n" + "SELECT ?next ?nodetype ?act\n"
 				+ "WHERE { \n" + "  ?node owl:sameAs<" + node.getIri() + ">.\n" + "  ?node pm:ctrlTo ?next.\n"
 				+ "  ?next a ?nodetype ;\n"
-				+ "	FILTER (?nodetype in (pm:CtrlInputPort, pm:Initial, pm:Final,pm:Fork, pm:Join)) \n"
+				+ "	FILTER (?nodetype in (pm:CtrlInputPort, pm:Initial, pm:Final,pm:ForkJoin)) \n"
 				+ "	OPTIONAL {\n" + "		?next pm:ofActivity ?act .\n" + "	}\n" + "}";
-		List<Node> list = new ArrayList<Node>();
+		list.clear();
 		results = FusekiWrapper.getInstance().execQuery(query);
 		while (results.hasNext()) {
 			QuerySolution soln = results.nextSolution();
@@ -297,7 +238,7 @@ public class NodeRespository {
 			break;
 		case Node.FORKJOIN_IRI:
 			// addlogic for fork join
-			node = new JoinNode();
+			node = new ForkJoinNode();
 			break;
 		case Node.ARTIFACT_IRI:
 			// addlogic for fork join

+ 131 - 7
src/main/java/ua/be/wee/model/repository/PMRepository.java

@@ -10,6 +10,7 @@ import org.springframework.stereotype.Repository;
 
 import ua.be.wee.model.nodes.Node;
 import ua.be.wee.model.pm.PM;
+import ua.be.wee.model.pt.PT;
 import ua.be.wee.model.util.Pair;
 
 @Repository
@@ -62,15 +63,15 @@ public class PMRepository {
 		
 	}
 
-	public List<Pair<String,String>> findNextNodes(String iri) {
+	public List<Pair<String,String>> findNextNodes(String iri, String trace) throws Exception {
 		List<Pair<String,String>> list = new ArrayList<Pair<String,String>>();
 		String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
 				+ "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n"
 				+ "SELECT ?e ?nodetype ?act WHERE {\n"
 				+ "  ?node owl:sameAs <" + iri + "> .\n"
-				+ "  ?node pm:ctrlTo+ ?e .\n"
+				+ "  ?node pm:ctrlTo ?e .\n"
 				+ "  ?e a ?nodetype ;\n"
-				+ "  FILTER (?nodetype in (pm:CtrlInputPort, pm:Final)) \n"
+				+ "  FILTER (?nodetype in (pm:CtrlInputPort, pm:Final, pm:ForkJoin)) \n"
 				+ "	 OPTIONAL {\n"
 				+ "		?e pm:ofActivity ?act .\n"
 				+ "	 }\n"
@@ -79,16 +80,139 @@ public class PMRepository {
 		while (results.hasNext()) {
 			QuerySolution soln = results.nextSolution();
 			RDFNode type = soln.get("?nodetype");
-			Pair<String,String> pair;
+			Pair<String,String> pair = null;
 			if (type.toString().equals(Node.CTRL_INPUT_PORT_IRI)) {
 				pair = new Pair<String,String>(soln.get("?e").toString(),soln.get("?act").toString());
+			} else if (type.toString().equals(Node.FORKJOIN_IRI)) {
+				if (isJoin(soln.get("?e").toString())) {
+					if (checkJoin(soln.get("?e").toString(), trace, iri)) {
+						list.addAll(findNextNodes(soln.get("?e").toString(), trace));
+					}
+				} else {
+					list.addAll(findNextNodes(soln.get("?e").toString(), trace));
+				}
 			} else {
 				pair = new Pair<String,String>(soln.get("?e").toString(), null);
 			}
-			list.add(pair);
-			
+			if (pair != null) {
+				list.add(pair);
+			}
 		}
 		return list;
-	}	
+	}
+
+	private boolean checkJoin(String node, String trace, String input) throws Exception {
+		String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
+				+ "PREFIX tr: <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#>\n"
+				+ "SELECT ?sync WHERE {\n"
+				+ "  ?sync a tr:JoinSync .\n"
+				+ "  ?sync tr:nodeIRI <" + node + "> .\n"
+				+ "  ?sync tr:trace <" + trace + "> .\n"
+				+ "}";
+		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
+		if (results.hasNext()) {
+			QuerySolution soln = results.nextSolution();
+			String sync = soln.get("?sync").toString();
+			return checkInputs(sync,node,trace,input);
+		} else {
+			createJoinSync(node,trace,input);
+			return false;
+		}
+	}
+
+	private boolean checkInputs(String sync, String node, String trace, String input) throws Exception {
+		List<String> list = new ArrayList<String>();
+		String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
+				+ "PREFIX tr: <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#>\n"
+				+ "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n"
+				+ "SELECT ?inCtrl WHERE {\n"
+				+ "  ?sync owl:sameAs  <" + sync + "> .\n"
+				+ "  ?sync tr:nodeIRI ?node .\n"
+				+ "  ?inCtrl pm:ctrlTo ?node .\n"
+				+ "  FILTER NOT EXISTS { ?sync tr:input ?inCtrl } \n"
+				+ "}";
+		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
+		while (results.hasNext()) {
+			QuerySolution soln = results.nextSolution();
+			String inCtrl = soln.get("?inCtrl").toString();
+			list.add(inCtrl);
+		}
+		if (list.size() == 1 && list.get(0).equals(input)) {
+			deleteJoinSync(sync);
+			return true; 
+		} else if (list.size() == 1 && !list.get(0).equals(input)) {
+			return false;
+		} else if (list.size() > 1) {
+			for (String inCtrl : list) {
+				if (inCtrl.equals(input)) {
+					insertRealizedInputInJoinSync(sync,input);
+				}
+			}
+		}
+		return false;
+		
+	}
+
+	private void insertRealizedInputInJoinSync(String sync, String input) throws Exception {
+		String query = "PREFIX tr: <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#>\n"
+				+ "INSERT {\n"
+				+ "GRAPH <"+ PT.TRACE_GRAPH_IRI + "> {"
+				+ "	<"+ sync + "> tr:input <" + input + "> .\n"
+				+ "	}"
+				+ "} ";
+		if (!FusekiWrapper.getInstance().updateQuery(query) ) {
+			throw new Exception("Error inserting data.");
+		}
+	}
+
+	private void deleteJoinSync(String sync) throws Exception {
+		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"
+				+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
+				+ "PREFIX base: <http://ua.be/sdo2l/vocabulary/base/acyclic#>\n"
+				+ "DELETE { "
+				+ "GRAPH <"+ PT.TRACE_GRAPH_IRI + "> {"
+				+ "	?sync ?p ?v . }\n"
+				+ "}"
+				+ "WHERE { \n"
+				+ "  ?sync a tr:JoinSync .\n"
+				+ "  ?sync owl:sameAs <" + sync + "> .\n"
+				+ "  ?sync ?p ?v .\n"
+				+ "};\n";	
+		if (!FusekiWrapper.getInstance().updateQuery(query) ) {
+			throw new Exception("Error inserting data.");
+		}
+	}
+
+	private void createJoinSync(String node, String trace, String input) throws Exception {
+		String sync = trace + "_" + node.split("#")[1];
+		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"
+				+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
+				+ "INSERT DATA {\n"
+				+ "GRAPH <"+ PT.TRACE_GRAPH_IRI + "> {"
+				+ "	<"+ sync + "> rdf:type <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#JoinSync> , owl:Thing ;\n"
+				+ "    	tr:nodeIRI <" + node + "> ;\n"
+				+ " 	tr:trace <" + trace + "> ;\n"
+				+ " 	tr:input <" + input + "> ;\n"
+				+ "     owl:sameAs  <" + sync + "> .\n"
+				+ "	} \n"
+				+ "}; ";
+		if (!FusekiWrapper.getInstance().updateQuery(query) ) {
+			throw new Exception("Error inserting data.");
+		}
+	}
+
+	private boolean isJoin(String iri) {
+		String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
+				+ "PREFIX pm: <http://ua.be/sdo2l/vocabulary/formalisms/pm#>\n"
+				+ "SELECT ?input WHERE {\n"
+				+ "  ?node owl:sameAs <" + iri + "> .\n"
+				+ "  ?input pm:ctrlTo ?node .\n"
+				+ "}";
+		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
+		results.next();
+		return results.hasNext();
+	}
 	
 }