Add direct link to the job archive file (raw data)
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Fri, 20 Dec 2013 08:30:35 +0000 (08:30 +0000)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Fri, 20 Dec 2013 08:30:35 +0000 (08:30 +0000)
engine/compbio/engine/archive/ArchivedJob.java
server/compbio/controllers/JobController.java
server/compbio/spring/WebConfig.java
webapp/view/reportJobLog.jsp

index 94433de..2c2c2ab 100644 (file)
@@ -10,14 +10,20 @@ import java.nio.file.Paths;
 import java.nio.file.Files;
 import java.util.List;
 
+import compbio.engine.ProteoCachePropertyHelperManager;
+import compbio.util.PropertyHelper;
+
 public class ArchivedJob {
        String path;
        String id;
+       String jobfilename;
        int filesize;
        List<String> files;
+       private static final PropertyHelper ph = ProteoCachePropertyHelperManager.getPropertyHelper();
 
        public ArchivedJob(String id) {
                this.id = id;
+               jobfilename = id + ".tar.gz";
        }
 
        public boolean copyArchiveFromWeb(String webpath) throws IOException, MalformedURLException {
@@ -25,9 +31,21 @@ public class ArchivedJob {
                ReadableByteChannel rbc = Channels.newChannel(website.openStream());
                FileOutputStream fos = new FileOutputStream(path);
                fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+               fos.close();
                return true;
        }
 
+       public String prepareJobArchiveToWeb() throws IOException {
+               String resultpath = ph.getProperty("archive.web.dir");
+               String thefile = ph.getProperty("archive.path") + '/' + jobfilename;
+               String finalpath = ProteoCachePropertyHelperManager.getLocalPath() + resultpath + '/' + jobfilename;
+               if (Files.isReadable(Paths.get(thefile))) {
+                       Files.copy(Paths.get(thefile), Paths.get(finalpath));
+                       return  resultpath + '/' + jobfilename;
+               }
+               return null;
+       }
+
        public boolean copyArchiveLocaly(String localpath) throws IOException {
                Files.copy(Paths.get(localpath), Paths.get(path));
                return true;
index 640dd29..a2b952c 100644 (file)
@@ -1,6 +1,6 @@
 package compbio.controllers;
 
-import java.security.Principal;
+import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -14,14 +14,27 @@ import org.springframework.web.bind.annotation.RequestParam;
 
 import compbio.statistic.CassandraRequester;
 import compbio.cassandra.DataBase;
+import compbio.engine.archive.ArchivedJob;
 
 /**
  * @author Alexander Sherstnev
  * @author Natasha Sherstneva
+ * @version 1.0 Dec 2013
  */
 @Controller
 public class JobController extends BasicController {
 
+       /**
+        * form a query page for job execution time statistics. The servlet should be
+        * available for users and admins only. By defaults the report time range is
+        * from the earliest day with jobs to today ("Query for all dates" is
+        * ticked). If the user removes the tick the time range is from today - 3
+        * days to today. Currently, the input model is empty.
+        * 
+        * @param model
+        *            MVC model
+        * @return link to the JSP query page
+        */
        @RequestMapping(value = "/stat/exectime/query", method = RequestMethod.GET)
        public String initFormExecTime(Map<String, Object> model) {
                model.put("username", getPrincipalName());
@@ -35,6 +48,13 @@ public class JobController extends BasicController {
                return "query/JobTimeExecution";
        }
 
+       /**
+        * form a query page for a job. The servlet should no be visible to users at all. 
+        * 
+        * @param model
+        *            MVC model
+        * @return link to the JSP query page
+        */
        @RequestMapping(value = "/job/query", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
                model.put("username", getPrincipalName());
@@ -74,9 +94,16 @@ public class JobController extends BasicController {
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("IdJob", jobid);
+
+               ArchivedJob aj = new ArchivedJob(jobid);
+               try {
+                       model.put("jobarchive", aj.prepareJobArchiveToWeb());
+               } catch (IOException e) {
+                       //TODO. what should we do if job is not available???
+               }
                return "reportJobLog";
        }
-       
+
        /*
         * convert ???
         */
@@ -85,5 +112,5 @@ public class JobController extends BasicController {
                String dateString = datformat.format(new Date(indate));
                return dateString;
        }
-       
+
 }
index 0a0de7a..be5e464 100644 (file)
@@ -29,6 +29,6 @@ public class WebConfig extends WebMvcConfigurerAdapter {
                registry.addResourceHandler("/css/**").addResourceLocations("/css/");
                registry.addResourceHandler("/images/**").addResourceLocations("/images/");
                registry.addResourceHandler("/js/**").addResourceLocations("/js/");
+               registry.addResourceHandler("/results/**").addResourceLocations("/results/");
        }
-
-}
\ No newline at end of file
+}
index 3772fbb..da1fcde 100644 (file)
 <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <p>IP: <a title="Click to view other jobs" href="${ip_query}?ip=${result.ip}">${result.ip}</a></p>
 </sec:authorize>
+                       <c:if test='${jobarchive != null}'>
+                               <spring:url value="../${jobarchive}" var="jobarchivefile" />
+                               <p>Job archive: <a title="Click to get the file" href="${jobarchivefile}">download</a></p>
+                       </c:if>
                        <table class="table table-striped table-hover table-bordered">
                        <tbody>
                                <tr>