Selaa lähdekoodia

Adding TraceArtifact class and changing the PT to consider this kind of
element in both startActivity and endActivity events.

Lucas Albertins 2 vuotta sitten
vanhempi
commit
60fcfd879a

+ 40 - 10
src/main/java/ua/be/wee/controller/EnactementControllerMVC.java

@@ -2,6 +2,7 @@ package ua.be.wee.controller;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -25,8 +26,10 @@ import ua.be.wee.model.nodes.FinalNode;
 import ua.be.wee.model.nodes.Node;
 import ua.be.wee.model.nodes.ports.ControlOutputPort;
 import ua.be.wee.model.pm.PM;
+import ua.be.wee.model.pt.EndActivityEvent;
 import ua.be.wee.model.pt.Event;
 import ua.be.wee.model.pt.PT;
+import ua.be.wee.model.pt.TraceArtifact;
 import ua.be.wee.model.repository.FusekiWrapper;
 import ua.be.wee.service.FileStorageService;
 
@@ -108,12 +111,13 @@ public class EnactementControllerMVC {
     	List<Node> acts = (List<Node>) request.getSession().getAttribute("acts");
     	List<Node> endacts = (List<Node>) request.getSession().getAttribute("endacts");
     	Node node = pm.getNode(activity);
-    	
+    	Object arts = request.getSession().getAttribute("arts");
     	if (node instanceof Activity) {
-    		List<Artifact> arts = new ArrayList<>();
-        	controller.addStartEvent(pt,(Activity)node,arts);
+
+        	controller.addStartEvent(pt,(Activity)node,((List<TraceArtifact>)arts));
         	acts.remove(node);
         	endacts.add(node);
+        	request.getSession().removeAttribute("arts");
         	return "enact";
 		} else if (node instanceof FinalNode) {
 			String previous = (String)request.getSession().getAttribute("previous");
@@ -147,7 +151,7 @@ public class EnactementControllerMVC {
 		for (String iri : iris) {
 			acts.add(pm.getNode(iri));
 		}
-    	List<Artifact> arts = new ArrayList<>();
+    	List<TraceArtifact> arts = new ArrayList<TraceArtifact>();
     	
     	controller.addEndEvent(pt,act,arts,p);
     	endacts.remove(act);
@@ -177,14 +181,19 @@ public class EnactementControllerMVC {
 		}
     	
     	List<Artifact> arts = act.getOutputs();
+    	List<TraceArtifact> traceArts = new ArrayList<TraceArtifact>();
     	for (Artifact artifact : arts) {
     		ArrayList<Part> parts = (ArrayList<Part>)request.getParts();
     		for (Part part : parts) {
 				if (part.getName().equals(artifact.getName())) {
-					artifact.setLocation(part.getSubmittedFileName());
-					artifact.setTag("v1"); //TODO fix the tag generation
-					artifact.setGUID(part.getSubmittedFileName()+"-" +artifact.getTag());
+					TraceArtifact tArt = new TraceArtifact();
+					tArt.setLocation(part.getSubmittedFileName());
+					tArt.setTag("v1"); //TODO fix the tag generation
+					tArt.setGUID(part.getSubmittedFileName()+"-" +tArt.getTag());
+					tArt.setRelatesTo(artifact);
+					traceArts.add(tArt);
 					storageService.save(part);
+					
 				}
 			}  
 		}
@@ -194,7 +203,7 @@ public class EnactementControllerMVC {
 			acts.add(pm.getNode(iri));
 		}
     	
-    	controller.addEndEvent(pt,act,arts,p);
+    	controller.addEndEvent(pt,act,traceArts,p);
     	endacts.remove(act);
     	
     	
@@ -228,18 +237,39 @@ public class EnactementControllerMVC {
     @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");
     	if (!iri.equals("1")) {
         	if (pm.getNode(iri) instanceof Activity) {
         		Activity act = (Activity)pm.getNode(iri);
         		List<Artifact> inputs = act.getInputs();
-            	model.addAttribute("arts", act.getInputs());
+        		List<TraceArtifact> arts = new ArrayList<TraceArtifact>();
+        		for (Artifact artifact : inputs) {
+        			Timestamp time = Timestamp.valueOf("1900-01-01 00:00:00");
+        			TraceArtifact chosen = null;
+        			for (Event ev : pt.getEvents()) {
+        				if (ev instanceof EndActivityEvent) {
+							List<TraceArtifact> producedArtifacts = ((EndActivityEvent) ev).getProducedArtifacts();
+							for (TraceArtifact traceArtifact : producedArtifacts) {
+								if (traceArtifact.getRelatesTo().getIri().equals(artifact.getIri()) && traceArtifact.getTimestamp().after(time)) {
+									chosen = traceArtifact;
+								}
+							}
+						}
+					}
+        			if (chosen != null) {
+        				arts.add(chosen);
+					}
+					
+				}
+            	//model.addAttribute("arts", arts);
+            	request.getSession().setAttribute("arts", arts);
             	model.addAttribute("storageURL", env.getProperty("storageURL"));
 			} else { 
 				model.addAttribute("endBool", true);
 			}
         	
 		} else {
-			model.addAttribute("arts", null);
+			request.getSession().setAttribute("arts", null);
 		}
     	model.addAttribute("current", iri);
     	return "enact";

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

@@ -14,6 +14,7 @@ import ua.be.wee.model.pm.PMRepository;
 import ua.be.wee.model.pt.Event;
 import ua.be.wee.model.pt.PT;
 import ua.be.wee.model.pt.PTRepository;
+import ua.be.wee.model.pt.TraceArtifact;
 
 @Component
 public class EnactmentController {
@@ -45,11 +46,11 @@ public class EnactmentController {
 		return traceRepo.createTrace(pm);
 	}
 
-	public void addStartEvent(PT pt, Activity act, List<Artifact> arts) throws Exception {
+	public void addStartEvent(PT pt, Activity act, List<TraceArtifact> arts) throws Exception {
 		traceRepo.createStartEvent(pt,act,arts);
 	}
 
-	public void addEndEvent(PT pt, Activity act, List<Artifact> arts, ControlOutputPort p) throws Exception {
+	public void addEndEvent(PT pt, Activity act, List<TraceArtifact> arts, ControlOutputPort p) throws Exception {
 		traceRepo.createEndEvent(pt,act,arts,p);
 		
 	}
@@ -63,5 +64,4 @@ public class EnactmentController {
 		traceRepo.updatePT(pt);
 		
 	}
-
 }

+ 1 - 33
src/main/java/ua/be/wee/model/nodes/Artifact.java

@@ -4,12 +4,6 @@ public class Artifact extends Node {
 	
 	private String type;
 
-	private String location;
-	
-	private String tag;
-	
-	private String GUID;
-
 	public String getType() {
 		return type;
 	}
@@ -17,32 +11,6 @@ public class Artifact extends Node {
 	public void setType(String type) {
 		this.type = type;
 	}
-
-	public String getLocation() {
-		return location;
-	}
-
-	public void setLocation(String location) {
-		this.location = location;
-	}
-
-	public String getTag() {
-		return tag;
-	}
-
-	public void setTag(String tag) {
-		this.tag = tag;
-	}
-
-	public String getGUID() {
-		return GUID;
-	}
-
-	public void setGUID(String gUID) {
-		GUID = gUID;
-	}
-	
-	
-	
+		
 
 }

+ 26 - 0
src/main/java/ua/be/wee/model/pt/EndActivityEvent.java

@@ -1,10 +1,19 @@
 package ua.be.wee.model.pt;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import ua.be.wee.model.nodes.ports.ControlOutputPort;
 
 public class EndActivityEvent extends Event {
 
 	private ControlOutputPort relatesTo;
+	
+	private List<TraceArtifact> producedArtifacts;
+	
+	public EndActivityEvent() {
+		producedArtifacts = new ArrayList<TraceArtifact>();
+	}
 
 	public ControlOutputPort getRelatesTo() {
 		return relatesTo;
@@ -14,4 +23,21 @@ public class EndActivityEvent extends Event {
 		this.relatesTo = relatesTo;
 	}
 	
+	public void addTraceArtifact(TraceArtifact art) {
+		producedArtifacts.add(art);
+	}
+	
+	public List<TraceArtifact> getProducedArtifacts() {
+		return producedArtifacts;
+	}
+	
+	public TraceArtifact getArtifact(String iri) {
+		for (TraceArtifact traceArtifact : producedArtifacts) {
+			if (iri.equals(traceArtifact.getIri())) {
+				return traceArtifact;
+			}
+		}
+		return null;
+	}
+	
 }

+ 37 - 16
src/main/java/ua/be/wee/model/pt/PTRepository.java

@@ -56,7 +56,7 @@ public class PTRepository {
 		return index;
 	}
 
-	public void createStartEvent(PT pt, Activity act, List<Artifact> arts) throws Exception {
+	public void createStartEvent(PT pt, Activity act, List<TraceArtifact> arts) throws Exception {
 		int index = pt.getLastEvent() == null ? 0 : (Integer.parseInt(""+pt.getLastEvent().getIri().charAt(pt.getLastEvent().getIri().length()-1))+1); 
 
 		String iri = pt.getIri().replace('#', '/') + "#" + "start_activity" + index;
@@ -73,19 +73,40 @@ public class PTRepository {
 				+ "    base:acyclicForward <" + endiri + "> ;\n"
 				+ "    tr:isFollowedBy <" + endiri + "> ;\n"
 				+ "    tr:isPrecededBy <" + preiri + "> ;\n"
-				+ "    tr:relatesTo <" + portiri + "> ;\n"
-				+ "    owl:sameAs <" + iri + "> .\n"
+				+ "    tr:relatesTo <" + portiri + "> ;\n";
+		if (arts != null) {
+			for (TraceArtifact artifact : arts) {
+				query += "    tr:consumes <" + artifact.getIri() + "> ;\n";
+			}
+		}
+		query +=  "    owl:sameAs <" + iri + "> .\n"
 				+ "}";
+		StartActivityEvent ev = new StartActivityEvent();
 		if (FusekiWrapper.getInstance().updateQuery(query) ) {
-			StartActivityEvent ev = new StartActivityEvent();
 			ev.setIri(iri);
 			ev.setRelatesTo(act.getCtrlInPorts().get(0));
 			pt.addEvent(ev);
-			updatePT(pt);
 		} else {
 			throw new Exception("Error inserting data.");
 		}
 		
+		if (arts != null) {
+			for (TraceArtifact traceArtifact : arts) {
+				query = "PREFIX pt: <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#>\n"
+						+ "INSERT DATA { \n"
+						+ " <" + traceArtifact.getIri() + "> " 
+						+ "        pt:isConsumedBy <" + iri + "> ;\n"
+						+ "}";
+				if (FusekiWrapper.getInstance().updateQuery(query) ) {
+					traceArtifact.setConsumedBy(ev);
+					ev.addTraceArtifact(traceArtifact);
+				} else {
+					throw new Exception("Error inserting data.");
+				}
+			}
+		}
+		updatePT(pt);
+		
 	}
 	
 	public void updatePT(PT pt) throws Exception {
@@ -119,7 +140,7 @@ public class PTRepository {
 		
 	}
 
-	public void createEndEvent(PT pt, Activity act, List<Artifact> arts, ControlOutputPort p) throws Exception {
+	public void createEndEvent(PT pt, Activity act, List<TraceArtifact> arts, ControlOutputPort p) throws Exception {
 		//TODO: this won't work with concurrent flows (solution: send the start activity event in the request)
 		List<Event> events = pt.getEvents();
 		Event aux = null;
@@ -138,8 +159,9 @@ public class PTRepository {
 		String endiri = pt.getIri().replace('#', '/') + "#" + "end_activity" + index;
 		
 		List<String> artifactsIRI = new ArrayList<String>();
-		for (Artifact art : arts) {
+		for (TraceArtifact art : arts) {
 			String artifactIRI = pt.getIri().replace('#', '/') + "#" + art.getGUID();
+			art.setIri(artifactIRI);
 			artifactsIRI.add(artifactIRI);
 			String query = "PREFIX pt: <http://ua.be/sdo2l/vocabulary/formalisms/processtraces#>\n"
 					+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
@@ -153,11 +175,12 @@ public class PTRepository {
 					//+ "        pt:isConsumedBy <http://ua.be/sdo2l/description/traces/my_pt#start_activity1> ;\n"
 					//+ "        pt:isModel <http://ua.be/sdo2l/description/artifacts/my_xopp#model> ;\n"
 					+ "        pt:isProducedBy <" + endiri + "> ;\n"
-					+ "        pt:relatesTo <" + art.getIri() + "> ;\n"
+					+ "        pt:relatesTo <" + art.getRelatesTo().getIri() + "> ;\n"
 					+ "        owl:sameAs  <" + artifactIRI + "> .\n"
 					+ "}";
 			if (FusekiWrapper.getInstance().updateQuery(query) ) {
 				artifactsIRI.add(artifactIRI);
+				art.setTimestamp(Timestamp.from(Instant.now()));
 			} else {
 				throw new Exception("Error inserting data.");
 			}
@@ -185,13 +208,14 @@ public class PTRepository {
 			ev.setIri(endiri);
 			ev.setRelatesTo(p);
 			pt.addEvent(ev);
+			for (TraceArtifact art : arts) {
+				art.setProducedBy(ev);
+				ev.addTraceArtifact(art);
+			}
 			updatePT(pt);
 		} else {
 			throw new Exception("Error inserting data.");
-		}
-		
-		
-		
+		}		
 	}
 	
 	public Event createEndTraceEvent(String ptIRI, String previous, String pmIRI) throws Exception {
@@ -209,14 +233,11 @@ public class PTRepository {
 			EndTraceEvent ev = new EndTraceEvent();
 			ev.setIri(traceiri);
 			ev.setTimestamp(Timestamp.from(Instant.now()));
-//			ev.setRelatesTo(p);
-//			pt.addEvent(ev);
-//			updatePT(pt);
 			return ev;
 		} else {
 			throw new Exception("Error inserting data.");
 		}
 		
-	}	
+	}
 
 }

+ 26 - 0
src/main/java/ua/be/wee/model/pt/StartActivityEvent.java

@@ -1,10 +1,19 @@
 package ua.be.wee.model.pt;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import ua.be.wee.model.nodes.ports.ControlInputPort;
 
 public class StartActivityEvent extends Event {
 	
 	private ControlInputPort relatesTo;
+	
+	private List<TraceArtifact> consumedArtifacts;
+	
+	public StartActivityEvent() {
+		consumedArtifacts = new ArrayList<TraceArtifact>();
+	}
 
 	public ControlInputPort getRelatesTo() {
 		return relatesTo;
@@ -14,6 +23,23 @@ public class StartActivityEvent extends Event {
 		this.relatesTo = relatesTo;
 	}
 	
+	public void addTraceArtifact(TraceArtifact art) {
+		consumedArtifacts.add(art);
+	}
+	
+	public List<TraceArtifact> getProducedArtifacts() {
+		return consumedArtifacts;
+	}
+	
+	public TraceArtifact getArtifact(String iri) {
+		for (TraceArtifact traceArtifact : consumedArtifacts) {
+			if (iri.equals(traceArtifact.getIri())) {
+				return traceArtifact;
+			}
+		}
+		return null;
+	}
+	
 	
 
 }

+ 88 - 0
src/main/java/ua/be/wee/model/pt/TraceArtifact.java

@@ -0,0 +1,88 @@
+package ua.be.wee.model.pt;
+
+import java.sql.Timestamp;
+
+import ua.be.wee.model.nodes.Artifact;
+
+public class TraceArtifact {
+	
+	private String location;
+	
+	private String tag;
+	
+	private String GUID;
+	
+	private String iri;
+	
+	private StartActivityEvent consumedBy;
+	
+	private EndActivityEvent producedBy;
+	
+	private Artifact relatesTo;
+	
+	private Timestamp timestamp;
+	
+	public Timestamp getTimestamp() {
+		return timestamp;
+	}
+
+	public void setTimestamp(Timestamp timestamp) {
+		this.timestamp = timestamp;
+	}
+	
+	public String getLocation() {
+		return location;
+	}
+
+	public void setLocation(String location) {
+		this.location = location;
+	}
+
+	public String getTag() {
+		return tag;
+	}
+
+	public void setTag(String tag) {
+		this.tag = tag;
+	}
+
+	public String getGUID() {
+		return GUID;
+	}
+
+	public void setGUID(String gUID) {
+		GUID = gUID;
+	}
+
+	public String getIri() {
+		return iri;
+	}
+
+	public void setIri(String iri) {
+		this.iri = iri;
+	}
+
+	public StartActivityEvent getConsumedBy() {
+		return consumedBy;
+	}
+
+	public void setConsumedBy(StartActivityEvent consumedBy) {
+		this.consumedBy = consumedBy;
+	}
+
+	public EndActivityEvent getProducedBy() {
+		return producedBy;
+	}
+
+	public void setProducedBy(EndActivityEvent producedBy) {
+		this.producedBy = producedBy;
+	}
+
+	public Artifact getRelatesTo() {
+		return relatesTo;
+	}
+
+	public void setRelatesTo(Artifact relatesTo) {
+		this.relatesTo = relatesTo;
+	}
+}

+ 5 - 6
src/main/resources/templates/enact.html

@@ -74,21 +74,21 @@
 
 <input id="endEnactment" th:if="${endBool}" class="button button1" type="submit" value="End Enactment" />
     
-<div id="hidden_div" th:if="${arts != null}"> 
+<div id="hidden_div" th:if="${session.arts != null}"> 
 
-<table th:if="${arts != null && arts.size > 0}">
+<table th:if="${session.arts != null && session.arts.size > 0}">
 	<tr> <th colspan="2"  style="padding: 20px; border-bottom: 1px solid red;" ><h3 style="color: #5e9ca0;"> Artifacts </h3></th> </tr>
 	
 	
-	<th:block th:each="art : ${arts}">
+	<th:block th:each="art : ${session.arts}">
     
     <tr>
         <td style="color: #5e9ca0;font-weight: bold;" > Artifact Name:</td>
-        <td style="color: #5e9ca0;" th:text="${art.name}">...</td>
+        <td style="color: #5e9ca0;" th:text="${art.relatesTo.name}">...</td>
     </tr>
     <tr>
         <td style="color: #5e9ca0;font-weight: bold;" > Type:</td>
-        <td style="color: #5e9ca0;" th:text="${art.type}" > </td>
+        <td style="color: #5e9ca0;" th:text="${art.relatesTo.type}" > </td>
     </tr>
     
     <tr>
@@ -98,7 +98,6 @@
     </tr>
     
   </th:block>
-	
 </table>
 <input id="startActivity" class="button button1" type="submit" value="Start Activity"/>