Browse Source

Fixing the enactment to support the continuation of PMs with ForkJoin
nodes.

Lucas Albertins 2 years ago
parent
commit
e8c27e7754

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

@@ -4,6 +4,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.sql.Timestamp;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -25,6 +26,7 @@ import ua.be.wee.model.EnactmentController;
 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.ForkJoinNode;
 import ua.be.wee.model.nodes.Node;
 import ua.be.wee.model.nodes.ports.ControlInputPort;
 import ua.be.wee.model.nodes.ports.ControlOutputPort;
@@ -150,11 +152,11 @@ public class EnactmentControllerMVC {
 				
 			} else {
 				endActs = findEndActs(events);
-				List<PMTrigger> acts = new ArrayList<PMTrigger>();
+				List<PMTrigger> acts = findStartActs(trace);
 				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(), trace.getIri());
-					acts = findElements(pm, iris);
+					acts.addAll(findElements(pm, iris));
 				}
 				
 				request.getSession().setAttribute("acts",acts);
@@ -171,6 +173,77 @@ public class EnactmentControllerMVC {
     }
     
 
+	private List<PMTrigger> findStartActs(PT trace) throws Exception {
+		PM pmEnacted = trace.getPmEnacted();
+		List<Node> nodes = pmEnacted.getNodes();
+		List<PMTrigger> result = new ArrayList<PMTrigger>();
+		for (Node node : nodes) {
+			if (node instanceof ForkJoinNode) {
+				ForkJoinNode fj = ((ForkJoinNode)node);
+				if (fj.getNextNodes().size() > 1) {
+					List<Pair<String,String>> findNextNodes = controller.findNextNodes(fj.getIri(), trace.getIri());
+					List<String> actIris = new ArrayList<String>();
+					for (Pair<String,String> pair : findNextNodes) {
+						if (pair.getSnd() != null) {
+							actIris.add(pair.getSnd());
+						}
+					}
+					List<String> consider = checkTrace(trace,actIris);
+						
+					for (Iterator<Pair<String,String>> iterator = findNextNodes.iterator(); iterator.hasNext();) {
+						Pair<String,String> pair = iterator.next();
+						
+						if (pair.getSnd() == null) {
+							findNextNodes.remove(pair);
+						} else {
+							boolean found = false;
+							for (String str : consider) {
+								if (str.equals(pair.getSnd())) {
+									found = true;
+									break;
+								}
+							}
+							if (!found) {
+								iterator.remove();
+							}
+						}
+					}
+					
+					result.addAll(findElements(trace.getPmEnacted(), findNextNodes));
+					
+				}
+			}
+		}
+		return result;
+	}
+
+
+	private List<String> checkTrace(PT trace, List<String> actIris) {
+		List<Pair<String,Integer>> pairs = new ArrayList<Pair<String,Integer>>();
+		int max = 0;
+		for (String iri : actIris) {
+			int count = 0;
+			for (Event ev : trace.getEvents()) {
+				if (ev instanceof StartActivityEvent && ((StartActivityEvent)ev).getRelatesTo().getActivity().getIri().equals(iri)) {
+					count++;
+				}
+			}
+			if (count > max) {
+				max = count;
+			}
+			pairs.add(new Pair<String, Integer>(iri, count));
+		}
+		
+		List<String> result = new ArrayList<String>();
+		for (Pair<String, Integer> pair : pairs) {
+			if (pair.getSnd() < max) {
+				result.add(pair.getFst());
+			}
+		}
+		return result;
+		
+	}
+
 	private List<Node> findEndActs(List<Event> events) {
 		List<Node> result = new ArrayList<Node>();
 		for (Event event : events) {
@@ -200,10 +273,10 @@ public class EnactmentControllerMVC {
     	List<PMTrigger> acts = (List<PMTrigger>) request.getSession().getAttribute("acts");
     	List<Node> endacts = (List<Node>) request.getSession().getAttribute("endacts");
     	PMTrigger element = findPMTrigger(acts,iri);
-    	Object arts = request.getSession().getAttribute("arts");
+    	List<TraceArtifact> arts = (List<TraceArtifact>)request.getSession().getAttribute("arts");
     	if (element.getPort() != null) {
     		ControlInputPort port = (ControlInputPort)element.getPort();
-        	controller.addStartEvent(pt,port, port.getActivity(),((List<TraceArtifact>)arts));
+        	controller.addStartEvent(pt,port, port.getActivity(),arts);
         	removeElement(acts,iri);
         	endacts.add(port.getActivity());
         	request.getSession().removeAttribute("arts");
@@ -292,7 +365,6 @@ public class EnactmentControllerMVC {
     
     @RequestMapping("/inarts")
     public String selectActivity(Model model, @RequestParam String iri, HttpServletRequest request) throws Exception {
-    	PM pm = (PM)request.getSession().getAttribute("pm");
     	PT pt = (PT)request.getSession().getAttribute("trace");
     	List<PMTrigger> acts = (List<PMTrigger>) request.getSession().getAttribute("acts");
     	if (!iri.equals("1")) {

+ 1 - 0
src/main/java/ua/be/wee/model/EnactmentController.java

@@ -49,6 +49,7 @@ public class EnactmentController {
 
 	public void addStartEvent(PT pt, ControlInputPort port, Activity act, List<TraceArtifact> arts) throws Exception {
 		traceRepo.createStartEvent(pt,port,act,arts);
+		pmRepo.checkJoinSync(port.getIri(),pt.getIri());
 	}
 
 	public void addEndEvent(PT pt, List<TraceArtifact> arts, ControlOutputPort p) throws Exception {

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

@@ -37,7 +37,7 @@ public class NodeRespository {
 				+ "PREFIX ob: <http://ua.be/sdo2l/vocabulary/formalisms/object_diagram#>\n"
 				+ "SELECT ?node ?nodetype WHERE {\n" + "  ?pm a pm:Model ;\n" + "  	ob:hasName ?pmName ;\n"
 				+ "  	owl:sameAs <" + pm.getIri() + "> ;\n" + "  	ob:hasObject ?node .\n" + "  ?node a ?nodetype .\n"
-				+ "  FILTER (?nodetype in (pm:Initial, pm:Activity, pm:Final, pm:Join, pm:Fork, pm:Artifact)) .      \n"
+				+ "  FILTER (?nodetype in (pm:Initial, pm:Activity, pm:Final, pm:ForkJoin, pm:Artifact)) .      \n"
 				+ "}";
 		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
 		while (results.hasNext()) {
@@ -131,7 +131,7 @@ public class NodeRespository {
 				+ "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:Initial, pm:Final,pm:Fork, pm:Join)) \n"
+				+ "	FILTER (?nodetype in (pm:CtrlOutputPort, pm:Initial, pm:Final,pm:ForkJoin)) \n"
 				+ "	OPTIONAL {\n" + "		?next pm:ofActivity ?act .\n" + "	}\n" + "}";
 		List<Node> list = new ArrayList<Node>();
 		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
@@ -157,7 +157,7 @@ public class NodeRespository {
 		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:CtrlInputPort, pm:Final,pm:Fork, pm:Join)) \n"
+				+ "  ?next a ?nodetype ;\n" + "	FILTER (?nodetype in (pm:CtrlInputPort, pm:Final,pm:ForkJoin)) \n"
 				+ "	OPTIONAL {\n" + "		?next pm:ofActivity ?act .\n" + "	}\n" + "}";
 		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
 		while (results.hasNext()) {

+ 37 - 2
src/main/java/ua/be/wee/model/repository/PMRepository.java

@@ -138,7 +138,7 @@ public class PMRepository {
 			list.add(inCtrl);
 		}
 		if (list.size() == 1 && list.get(0).equals(input)) {
-			deleteJoinSync(sync);
+			insertRealizedInputInJoinSync(sync,input);
 			return true; 
 		} else if (list.size() == 1 && !list.get(0).equals(input)) {
 			return false;
@@ -148,6 +148,8 @@ public class PMRepository {
 					insertRealizedInputInJoinSync(sync,input);
 				}
 			}
+		} else if (list.isEmpty()) {
+			return true;
 		}
 		return false;
 		
@@ -155,7 +157,7 @@ public class PMRepository {
 
 	private void insertRealizedInputInJoinSync(String sync, String input) throws Exception {
 		String query = "PREFIX tr: <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#>\n"
-				+ "INSERT {\n"
+				+ "INSERT DATA {\n"
 				+ "GRAPH <"+ PT.TRACE_GRAPH_IRI + "> {"
 				+ "	<"+ sync + "> tr:input <" + input + "> .\n"
 				+ "	}"
@@ -214,5 +216,38 @@ public class PMRepository {
 		results.next();
 		return results.hasNext();
 	}
+
+	public void checkJoinSync(String portiri, String traceiri) 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 DISTINCT ?sync WHERE {\n"
+				+ "  ?inCtrl owl:sameAs <" + portiri + "> .\n"
+				+ "  {?node pm:ctrlTo ?inCtrl .}\n"
+				+ "  UNION\n"
+				+ "  {?inCtrl pm:ctrlFrom+ ?node . }\n"
+				+ "  ?node a pm:ForkJoin .\n"
+				+ "  ?sync tr:nodeIRI ?node .\n"
+				+ "  ?sync tr:trace <" + traceiri +"> .\n"
+				+ "  FILTER NOT EXISTS { \n"
+				+ "  	?in pm:ctrlTo ?node . \n"
+				+ "    FILTER NOT EXISTS {\n"
+				+ "   		?sync tr:input ?in .\n"
+				+ "    }\n"
+				+ "  }\n"
+				+ "}";
+		ResultSet results = FusekiWrapper.getInstance().execQuery(query);
+		while (results.hasNext()) {
+			QuerySolution soln = results.nextSolution();
+			String sync = soln.get("?sync").toString();
+			list.add(sync);
+		}
+		
+		for (String sync : list) {
+			deleteJoinSync(sync);
+		}
+		
+	}
 	
 }