import com.datastax.driver.core.Session;
import com.datastax.driver.core.exceptions.QueryExecutionException;
import com.datastax.driver.core.exceptions.QueryValidationException;
+
import compbio.cassandra.CassandraNativeConnector;
public class CassandraReader {
- private static long earlestDate = 0;
- private Session session;
+ protected static long earlestDate = 0;
+ protected Session session;
protected static Logger log = Logger.getLogger(CassandraNativeConnector.class);
public CassandraReader() {
ResultSet results = session.execute(command);
return results;
} catch (QueryExecutionException e) {
- String mess = "CassandraUserManagerImpl.findAllUsers: query execution exception...";
+ String mess = "ProteoCache Cassandra DB interface: query execution exception...\n Command: " + command;
System.out.println(mess);
log.error(mess);
log.error(e.getLocalizedMessage(), e.getCause());
return null;
} catch (QueryValidationException e) {
- String mess = "CassandraUserManagerImpl.findAllUsers: query validation exception... Command: " + command;
+ String mess = "CProteoCache Cassandra DB interface: query validation exception...\n Command: " + command;
System.out.println(mess);
log.error(mess);
log.error(e.getLocalizedMessage(), e.getCause());
earlestDate = CassandraNativeConnector.getEarliestDateInDB();
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 "";
+ }
}
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
- import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
- import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import compbio.statistic.CassandraRequester;
import compbio.beans.DateBean;
import compbio.beans.ExecutionTimeBean;
- import compbio.beans.Total;
+ import compbio.beans.JobBean;
import compbio.beans.TotalExecutionTime;
- import compbio.beans.TotalJobsStatisticBean;
- import compbio.cassandra.DataBase;
import compbio.cassandra.DateFormatter;
import compbio.cassandra.readers.CassandraReader;
import compbio.cassandra.readers.ExecutionTimeReader;
import compbio.cassandra.readers.JobReader;
import compbio.engine.ExecutionInterval;
import compbio.engine.archive.ArchivedJob;
/**
+ * Spring controller for supporting job queries. This version works in the
+ * servlet style.
+ *
* @author Alexander Sherstnev
* @author Natasha Sherstneva
- * @version 1.0 Dec 2013
+ * @version 1.0
+ * @since Dec 2013
*/
@Controller
public class JobController extends BasicController {
@RequestMapping(value = "/job/query", method = RequestMethod.GET)
public String initFindForm(Map<String, Object> model) {
model.put("username", getPrincipalName());
- CassandraRequester cr = new CassandraRequester();
+ CassandraReader cr = new CassandraReader();
model.put("value", cr.getExample("jobid"));
return "query/JobLog";
}
/**
* form a report page for a job execution time statistics.
*
+ * @param date1
+ * initial date for requested statistics
+ * @param date2
+ * final date for requested statistics
+ * @param alldates
+ * All available jobs are analyzed if alldates="AllDates,off"
* @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) {
+ @RequestParam(value = "option", required = false) String alldates, Map<String, Object> model) {
model.put("username", getPrincipalName());
final long startTime = System.currentTimeMillis();
Calendar loccal = Calendar.getInstance();
ExecutionTimeReader reader = new ExecutionTimeReader();
- if (option.equals("AllDates,off")) {
- date1 = theEaerlistDate;
- date2 = theCurrentDate;
+ if (alldates.equals("AllDates,off")) {
+ date1 = getEarliestDate();
+ date2 = getCurrentDate();
}
-
+
// 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);
+ String error = checkDates(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())
date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD);
model.put("date1", date1);
model.put("date2", date2);
- model.put("option", option);
- ExecutionTimeBean res = reader.query(longDate1, longDate2);;
+ model.put("option", alldates);
+ ExecutionTimeBean res = reader.query(longDate1, longDate2);
+ ;
model.put("result", res);
Map<String, TotalExecutionTime> results = res.getDateTotal();
- String csvline = "";
+ StringBuilder csvline = new StringBuilder("");
if (0 < res.getDateTotal().size()) {
- csvline = "\'Date\',\'Total\',\'0-30 sec\',\'30-60 sec\',\'1-2 min\',\'2-10 min\',\'more 10 min\'%0A";
+ csvline.append("\'Date\',\'Total\',\'0-30 sec\',\'30-60 sec\',\'1-2 min\',\'2-10 min\',\'more 10 min\'%0A");
for (Map.Entry<String, TotalExecutionTime> 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";
+ csvline.append("\'" + 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("csvfile", csvline.toString());
model.put("ndays", res.getDateTotal().size() - 1);
final long endTime = System.currentTimeMillis();
model.put("timeExecution", (endTime - startTime));
if (null == ExecutionInterval.getExecutionInterval(interval))
return "support/Notimplemented";
-
ExecutionTimeReader reader = new ExecutionTimeReader();
// IMPORTANT: input should be suppied in the format: DD/MM/YYYY
DateBean r = reader.readJobByDay(thetime, realdate, ExecutionInterval.getBoundsInterval(interval));
}
/**
- * form a query page for a job. The servlet should no be visible to users at
- * all.
+ * form result page for one job with a given job ID.
*
+ * @param jobid
+ * job ID
* @param model
* MVC model
+ *
* @return link to the JSP query page
* @throws IOException
*/
model.put("username", getPrincipalName());
final long startTime = System.currentTimeMillis();
JobReader reader = new JobReader();
- model.put("result", reader.readJobLog(jobid));
+ JobBean job = reader.readJobLog(jobid);
+ if (null == job) {
+ model.put("jobnotfound", "yes");
+ } else {
+ model.put("result", job);
+ }
final long endTime = System.currentTimeMillis();
model.put("timeExecution", (endTime - startTime));
model.put("IdJob", jobid);
+ // prepare archive file for the job for downloading
ArchivedJob aj = new ArchivedJob(jobid);
try {
model.put("jobarchive", aj.prepareJobArchiveToWeb());
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);
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;
- }
-
}
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
-import compbio.statistic.CassandraRequester;
+import compbio.cassandra.readers.FeaturesReader;
/**
- * Spring controller for sequence queries. This version works in the servlet
- * style.
+ * Spring controller for protein secondary structure features. This version
+ * works in the servlet style.
*
* @author Alexander Sherstnev
* @author Natasha Sherstneva
@RequestMapping("/features")
public class SSFeaturesController extends BasicController {
+ /**
+ * form a query page for protein secondary structure feaatures: Proteins
+ * with given fraction of H/E (helix/beta sheets)
+ *
+ * @param model
+ * MVC model object
+ *
+ * @return link to the report JSP page
+ */
@RequestMapping(value = "query", method = RequestMethod.GET)
public String formCounterQuery(Map<String, Object> model) {
model.put("username", getPrincipalName());
return "query/SSFeatures";
}
+ /**
+ * form a results page for protein secondary structure features: Proteins
+ * with given fraction of H/E (helix/beta sheets) All proteins with E/H
+ * higher than a given percent of the length are returned
+ *
+ * @param model
+ * MVC model object
+ * @param typeFeature
+ * type of SS: H/E (helix/beta sheets)
+ * @param percent
+ * fraction of the protein length predicted as H/E (helix/beta
+ * sheets)
+ *
+ * @return link to the report JSP page
+ */
@RequestMapping(value = "results", method = RequestMethod.GET)
public String countSequences(@RequestParam("TypeFeatures") String typeFeature, @RequestParam("Percent") String percent,
Map<String, Object> model) {
return "query/SSFeatures";
}
- CassandraRequester cr = new CassandraRequester();
- Map<String, String> r = cr.readProteinsPrediction(typeFeature, realpercent);
+ FeaturesReader reader = new FeaturesReader();
+ Map<String, String> r = reader.readProteinsPrediction(typeFeature, realpercent);
model.put("results", r);
model.put("njobs", 0);
- String csvline = "";
+ StringBuilder csvline = new StringBuilder("");
if (null != r) {
model.put("njobs", r.size());
- csvline = "\'Prediction%20number\',\'Protein%20Sequence\', \'Secondary%20Structure%20Prediction\'%0A";
- }
+ csvline.append("\'Prediction%20number\',\'Protein%20Sequence\', \'Secondary%20Structure%20Prediction\'%0A");
- // form line for CSV file
- int counter = 1;
- for (Map.Entry<String, String> entry : r.entrySet()) {
- csvline += "\'" + counter + "\',\'" + entry.getKey() + "\',\'" + entry.getValue() + "\'%0A";
- ++counter;
+ // form line for CSV file
+ int counter = 1;
+ for (Map.Entry<String, String> entry : r.entrySet()) {
+ csvline.append("\'" + counter + "\',\'" + entry.getKey() + "\',\'" + entry.getValue() + "\'%0A");
+ ++counter;
+ }
}
- model.put("csvfile", csvline);
+ model.put("csvfile", csvline.toString());
final long endTime = System.currentTimeMillis();
model.put("timeExecution", (endTime - startTime));