Introduce new table for programs and necessary infrastructure for the table
[proteocache.git] / datadb / compbio / cassandra / readers / JobReader.java
1 package compbio.cassandra.readers;
2
3 import com.datastax.driver.core.ResultSet;
4 import com.datastax.driver.core.Row;
5
6 import compbio.beans.JobBean;
7
8 public class JobReader extends CassandraReader {
9
10         public JobReader() {
11                 super();
12         }
13
14         /**
15          * query jobs log info
16          * 
17          * @param jobid
18          * 
19          * @return JobBean to the controller JobController
20          * 
21          **/
22         public JobBean readJobLog(String jobid) {
23                 ResultSet results = CassandraQuery("SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';");
24                 if (results.isExhausted())
25                         return null;
26                 Row row1 = results.one();
27                 ResultSet results1 = CassandraQuery("SELECT * FROM ProteinRow WHERE JobID = '" + jobid + "' ALLOW FILTERING;");
28                 if (results1.isExhausted())
29                         return null;
30                 Row row2 = results1.one();
31                 String program = row1.getString("ProgramName");
32                 String version = row1.getString("ProgramVersion");
33                 JobBean res = new JobBean(row1.getString("Protein"), row1.getString("JobID"), row1.getString("DataBegin"),
34                                 row1.getString("DataEnd"), row1.getString("ip"), row2.getMap("Predictions", String.class, String.class));
35
36                 if (null != program && null != version) {
37                         res.setProgramName(program);
38                         res.setProgramVersion(version);
39                         ResultSet results3 = CassandraQuery("SELECT * FROM Programs WHERE Program = '" + program + "' and Version = '" + version
40                                         + "' ALLOW FILTERING;");
41                         if (results3.isExhausted())
42                                 return null;
43                         Row row3 = results3.one();
44                         String link = row3.getString("weblink");
45                         if (null != link) {
46                                 res.setProgramLink(link);
47                         }
48                 }
49
50                 return res;
51         }
52 }