Merge branch 'DAO'
[proteocache.git] / datadb / compbio / cassandra / readers / IpReader.java
1 package compbio.cassandra.readers;
2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6
7 import com.datastax.driver.core.ResultSet;
8 import com.datastax.driver.core.Row;
9
10 import compbio.beans.UserBean;
11
12 public class IpReader extends CassandraReader {
13         
14         public IpReader() {
15                 super();
16         }
17         
18         /**
19          * query jobs by ip
20          * 
21          * @param ip
22          * 
23          * @return UserBean to the controller IPDataController
24          **/
25         public UserBean readIp(String ip) {
26                 ResultSet results = CassandraQuery("SELECT JobID, Protein, FinalStatus, DataBegin FROM ProteinLog WHERE ip = '" + ip + "';");
27                 if (results.isExhausted())
28                         return null;
29                 List<Row> rows = results.all();
30                 Map<String, String[]> res = new HashMap<String, String[]>();
31                 for (Row r : rows) {
32                         if (r.getString("FinalStatus").equals("OK")) {
33                                 String date = r.getString("DataBegin");
34                                 res.put(r.getString("JobID"), new String[] { date.substring(0, date.indexOf(":")), r.getString("Protein") });                   
35                         }
36                 }
37                 UserBean query = new UserBean(ip);
38                 query.setMainInfo(res);
39                 return query;
40         }
41
42 }