Browse Source

Merge master into fragments

Arkadiusz Ryś 1 year ago
parent
commit
a6748a9c9a

+ 6 - 6
flake.lock

@@ -5,11 +5,11 @@
         "systems": "systems"
       },
       "locked": {
-        "lastModified": 1689068808,
-        "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
+        "lastModified": 1694529238,
+        "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
         "owner": "numtide",
         "repo": "flake-utils",
-        "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
+        "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
         "type": "github"
       },
       "original": {
@@ -43,11 +43,11 @@
     },
     "nixpkgs": {
       "locked": {
-        "lastModified": 1692084312,
-        "narHash": "sha256-Za++qKVK6ovjNL9poQZtLKRM/re663pxzbJ+9M4Pgwg=",
+        "lastModified": 1695360818,
+        "narHash": "sha256-JlkN3R/SSoMTa+CasbxS1gq+GpGxXQlNZRUh9+LIy/0=",
         "owner": "NixOS",
         "repo": "nixpkgs",
-        "rev": "8353344d3236d3fda429bb471c1ee008857d3b7c",
+        "rev": "e35dcc04a3853da485a396bdd332217d0ac9054f",
         "type": "github"
       },
       "original": {

+ 4 - 13
flake.nix

@@ -18,34 +18,25 @@
           inherit system;
         });
 
-        mavenRepository = pkgs.buildMavenRepositoryFromLockFile {
-          file = ./mvn2nix-lock.json;
-        };
       in rec {
         packages = rec {
-          wee = pkgs.stdenv.mkDerivation rec {
+          wee = pkgs.maven.buildMavenPackage rec {
             pname = "wee";
             version = "0.0.1";
             name = "${pname}-${version}";
             src = pkgs.nix-gitignore.gitignoreSource [ "*.nix" ] ./.;
+            mvnHash = "sha256-PUUlNgRvBiZZVH3zxTmQW92nBo90nm+FSS1Ryw/0rB0=";
             nativeBuildInputs = [
               pkgs.makeWrapper
             ];
-            buildPhase = ''
-              echo "Building with maven repository ${mavenRepository}"
-              ${pkgs.maven}/bin/mvn package --offline -Dmaven.repo.local=${mavenRepository}
-            '';
             installPhase = ''
               # create the bin directory
               mkdir -p $out/bin
 
-              # create a symbolic link for the lib directory
-              ln -s ${mavenRepository} $out/lib
-
               # copy out the JAR
               # Maven already setup the classpath to use m2 repository layout
               # with the prefix of lib/
-              cp target/${name}.jar $out/
+              install -Dm644 target/${name}.jar $out/${name}.jar
 
               # create a wrapper that will automatically set the classpath
               # this should be the paths from the dependency derivation
@@ -56,4 +47,4 @@
         };
         defaultPackage = packages.wee;
       });
-}
+}

+ 7 - 7
pom.xml

@@ -44,11 +44,6 @@
 			<artifactId>h2</artifactId>
 			<scope>runtime</scope>
 		</dependency>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-configuration-processor</artifactId>
-			<optional>true</optional>
-		</dependency>
 		<dependency>
 			<groupId>org.projectlombok</groupId>
 			<artifactId>lombok</artifactId>
@@ -59,11 +54,16 @@
 			<artifactId>spring-boot-starter-test</artifactId>
 			<scope>test</scope>
 		</dependency>
-		<dependency>
+	 	<dependency>
         	<groupId>org.asynchttpclient</groupId>
         	<artifactId>async-http-client</artifactId>
         	<version>3.0.0.Beta2</version>
-        </dependency>
+        </dependency> 
+        <dependency>
+  			<groupId>org.json</groupId>
+  				<artifactId>json</artifactId>
+  				<version>20220924</version>
+		</dependency>
 	</dependencies>
 
 	<build>

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

@@ -5,7 +5,6 @@ import java.io.IOException;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -23,11 +22,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import ua.be.wee.controller.rest.PTController;
-import ua.be.wee.model.AutomatedActivityProgress;
 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.AutomatedActivity;
+import ua.be.wee.model.nodes.AutomatedStatus;
 import ua.be.wee.model.nodes.FinalNode;
 import ua.be.wee.model.nodes.ForkJoinNode;
 import ua.be.wee.model.nodes.Node;
@@ -71,10 +70,6 @@ public class EnactmentControllerMVC {
 		} else {
 			model.addAttribute("hasEndpoint", false);
 		}
-        List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-        model.addAttribute("activities", automated_activity_progress);
         return "index";
     }
 
@@ -86,17 +81,9 @@ public class EnactmentControllerMVC {
     		model.addAttribute("pms", controller.getAllPMs());
     		model.addAttribute("traces",null);
     		model.addAttribute("current", "1");
-            List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-            automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-            automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-            model.addAttribute("activities", automated_activity_progress);
             return "pms";
 		} else {
 			model.addAttribute("error",true);
-            List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-            automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-            automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-            model.addAttribute("activities", automated_activity_progress);
 			return "index";
 		}
     }
@@ -112,10 +99,6 @@ public class EnactmentControllerMVC {
     	model.addAttribute("error",false);
 		model.addAttribute("pms", controller.getAllPMs());
 		model.addAttribute("current", iri);
-        List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-        model.addAttribute("activities", automated_activity_progress);
         return "pms";
     }
 
@@ -138,13 +121,10 @@ public class EnactmentControllerMVC {
 			request.getSession().setAttribute("trace", trace);
 			request.getSession().setAttribute("acts",acts);
 			request.getSession().setAttribute("endacts",new ArrayList<Node>());
-			request.getSession().setAttribute("automated",new ArrayList<AutomatedActivity>());
+			//TODO instead of creating empty check if there is any automated activity being executed
+			request.getSession().setAttribute("automated",controller.getAutomatedActivities(trace));
 			model.addAttribute("arts", null);
 			model.addAttribute("current", "1");
-            List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-            automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-            automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-            model.addAttribute("activities", automated_activity_progress);
 	        return "enact";
 		}
     }
@@ -179,17 +159,15 @@ public class EnactmentControllerMVC {
 				}
 				request.getSession().setAttribute("acts",acts);
 			}
-			model.addAttribute("error", false);
+
 			request.getSession().setAttribute("pm", pm);
 			request.getSession().setAttribute("trace", trace);
 			request.getSession().setAttribute("endacts",endActs);
-			request.getSession().setAttribute("automated",new ArrayList<AutomatedActivity>());
+			//TODO instead of creating empty check if there is any automated activity being executed
+			request.getSession().setAttribute("automated",controller.getAutomatedActivities(trace));
+			model.addAttribute("error", false);
 			model.addAttribute("arts", null);
 			model.addAttribute("current", "1");
-            List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-            automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-            automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-            model.addAttribute("activities", automated_activity_progress);
 	        return "enact";
 		}
     }
@@ -285,37 +263,61 @@ public class EnactmentControllerMVC {
 		return result;
 	}
 
+	@PostMapping("/reload")
+    public String reload(Model model, HttpServletRequest request) throws Exception {
+		PT pt = (PT)request.getSession().getAttribute("trace");
+		PM pm = (PM)request.getSession().getAttribute("pm");
+		request.getSession().setAttribute("automated",controller.getAutomatedActivities(pt));
+
+		List<Event> events = ptController.getEvents(pt.getIri());
+		pt.setEvents(events);
+
+		List <Node> endActs = findEndActs(pt.getEvents());
+		List<PMTrigger> acts = findStartActs(pt);
+		if (pt.getEvents().get(pt.getEvents().size()-1) instanceof EndActivityEvent) {
+			EndActivityEvent last = (EndActivityEvent)pt.getEvents().get(pt.getEvents().size()-1);
+			List<Pair<String,String>> iris = controller.findNextNodes(last.getRelatesTo().getIri(), pt.getIri());
+			acts.addAll(findElements(pm, iris));
+		}
+		request.getSession().setAttribute("acts",acts);
+		request.getSession().setAttribute("endacts",endActs);
+
+    	request.getSession().setAttribute("trace", pt);
+
+    	model.addAttribute("error", false);
+		model.addAttribute("arts", null);
+		model.addAttribute("current", "1");
+		return "enact";
+	}
+
 	@PostMapping("/startAct")
     public String startActivity(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");
     	List<Node> endacts = (List<Node>) request.getSession().getAttribute("endacts");
-    	List<AutomatedActivity> automated = (List<AutomatedActivity>) request.getSession().getAttribute("automated");
     	PMTrigger element = findPMTrigger(acts,iri);
     	List<TraceArtifact> arts = (List<TraceArtifact>)request.getSession().getAttribute("arts");
-        List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-        model.addAttribute("activities", automated_activity_progress);
     	if (element.getPort() != null) {
     		ControlInputPort port = (ControlInputPort)element.getPort();
         	Activity activity = port.getActivity();
         	if (activity instanceof AutomatedActivity) {
 				AutomatedActivity aut = (AutomatedActivity)activity;
-				controller.callAutomatedActivity(pt,aut, arts);
-				automated.add(aut);
+				controller.callAutomatedActivity(pt,aut, port, arts);
+				aut.setAutomatedStatus(AutomatedStatus.IN_PROGRESS);
 			} else {
 				endacts.add(port.getActivity());
 			}
         	controller.addStartEvent(pt,port, port.getActivity(),arts);
         	removeElement(acts,iri);
+        	request.getSession().setAttribute("automated",controller.getAutomatedActivities(pt));
         	request.getSession().removeAttribute("arts");
         	return "enact";
 		} else if (element.getNode() != null) {
 			Event endTraceEvent = controller.addEndTraceEvent(pt.getIri(), pt.getLastEvent().getIri(), pm.getIri());
 			pt.addEvent(endTraceEvent);
 			controller.updatePT(pt);
+			request.getSession().setAttribute("automated",controller.getAutomatedActivities(pt));
 			return "endEnactment";
 		} else {
 			return "error";
@@ -367,14 +369,11 @@ public class EnactmentControllerMVC {
         acts.addAll(findElements(pm, iris));
 
     	request.getSession().setAttribute("trace", pt);
-    	request.getSession().setAttribute("previous", p.getIri());
+    	request.getSession().setAttribute("automated",controller.getAutomatedActivities(pt));
+    	//request.getSession().setAttribute("previous", p.getIri());
 		model.addAttribute("arts", null);
 		model.addAttribute("current", "1");
-        List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-        model.addAttribute("activities", automated_activity_progress);
-        return "enact";
+    	return "enact";
     }
 
     @RequestMapping("/endselect")
@@ -392,10 +391,7 @@ public class EnactmentControllerMVC {
 		} else {
 			model.addAttribute("arts", null);
 		}
-        List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-        model.addAttribute("activities", automated_activity_progress);
+
     	return "enactEnd";
     }
 
@@ -436,11 +432,8 @@ public class EnactmentControllerMVC {
 		} else {
 			request.getSession().setAttribute("arts", null);
 		}
+    	request.getSession().setAttribute("automated",controller.getAutomatedActivities(pt));
     	model.addAttribute("current", iri);
-        List<AutomatedActivityProgress> automated_activity_progress = new LinkedList<>();
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 1", true));
-        automated_activity_progress.add(new AutomatedActivityProgress("Example 2", false));
-        model.addAttribute("activities", automated_activity_progress);
     	return "enact";
     }
 

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

@@ -2,23 +2,27 @@ package ua.be.wee.model;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.json.JSONException;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.configurationprocessor.json.JSONException;
 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.AutomatedActivity;
+import ua.be.wee.model.nodes.AutomatedStatus;
 import ua.be.wee.model.nodes.ports.ControlInputPort;
 import ua.be.wee.model.nodes.ports.ControlOutputPort;
 import ua.be.wee.model.nodes.ports.DataInputPort;
 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.StartActivityEvent;
 import ua.be.wee.model.pt.TraceArtifact;
 import ua.be.wee.model.repository.NodeRespository;
 import ua.be.wee.model.repository.PMRepository;
@@ -79,9 +83,9 @@ public class EnactmentController {
 		
 	}
 
-	public void callAutomatedActivity(PT pt, AutomatedActivity aut, List<TraceArtifact> arts) throws JSONException, IOException {
+	public void callAutomatedActivity(PT pt, AutomatedActivity aut, ControlInputPort port, List<TraceArtifact> arts) throws JSONException, IOException {
 		Map<String,Pair<String,String>> params = createParamsMap(aut, arts);
-		AsyncHttpClientService.asyncHTTPClient(pt, aut, params,this);
+		AsyncHttpClientService.asyncHTTPClient(pt, aut, port, params,this);
 		
 	}
 
@@ -94,8 +98,18 @@ public class EnactmentController {
 				Artifact relatesTo = traceArtifact.getRelatesTo();
 				if (dataInputPort.getArtifact().getIri().equals(relatesTo.getIri())) {
 					traceArtifact.getLocation();
-					String content = storageService.load(traceArtifact.getLocation());
-					params.put(dataInputPort.getName(), new Pair<String, String>(traceArtifact.getFileExtension(), content));
+					//TODO Instead of this, send both the inline and url to the services
+					if (traceArtifact.getFileExtension().equals("txt") || 
+							traceArtifact.getFileExtension().equals("csv") ||
+							traceArtifact.getFileExtension().equals("xopp")||
+							traceArtifact.getFileExtension().equals("drawio")) {
+						String content = storageService.load(traceArtifact.getLocation());
+						params.put(dataInputPort.getName(), new Pair<String, String>(traceArtifact.getFileExtension(), content));
+					} else {
+						String content = storageService.getURL(traceArtifact.getLocation());
+						params.put(dataInputPort.getName(), new Pair<String, String>(traceArtifact.getFileExtension(), content));
+					}
+					
 				}
 			}
 		}
@@ -105,4 +119,47 @@ public class EnactmentController {
 	public void uploadArtifact(InputStream is, String filename) throws IOException {
 		storageService.save(is,filename);	
 	}
+
+	public List<AutomatedActivity> getAutomatedActivities(PT trace) {
+		trace.getPmEnacted();
+		List<AutomatedActivity> result = new ArrayList<AutomatedActivity>();
+		List<Event> events = trace.getEvents();
+		for (Event event : events) {
+			if (event instanceof StartActivityEvent) {
+				Activity activity = ((StartActivityEvent) event).getRelatesTo().getActivity();
+				if (activity instanceof AutomatedActivity) {
+					boolean found = false;
+					for (Event event2 : events) {
+						if (event2 instanceof EndActivityEvent) {
+							if (checkMatchingActivityEvents((StartActivityEvent)event, (EndActivityEvent)event2)) {
+								AutomatedActivity aut =(AutomatedActivity)activity;
+								aut.setAutomatedStatus(AutomatedStatus.COMPLETED);
+								result.add(aut);
+								found = true;
+								break;
+							}
+							
+						}
+					}
+					if (!found) {
+						AutomatedActivity aut =(AutomatedActivity)activity;
+						aut.setAutomatedStatus(AutomatedStatus.IN_PROGRESS);
+						result.add(aut);	
+					}
+				}
+			} 
+		}
+		return result;
+	}
+	
+	public boolean checkMatchingActivityEvents(StartActivityEvent ev1, EndActivityEvent ev2) {
+		String ir = ev1.getIri();
+		String ir2= ev2.getIri();
+		String[] split = ir.split("#");
+		String[] split2 = ir2.split("#");
+		String sub1 = split[1].substring(split[1].indexOf('_'));
+		String sub2 = split2[1].substring(split2[1].indexOf('_'));
+		return split[0].equals(split2[0]) && sub1.equals(sub2);
+	}
+	
 }

+ 11 - 2
src/main/java/ua/be/wee/model/nodes/AutomatedActivity.java

@@ -2,11 +2,12 @@ package ua.be.wee.model.nodes;
 
 public class AutomatedActivity extends Activity {
 
-	
 	private String endpoint;
 	
 	private long timeout;
 	
+	private AutomatedStatus status;
+	
 	public long getTimeout() {
 		return timeout;
 	}
@@ -21,5 +22,13 @@ public class AutomatedActivity extends Activity {
 
 	public void setEndpoint(String endpoint) {
 		this.endpoint = endpoint;
-	}	
+	}
+	
+	public void setAutomatedStatus(AutomatedStatus s) {
+		this.status = s;
+	}
+	
+	public AutomatedStatus getAutomatedStatus() {
+		return this.status;
+	}
 }

+ 5 - 0
src/main/java/ua/be/wee/model/nodes/AutomatedStatus.java

@@ -0,0 +1,5 @@
+package ua.be.wee.model.nodes;
+
+public enum AutomatedStatus {
+	IN_PROGRESS, COMPLETED
+}

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

@@ -11,6 +11,7 @@ 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.AutomatedActivity;
 import ua.be.wee.model.nodes.ports.ControlInputPort;
 import ua.be.wee.model.nodes.ports.ControlOutputPort;
 import ua.be.wee.model.pm.PM;
@@ -812,8 +813,6 @@ public class PTRepository {
 			list.add(ev);
 		}
 		return list;		
-	}
-
-	
+	}	
 
 }

+ 76 - 43
src/main/java/ua/be/wee/model/util/AsyncHttpClientService.java

@@ -5,38 +5,41 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.time.Duration;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeoutException;
 
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.asynchttpclient.AsyncCompletionHandler;
 import org.asynchttpclient.AsyncHttpClient;
 import org.asynchttpclient.DefaultAsyncHttpClientConfig;
 import org.asynchttpclient.Dsl;
 import org.asynchttpclient.Request;
 import org.asynchttpclient.Response;
-import org.springframework.boot.configurationprocessor.json.JSONException;
-import org.springframework.boot.configurationprocessor.json.JSONObject;
+import org.json.JSONException;
+import org.json.JSONObject;
 
 import ua.be.wee.model.EnactmentController;
 import ua.be.wee.model.nodes.AutomatedActivity;
+import ua.be.wee.model.nodes.ports.ControlInputPort;
 import ua.be.wee.model.nodes.ports.ControlOutputPort;
 import ua.be.wee.model.nodes.ports.DataOutputPort;
 import ua.be.wee.model.pt.PT;
 import ua.be.wee.model.pt.TraceArtifact;
-import ua.be.wee.service.FileStorageService;
-import ua.be.wee.service.FileStorageServiceImpl;
 
 public class AsyncHttpClientService {
 	
-	public static void asyncHTTPClient(PT pt, AutomatedActivity act, Map<String,Pair<String,String>> artifacts, EnactmentController control) throws JSONException, IOException {
+	public static void asyncHTTPClient(PT pt, AutomatedActivity act, ControlInputPort port, Map<String,Pair<String,String>> artifacts, EnactmentController control) throws JSONException, IOException {
 		DefaultAsyncHttpClientConfig.Builder clientBuilder = Dsl.config().setConnectTimeout(Duration.ofMillis(act.getTimeout()));
 		AsyncHttpClient client = Dsl.asyncHttpClient(clientBuilder);
 		
-		String requestBody = createJSONBody(artifacts);
+		String requestBody = createJSONBody(port, artifacts);
 		
 		Request request = Dsl.post(act.getEndpoint()).setBody(requestBody).setRequestTimeout(Duration.ofMillis(act.getTimeout())).build();
 		
@@ -65,8 +68,8 @@ public class AsyncHttpClientService {
 					
 					JSONObject outputs = res.getJSONObject("output");
 					List<TraceArtifact> traceArts = new ArrayList<TraceArtifact>();
-					for (Iterator iterator = outputs.keys(); iterator.hasNext();) {
-						String outDataName = (String) iterator.next();
+					for (Iterator<String> iterator = outputs.keys(); iterator.hasNext();) {
+						String outDataName = iterator.next();
 						List<DataOutputPort> dataOutPorts = act.getDataOutPorts();
 						
 						for (DataOutputPort dataOutputPort : dataOutPorts) {
@@ -82,20 +85,31 @@ public class AsyncHttpClientService {
 									tArt.setLocation(name);
 									tArt.setRelatesTo(dataOutputPort.getArtifact());
 									traceArts.add(tArt);
-								} else if (type.equals("url")) {
-									//TODO add possibility to link data to URL
+								} else if (type.equals("reference")) {
+									String url = outData.getString("content");
+									String name = outData.getString("name");
+									CloseableHttpClient httpclient = HttpClients.createDefault();
+									HttpGet httpGet = new HttpGet(url);
+									HttpResponse resp = httpclient.execute(httpGet);
+									String responseBody = new BasicResponseHandler().handleResponse(resp);
+									httpclient.close();
+									InputStream is = new ByteArrayInputStream(responseBody.getBytes());
+									control.uploadArtifact(is,name);
+									TraceArtifact tArt = new TraceArtifact();
+									tArt.setLocation(name);
+									tArt.setRelatesTo(dataOutputPort.getArtifact());
+									traceArts.add(tArt);
 								}
 							}
 						}	
 					} 
-					Thread.sleep(1000);
+					Thread.sleep(500);
 					control.addEndEvent(pt, traceArts, ctrlOutPort);
 					
 				} else {
 					throw new Exception("The response of automated activity " + act.getName() + " returned an unexpected status code: " + statusCode);
 				}
 				
-				
 				client.close();
 				return result;
 		    }
@@ -103,54 +117,73 @@ public class AsyncHttpClientService {
 			@Override
 		    public void onThrowable(Throwable t) {
 				if (t instanceof TimeoutException) {
-					System.err.println("Timeout occurred!");
+					List<ControlOutputPort> ctrlOutPorts = act.getCtrlOutPorts();
+					ControlOutputPort ctrlOutPort = null;
+					for (ControlOutputPort controlOutputPort : ctrlOutPorts) {
+						if (controlOutputPort.getName().equals("error")) {
+							ctrlOutPort = controlOutputPort;
+							break;
+						}
+					}
+					try {
+						if (ctrlOutPort != null) {
+							control.addEndEvent(pt, new ArrayList<>(), ctrlOutPort);
+						} else {
+							System.err.println("Missing 'error' control port!");
+						}
+						
+					} catch (Exception e) {
+						System.err.println("Error happened when adding timeout end event in the trace!");
+						e.printStackTrace();
+					}
+					
 				} else {
-					System.err.println("Another error occurred!");
+					List<ControlOutputPort> ctrlOutPorts = act.getCtrlOutPorts();
+					ControlOutputPort ctrlOutPort = null;
+					for (ControlOutputPort controlOutputPort : ctrlOutPorts) {
+						if (controlOutputPort.getName().equals("error")) {
+							ctrlOutPort = controlOutputPort;
+							break;
+						}
+					}
+					try {
+						if (ctrlOutPort != null) {
+							control.addEndEvent(pt, new ArrayList<>(), ctrlOutPort);
+						} else {
+							System.err.println("Missing 'error' control port!");
+						}
+					} catch (Exception e) {
+						System.err.println("Error happened when adding error end event in the trace!");
+						e.printStackTrace();
+					}
 				}
 		    }
 		});
 		
 	}
 	
-	private static String createJSONBody(Map<String,Pair<String,String>> params) throws JSONException {
+	private static String createJSONBody(ControlInputPort port, Map<String,Pair<String,String>> params) throws JSONException {
 		JSONObject body = new JSONObject();
 		JSONObject input = new JSONObject();
 		Set<String> keySet = params.keySet();
 		for (String dataPort : keySet) {
 			JSONObject inner = new JSONObject();
-			inner.put("type", "inline");
+			if (params.get(dataPort).getFst().equals("txt") || 
+					params.get(dataPort).getFst().equals("csv") ||
+					params.get(dataPort).getFst().equals("xopp")||
+					params.get(dataPort).getFst().equals("drawio")) {
+				inner.put("type", "inline");
+			} else {
+				inner.put("type", "reference");
+			}
 			inner.put("content", params.get(dataPort).getSnd());
 			input.put(dataPort, inner);
+			
 		}
 		body.put("input", input);
+		body.put("ctrl", port.getName());
 		System.out.println(body.toString());
 		return body.toString();
 	}
-	
-	public static void main(String[] args) throws JSONException, IOException {
-		
-
-		FileStorageService storageService = new FileStorageServiceImpl();
-		storageService.setStorageURL("http://localhost:5000");
-				
-		AutomatedActivity a = new AutomatedActivity();
-		a.setTimeout(5000);
-		a.setEndpoint("http://localhost:7999");
-		
-		Map<String,Pair<String,String>> params = new HashMap<String, Pair<String,String>>();
-				
-		String content = storageService.load("mock_requirements.txt");
-		System.out.println(content);
-		params.put("din", new Pair<String, String>("txt", content+ "c"));
-		
-		EnactmentController enac = new EnactmentController();
-		
-		PT pt = new PT();
-		
-		asyncHTTPClient(pt, a, params,enac);
-		System.out.println("chegou aqui");
-
-	}
-
 
 }

+ 2 - 7
src/main/java/ua/be/wee/model/util/HTTPRequestClient.java

@@ -7,22 +7,17 @@ import java.net.http.HttpRequest.BodyPublisher;
 import java.net.http.HttpResponse;
 import java.time.Duration;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
-import java.util.stream.Collectors;
 
-import org.springframework.boot.configurationprocessor.json.JSONException;
-import org.springframework.boot.configurationprocessor.json.JSONObject;
+import org.json.JSONException;
+import org.json.JSONObject;
 
-import ua.be.wee.model.nodes.Artifact;
 import ua.be.wee.model.nodes.AutomatedActivity;
-import ua.be.wee.model.nodes.ports.DataInputPort;
-import ua.be.wee.model.pt.TraceArtifact;
 import ua.be.wee.service.FileStorageService;
 import ua.be.wee.service.FileStorageServiceImpl;
 

+ 2 - 0
src/main/java/ua/be/wee/service/FileStorageService.java

@@ -18,4 +18,6 @@ public interface FileStorageService {
   public Stream<Path> loadAll();
   
   public void setStorageURL(String url);
+  
+  public String getURL(String filename);
 }

+ 25 - 0
src/main/java/ua/be/wee/service/FileStorageServiceImpl.java

@@ -176,4 +176,29 @@ public class FileStorageServiceImpl implements FileStorageService {
 		storageServiceURL = url;
 		
 	}
+
+	@Override
+	public String getURL(String filename) {
+		
+			if (storageServiceURL == null) {
+				init();
+			}
+			//Files.copy(file.getInputStream(), this.root.resolve(file.getOriginalFilename()));
+			String url = "";
+			switch (filename.substring(filename.lastIndexOf('.'))) {
+			case ".xopp":
+				url = storageServiceURL + "/files/xopp/"+filename;				
+				break;
+			case ".csv":
+				url = storageServiceURL +"/files/csv/"+filename;				
+				break;
+			case ".drawio":
+				url = storageServiceURL + "/files/drawio/"+filename;				
+				break;
+			default:
+				url = storageServiceURL + "/files/file/"+filename; 
+				break;
+			}
+		return url;
+	}
 }

+ 28 - 0
src/main/resources/templates/enact.html

@@ -8,6 +8,34 @@
   <!-- TODO Use fragment inclusion expressions to hide the panel when no ongoing automated activities are present? -->
   <article th:replace="fragments/automated.html :: activity(activities=${activities})"></article>
 
+  <article class="panel is-primary automated-activities">
+    <p class="panel-heading">Automated Activities</p>
+
+    <th:block th:each="aut : ${session.automated}">
+            <p th:if="${aut.automatedStatus == T(ua.be.wee.model.nodes.AutomatedStatus).COMPLETED}">
+    	    	<a class="panel-block automated-activity">
+      			<progress class="progress is-medium is-success activity" value= "100" max="100"></progress>
+      			<span th:text="${aut.name} + ': Completed'" >Example Completed Activity 1</span>
+    			</a>
+            </p>
+            <p th:if="${aut.automatedStatus == T(ua.be.wee.model.nodes.AutomatedStatus).IN_PROGRESS}">
+            	<a class="panel-block automated-activity">
+      			<progress class="progress is-medium is-info activity" max="100"></progress>
+      			<span th:text="${aut.name} + ': In Progress'">Example In Progress Activity 2</span>
+    			</a>
+            </p>
+
+    </th:block>
+
+   <form class="form" th:action="@{/reload}" method="post">
+
+   <a class="panel-block">
+      <button id="reloadButton" class="button is-primary" type="submit"><img class="refresh" width="32" height="32" th:src="@{/img/refresh.svg}" alt="Circular arrow"></button>
+    </a>
+  </article>
+
+  </form>
+
   <section class="pt-6 pb-6 pl-5 pr-5">
     <div class="columns">
       <div class="column is-two-thirds">

+ 27 - 0
src/main/resources/templates/enactEnd.html

@@ -7,6 +7,33 @@
 <main>
   <article th:replace="fragments/automated.html :: activity(activities=${activities})"></article>
 
+  <article class="panel is-primary automated-activities">
+    <p class="panel-heading">Automated Activities</p>
+     <th:block th:each="aut : ${session.automated}">
+            <p th:if="${aut.automatedStatus == T(ua.be.wee.model.nodes.AutomatedStatus).COMPLETED}">
+    	    	<a class="panel-block automated-activity">
+      			<progress class="progress is-medium is-success activity" value= "100" max="100"></progress>
+      			<span th:text="${aut.name} + ': Completed'" >Example Completed Activity 1</span>
+    			</a>
+            </p>
+            <p th:if="${aut.automatedStatus == T(ua.be.wee.model.nodes.AutomatedStatus).IN_PROGRESS}">
+            	<a class="panel-block automated-activity">
+      			<progress class="progress is-medium is-info activity" max="100"></progress>
+      			<span th:text="${aut.name} + ': In Progress'">Example In Progress Activity 2</span>
+    			</a>
+            </p>
+
+    </th:block>
+    <form class="form" th:action="@{/reload}" method="post">
+
+   <a class="panel-block">
+      <button id="reloadButton" class="button is-primary" type="submit"><img class="refresh" width="32" height="32" th:src="@{/img/refresh.svg}" alt="Circular arrow"></button>
+    </a>
+  </article>
+
+  </form>
+  </article>
+
   <section class="pt-6 pb-6 pl-5 pr-5">
     <div class="columns">
       <div class="column is-two-thirds">

+ 21 - 0
src/main/resources/templates/endEnactment.html

@@ -7,6 +7,27 @@
 <main>
   <article th:replace="fragments/automated.html :: activity(activities=${activities})"></article>
 
+  <article class="panel is-primary automated-activities">
+    <p class="panel-heading">Automated Activities</p>
+    <th:block th:each="aut : ${session.automated}">
+            <p th:if="${aut.automatedStatus == T(ua.be.wee.model.nodes.AutomatedStatus).COMPLETED}">
+    	    	<a class="panel-block automated-activity">
+      			<progress class="progress is-medium is-success activity" value= "100" max="100"></progress>
+      			<span th:text="${aut.name} + ': Completed'" >Example Completed Activity 1</span>
+    			</a>
+            </p>
+            <p th:if="${aut.automatedStatus == T(ua.be.wee.model.nodes.AutomatedStatus).IN_PROGRESS}">
+            	<a class="panel-block automated-activity">
+      			<progress class="progress is-medium is-info activity" max="100"></progress>
+      			<span th:text="${aut.name} + ': In Progress'">Example In Progress Activity 2</span>
+    			</a>
+            </p>
+
+    </th:block>
+
+  </article>
+
+
   <section class="pt-6 pb-6 pl-5 pr-5">
     <p th:inline="text">Enactment of the Process Model: <span class="accent">[[${session.pm.name}]]</span> has ended!</p>
     <p>You can review the details about the Process Trace.</p>

+ 1 - 1
src/main/resources/templates/index.html

@@ -6,7 +6,7 @@
 <body>
 <main>
   <section class="pt-6 pb-6 pl-5 pr-5">
-    <h2 class="is-size-3 is-capitalized">Welcome to Wee!</h2>
+    <h2 class="is-size-3 is-capitalized">Welcome to WEE!</h2>
     <audio id="audio" src="/audio/Wee.mp3"></audio>
     <img id="img" value="PLAY" onclick="play()" class="wee-meme-image" src="../static/img/wee.png" th:src="@{/img/wee.png}" alt="Logo of person slipping"><!--  https://thenounproject.com/icon/slipping-11426/  -->
     <p>If you want to see wee memes click <a href="https://www.instagram.com/weee.memes/">here!</a></p>

+ 0 - 2
src/main/resources/templates/pms.html

@@ -5,8 +5,6 @@
 </head>
 <body>
 <main>
-  <article th:replace="fragments/automated.html :: activity(activities=${activities})"></article>
-
   <section class="pt-6 pb-6 pl-5 pr-5">
     <form class="pt-3" th:action="@{/enactpm}" method="post">
       <p class="is-size-4">Choose the Process Model to be enacted</p>