new readers for the queries
[proteocache.git] / datadb / compbio / cassandra / readers / IpReader.java
diff --git a/datadb/compbio/cassandra/readers/IpReader.java b/datadb/compbio/cassandra/readers/IpReader.java
new file mode 100644 (file)
index 0000000..2928b70
--- /dev/null
@@ -0,0 +1,42 @@
+package compbio.cassandra.readers;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+
+import compbio.beans.UserBean;
+
+public class IpReader extends CassandraReader {
+       
+       public IpReader() {
+               super();
+       }
+       
+       /**
+        * query jobs by ip
+        * 
+        * @param ip
+        * 
+        * @return UserBean to the controller IPDataController
+        **/
+       public UserBean readIp(String ip) {
+               ResultSet results = CassandraQuery("SELECT JobID, Protein, FinalStatus, DataBegin FROM ProteinLog WHERE ip = '" + ip + "';");
+               if (results.isExhausted())
+                       return null;
+               List<Row> rows = results.all();
+               Map<String, String[]> res = new HashMap<String, String[]>();
+               for (Row r : rows) {
+                       if (r.getString("FinalStatus").equals("OK")) {
+                               String date = r.getString("DataBegin");
+                               res.put(r.getString("JobID"), new String[] { date.substring(0, date.indexOf(":")), r.getString("Protein") });                   
+                       }
+               }
+               UserBean query = new UserBean(ip);
+               query.setMainInfo(res);
+               return query;
+       }
+
+}