X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=server%2Fcompbio%2Fcontrollers%2FJobController.java;h=c1c7af84f64a16c0a599cb9fef537808bf86ae55;hb=e8aea0549be548d481fddd08c9e15eac54b73770;hp=264a5d1488118e9da96fea7a7a1955aa74ec6358;hpb=32cb93e5d1032189360155cbeedd45adadebfd46;p=proteocache.git diff --git a/server/compbio/controllers/JobController.java b/server/compbio/controllers/JobController.java index 264a5d1..c1c7af8 100644 --- a/server/compbio/controllers/JobController.java +++ b/server/compbio/controllers/JobController.java @@ -1,10 +1,9 @@ package compbio.controllers; import java.io.IOException; -import java.text.SimpleDateFormat; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.Calendar; -import java.util.Date; -import java.util.List; import java.util.Map; import org.apache.log4j.Logger; @@ -14,7 +13,11 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import compbio.statistic.CassandraRequester; -import compbio.cassandra.DataBase; +import compbio.beans.ExecutionTimeBean; +import compbio.beans.TotalExecutionTime; +import compbio.cassandra.DateFormatter; +import compbio.cassandra.readers.CassandraReader; +import compbio.cassandra.readers.ExecutionTimeReader; import compbio.cassandra.readers.JobReader; import compbio.engine.archive.ArchivedJob; @@ -79,36 +82,51 @@ public class JobController extends BasicController { @RequestParam(value = "option", required = false) String option, Map model) { model.put("username", getPrincipalName()); final long startTime = System.currentTimeMillis(); - - CassandraRequester sp = new CassandraRequester(); + Calendar loccal = Calendar.getInstance(); + ExecutionTimeReader reader = new ExecutionTimeReader(); if (option.equals("AllDates,off")) { - Calendar cal = Calendar.getInstance(); - date1 = DateFormatYYMMDD(sp.earliestDate()); - date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); + date1 = theEaerlistDate; + date2 = theCurrentDate; + } + + // dates in string format + String trimmeddate1 = date1.replaceAll("\\s", ""); + String trimmeddate2 = date2.replaceAll("\\s", ""); + // dates in long format + long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD); + long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD); + String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2); + if (error != null) { + model.put("error", error); + model.put("date1", date1); + model.put("date2", date2); + return "query/JobTimeExecution"; } + + if (longDate1 < CassandraReader.earliestDate()) + longDate1 = CassandraReader.earliestDate(); + if (longDate2 > loccal.getTimeInMillis()) + longDate2 = loccal.getTimeInMillis(); + + date1 = DateFormatter.DateLongToString(longDate1, formaterYYMMDD); + date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD); model.put("date1", date1); model.put("date2", date2); model.put("option", option); - List res = sp.extractExecutionTime(date1, date2); + ExecutionTimeBean res = reader.query(longDate1, longDate2);; model.put("result", res); + Map results = res.getDateTotal(); String csvline = ""; - if (0 < res.size()) { + if (0 < res.getDateTotal().size()) { csvline = "\'Date\',\'Total\',\'0-30 sec\',\'30-60 sec\',\'1-2 min\',\'2-10 min\',\'more 10 min\'%0A"; - for (DataBase entry : res) { - List counts = entry.getTimeRez(); - int total = 0; - for (int i = 0; i < counts.size(); ++i) { - total += counts.get(i); - } - csvline += "\'" + entry.getDate() + "\',\'" + total; - for (int i = 0; i < counts.size(); ++i) { - csvline += "\',\'" + counts.get(i); - } - csvline += "\'%0A"; + for (Map.Entry entry : results.entrySet()) { + csvline += "\'" + entry.getKey() + "\',\'" + entry.getValue().getTotal() + "\',\'" + entry.getValue().getTotal0_30s() + "\',\'" + + entry.getValue().getTotal30_60s() + "\',\'" + entry.getValue().getTotal1_2m() + "\',\'" + + entry.getValue().getTotal2_10m() + "\',\'" + entry.getValue().getTotal10m() + "\'%0A"; } } model.put("csvfile", csvline); - model.put("ndays", res.size() - 1); + model.put("ndays", res.getDateTotal().size() - 1); final long endTime = System.currentTimeMillis(); model.put("timeExecution", (endTime - startTime)); return "/reports/TimeExecution"; @@ -121,9 +139,10 @@ public class JobController extends BasicController { * @param model * MVC model * @return link to the JSP query page + * @throws IOException */ @RequestMapping(value = "/job/results", method = RequestMethod.GET) - public String findJob(@RequestParam("IdJob") String jobid, Map model) { + public String findJob(@RequestParam("IdJob") String jobid, Map model) throws IOException { model.put("username", getPrincipalName()); final long startTime = System.currentTimeMillis(); JobReader reader = new JobReader(); @@ -139,21 +158,14 @@ public class JobController extends BasicController { log.error("JobController.prepareJobArchiveToWeb: IO exception with job archive file"); log.error(e.getLocalizedMessage(), e.getCause()); } + // add a direct link to the job + String remotelink = "http://www.compbio.dundee.ac.uk/www-jpred/results/" + jobid + "/" + jobid + ".results.html"; + URL remotelinkurl = new URL(remotelink); + HttpURLConnection httpConnection_remotelinkurl = (HttpURLConnection) remotelinkurl.openConnection(); + if (199 < httpConnection_remotelinkurl.getResponseCode() && httpConnection_remotelinkurl.getResponseCode() < 300) { + model.put("jobremotelink", remotelink); + } return "reports/Job"; } - /** - * 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"); - String dateString = datformat.format(new Date(indate)); - return dateString; - } - }