Selaa lähdekoodia

Adding the support to download artifacts previously uploaded to the
traces.

Lucas Albertins 2 vuotta sitten
vanhempi
commit
58b9fae815

+ 3 - 1
src/main/java/ua/be/wee/controller/EnactementControllerMVC.java

@@ -231,7 +231,9 @@ public class EnactementControllerMVC {
     	if (!iri.equals("1")) {
         	if (pm.getNode(iri) instanceof Activity) {
         		Activity act = (Activity)pm.getNode(iri);
-            	model.addAttribute("arts", act.getInputs() == null ? (new ArrayList<Artifact>()) : act.getInputs());
+        		List<Artifact> inputs = act.getInputs();
+            	model.addAttribute("arts", act.getInputs());
+            	model.addAttribute("storageURL", env.getProperty("storageURL"));
 			} else { 
 				model.addAttribute("endBool", true);
 			}

+ 13 - 3
src/main/java/ua/be/wee/service/FileStorageServiceImpl.java

@@ -1,5 +1,6 @@
 package ua.be.wee.service;
 
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.nio.file.FileAlreadyExistsException;
@@ -12,6 +13,8 @@ import javax.servlet.http.Part;
 
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.FileEntity;
+import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.BasicResponseHandler;
 import org.apache.http.impl.client.CloseableHttpClient;
@@ -68,15 +71,22 @@ public class FileStorageServiceImpl implements FileStorageService {
 			}
 			
 			CloseableHttpClient httpclient = HttpClients.createDefault();
-
+			
 			HttpPut httpPut = new HttpPut(url);
 			
+			
 			// specify the PUT body to send to the server as part of the request
-			httpPut.setEntity(new StringEntity(file.getInputStream().toString()));
+			//httpPut.setEntity(new StringEntity(file.getInputStream().toString()));
 
+			httpPut.setEntity(new InputStreamEntity(file.getInputStream()));
+			
+			
 			HttpResponse response = httpclient.execute(httpPut);
 
-			String responseBody = new BasicResponseHandler().handleResponse(response);			
+			String responseBody = new BasicResponseHandler().handleResponse(response);	
+			
+			
+			httpclient.close();
 			
 		} catch (Exception e) {
 			if (e instanceof FileAlreadyExistsException) {

+ 20 - 1
src/main/resources/templates/enact.html

@@ -77,9 +77,28 @@
 <div id="hidden_div" th:if="${arts != null}"> 
 
 <table th:if="${arts != null && arts.size > 0}">
-	<tr> <td > Artifacts </td> </tr>
+	<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}">
+    
+    <tr>
+        <td style="color: #5e9ca0;font-weight: bold;" > Artifact Name:</td>
+        <td style="color: #5e9ca0;" th:text="${art.name}">...</td>
+    </tr>
+    <tr>
+        <td style="color: #5e9ca0;font-weight: bold;" > Type:</td>
+        <td style="color: #5e9ca0;" th:text="${art.type}" > </td>
+    </tr>
+    
+    <tr>
+        <td colspan="2" style="color: #5e9ca0;font-weight: bold; padding: 20px;
+    		border-bottom: 1px solid red;"  >  <a class="button button1" th:href="@{|${storageURL}/files/file/${art.location}|}"> Download </a>  </td>
+
+    </tr>
+    
+  </th:block>
+	
 </table>
 <input id="startActivity" class="button button1" type="submit" value="Start Activity"/>