Centralize initial examples of job id and IP
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Fri, 20 Dec 2013 11:37:35 +0000 (11:37 +0000)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Fri, 20 Dec 2013 11:37:35 +0000 (11:37 +0000)
server/compbio/controllers/IPDataController.java
server/compbio/controllers/JobController.java
server/compbio/statistic/CassandraRequester.java

index ae3ca75..5f3f5e1 100644 (file)
@@ -29,7 +29,8 @@ public class IPDataController extends BasicController {
        @RequestMapping(value = "/admin/ip/query", method = RequestMethod.GET)
        public String initOneIPForm(Map<String, Object> model) {
                model.put("username", getPrincipalName());
-               model.put("value", "127.0.0.1");
+               CassandraRequester cr = new CassandraRequester();
+               model.put("value", cr.getExample("ip"));
                return "query/IP";
        }
 
index a2b952c..4819e75 100644 (file)
@@ -7,12 +7,14 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.log4j.Logger;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import compbio.statistic.CassandraRequester;
+import compbio.cassandra.CassandraNativeConnector;
 import compbio.cassandra.DataBase;
 import compbio.engine.archive.ArchivedJob;
 
@@ -23,11 +25,12 @@ import compbio.engine.archive.ArchivedJob;
  */
 @Controller
 public class JobController extends BasicController {
+       private static Logger log = Logger.getLogger(JobController.class);
 
        /**
-        * 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
+        * 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.
         * 
@@ -49,7 +52,8 @@ public class JobController extends BasicController {
        }
 
        /**
-        * form a query page for a job. The servlet should no be visible to users at all. 
+        * form a query page for a job. The servlet should no be visible to users at
+        * all.
         * 
         * @param model
         *            MVC model
@@ -58,10 +62,18 @@ public class JobController extends BasicController {
        @RequestMapping(value = "/job/query", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
                model.put("username", getPrincipalName());
-               model.put("value", "jp_NzBOJKo");
+               CassandraRequester cr = new CassandraRequester();
+               model.put("value", cr.getExample("jobid"));
                return "query/JobLog";
        }
 
+       /**
+        * form a report page for a job execution time statistics.
+        * 
+        * @param model
+        *            MVC model
+        * @return link to the JSP query page
+        */
        @RequestMapping(value = "/stat/exectime/results", method = RequestMethod.GET)
        public String findExecTimeData(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
                        @RequestParam(value = "option", required = false) String option, Map<String, Object> model) {
@@ -85,6 +97,14 @@ public class JobController extends BasicController {
                return "/reportTimeExecution";
        }
 
+       /**
+        * 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/results", method = RequestMethod.GET)
        public String findJob(@RequestParam("IdJob") String jobid, Map<String, Object> model) {
                model.put("username", getPrincipalName());
@@ -99,13 +119,20 @@ public class JobController extends BasicController {
                try {
                        model.put("jobarchive", aj.prepareJobArchiveToWeb());
                } catch (IOException e) {
-                       //TODO. what should we do if job is not available???
+                       log.error("JobController.prepareJobArchiveToWeb: IO exception with job archive file");
+                       log.error(e.getLocalizedMessage(), e.getCause());
                }
                return "reportJobLog";
        }
 
-       /*
-        * convert ???
+       /**
+        * convert date from the standard long representation (milliseconds from 1
+        * Jan 1970) to yyyy/mm/dd
+        * 
+        * @param indate
+        *            date in milliseconds from 1 Jan 1970
+        * @return date 
+        *            in the form of yyyy/mm/dd
         */
        private String DateFormatYYMMDD(long indate) {
                SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
index 3e5db8a..0ce458b 100755 (executable)
@@ -122,25 +122,21 @@ public class CassandraRequester {
         * query: total number of jobs for the period from date1 till date2
         */
        public TotalJobsStatisticBean countJobs(String date1, String date2) {
-       /*      if (null == date1) {
-                       date1 = "1970/1/1";
-               }
-               if (null == date2) {
-                       date1 = "2100/1/1";
-               }
-               if (!isThisDateValid(date1, formatYYMMDD) || !isThisDateValid(date2, formatYYMMDD)) {
-                       System.out.println("CassandraRequester.countJobs: wrong format for date1 " + date1 + "or date2 " + date2);
-                       return null;
-               }*/
+               /*
+                * if (null == date1) { date1 = "1970/1/1"; } if (null == date2) { date1
+                * = "2100/1/1"; } if (!isThisDateValid(date1, formatYYMMDD) ||
+                * !isThisDateValid(date2, formatYYMMDD)) { System.out.println(
+                * "CassandraRequester.countJobs: wrong format for date1 " + date1 +
+                * "or date2 " + date2); return null; }
+                */
                SetDateRange();
                long dateStart = DateParsing(date1, formatYYMMDD);
                long dateEnd = DateParsing(date2, formatYYMMDD);
-/*             if (dateEnd < earlestDate || dateStart > currentDate || dateStart > dateEnd)
-                       return null;
-               if (dateStart < earlestDate)
-                       dateStart = earlestDate;
-               if (dateEnd > currentDate)
-                       dateStart = currentDate;*/
+               /*
+                * if (dateEnd < earlestDate || dateStart > currentDate || dateStart >
+                * dateEnd) return null; if (dateStart < earlestDate) dateStart =
+                * earlestDate; if (dateEnd > currentDate) dateStart = currentDate;
+                */
                Calendar start = Calendar.getInstance();
                start.setTime(new Date(dateStart));
                Calendar end = Calendar.getInstance();
@@ -174,7 +170,7 @@ public class CassandraRequester {
                long day = DateParsing(date, formatDDMMYY);
                if (day < earlestDate || day > currentDate)
                        return null;
-               
+
                if (status == JobStatus.OK) {
                        return db.ReadProteinData(day, date);
                }
@@ -200,21 +196,22 @@ public class CassandraRequester {
                }
                return result;
        }
-       
+
        /*
         * query: protein feature
         */
        public Map<String, String> readProteinsPrediction(String feature, int percent) {
-               Map<String, String> result = db.ReadProtein();;
+               Map<String, String> result = db.ReadProtein();
+               ;
                if (result == null)
                        return null;
                Map<String, String> query = new HashMap<String, String>();
                for (Map.Entry<String, String> entry : result.entrySet()) {
-                       String pred = entry.getValue();                 
-                       if (pred.replaceAll("[^"+feature+"]", "").length() > pred.length() * percent / 100 && (!entry.getKey().equals(""))) {
-                       //      if (!entry.getKey().equals(""))
-                                       query.put(entry.getKey(), pred);
-                       }       
+                       String pred = entry.getValue();
+                       if (pred.replaceAll("[^" + feature + "]", "").length() > pred.length() * percent / 100 && (!entry.getKey().equals(""))) {
+                               // if (!entry.getKey().equals(""))
+                               query.put(entry.getKey(), pred);
+                       }
                }
                return query;
        }
@@ -360,4 +357,22 @@ public class CassandraRequester {
                return earlestDate;
        }
 
+       /**
+        * prepares an example of either job id or IP for the DB
+        * 
+        * @param exampletype
+        *            defines which example you need (an existing job from the DB -
+        *            jobid, an IP - "ip")
+        * @return a string representation of the requested example, if the example
+        *         type is not known empty string is returned
+        */
+       public String getExample(String exampletype) {
+               if (exampletype.equals("jobid")) {
+                       return "jp_NzBOJKo";
+               } else if (exampletype.equals("ip")) {
+                       return "127.0.0.1";
+               }
+               return "";
+       }
+
 }