PROT-4 Initial code for remover servlet
authorNatasha Sherstneva <n.shertneva@gmail.com>
Mon, 18 Nov 2013 21:31:47 +0000 (21:31 +0000)
committerNatasha Sherstneva <n.shertneva@gmail.com>
Mon, 18 Nov 2013 21:31:47 +0000 (21:31 +0000)
WEB-INF/web.xml
datadb/compbio/cassandra/CassandraRemover.java [new file with mode: 0644]
server/compbio/listeners/ServletDeleteRecord.java [new file with mode: 0644]
website/Update.jsp [new file with mode: 0644]

index 242a900..b8436c2 100644 (file)
        <listener>\r
                <listener-class>compbio.listeners.ContextListener</listener-class>\r
        </listener>\r
+       <servlet-mapping>\r
+               <servlet-name>ServletDeleteRecord</servlet-name>\r
+               <url-pattern>/ServletDeleteRecord</url-pattern>\r
+       </servlet-mapping>\r
 \r
 \r
        <!-- Session timeout in minutes -->\r
                </init-param>\r
                <load-on-startup>1</load-on-startup>\r
        </servlet>\r
+       <servlet>\r
+               <description>\r
+               </description>\r
+               <display-name>ServletDeleteRecord</display-name>\r
+               <servlet-name>ServletDeleteRecord</servlet-name>\r
+               <servlet-class>compbio.listeners.ServletDeleteRecord</servlet-class>\r
+       </servlet>\r
 \r
 \r
        <!-- ProteoCache servlets -->\r
diff --git a/datadb/compbio/cassandra/CassandraRemover.java b/datadb/compbio/cassandra/CassandraRemover.java
new file mode 100644 (file)
index 0000000..d066d82
--- /dev/null
@@ -0,0 +1,51 @@
+package compbio.cassandra;
+
+import org.apache.log4j.Logger;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.Session;
+
+public class CassandraRemover {
+       private Session session;
+       private static Logger log = Logger.getLogger(CassandraNativeConnector.class);
+
+       public CassandraRemover() {
+               Session inis = CassandraNativeConnector.getSession();
+               setSession (inis);
+       }
+
+       public void setSession(Session s) {
+               assert s != null;
+               session = s;
+       }
+       
+       /*
+        * getting a record from CF for current jobId
+        */
+       public StructureJobLog ReadJobLog(String jobid) {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT Protein, StartTime FROM ProteinLog WHERE JobID = '" + jobid + "';";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               Row row = results.one();
+               String com1 = "SELECT * FROM ProteinRow WHERE JobID = '" + jobid + "' ALLOW FILTERING;";
+               System.out.println("Command: " + com1);
+               ResultSet results1 = session.execute(com1);
+               if (results1.isExhausted())
+                       return null;
+               Row row1 = results1.one();
+               StructureJobLog res = new StructureJobLog(row.getString("Protein"), row.getString("JobID"), row.getString("DataBegin"),
+                               row.getString("DataEnd"), row.getString("ip"), row1.getMap("Predictions", String.class, String.class));
+               System.out.println("Query time is " + (queryTime - startTime) + " msec");
+               final long endTime = System.currentTimeMillis();
+               System.out.println(" rows analysed, execution time is " + (endTime - startTime) + " msec");
+               return res;
+       }
+       
+       
+
+}
diff --git a/server/compbio/listeners/ServletDeleteRecord.java b/server/compbio/listeners/ServletDeleteRecord.java
new file mode 100644 (file)
index 0000000..8ec6a1f
--- /dev/null
@@ -0,0 +1,43 @@
+package compbio.listeners;
+
+import java.io.IOException;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import compbio.statistic.CassandraRequester;
+
+/**
+ * Servlet implementation class ServletDeleteRecord
+ */
+public class ServletDeleteRecord extends HttpServlet {
+       private static final long serialVersionUID = 1L;
+       
+       /**request
+        * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
+        */
+       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+               CassandraRequester cr = new CassandraRequester();
+               String flagId = request.getParameter("byId");
+               String jobId = request.getParameter("id");
+               String date1 = request.getParameter("date1");
+               String date2 = request.getParameter("date2");
+               if (flagId.equals("on"))
+                       request.setAttribute("result", cr.countJobs(date1, date2));
+               System.out.println(flagId);
+//             request.setAttribute("IdJob", id);
+//             RequestDispatcher rd = request.getRequestDispatcher("/ReportLogInfo.jsp");
+//             rd.forward(request, response);
+       }
+
+       /**
+        * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
+        */
+       protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+               doGet(request, response);
+       }
+
+}
diff --git a/website/Update.jsp b/website/Update.jsp
new file mode 100644 (file)
index 0000000..844079b
--- /dev/null
@@ -0,0 +1,41 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<%@page import="java.util.*"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Update/delete data base</title>
+<script type="text/javascript">
+function show(el, id) {
+       document.getElementById(id).style.visibility = (el.checked)?"visible":"hidden";
+}
+</script>
+</head>
+<body>
+<form method="post" action="ServletDeleteRecord">
+               <h3>Delete:</h3>
+               <% Calendar cal = Calendar.getInstance();
+                       String currentdate = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
+                %>
+                <input type="checkbox" name="byId" onclick="show(this, 'id');">records with job's id
+               <div id='id' class="row" style="visibility:hidden;">
+               job id:  <input type="text" name="id" />
+          </div>
+               <input type="checkbox" name="byDate" onclick="show(this, 'date');">records for the period of dates
+          <div id='date' class="row" style="visibility:hidden;">
+               from  <input type="text" name="data1" value = <%= currentdate%> style=" width : 145px;"/>
+                               to <input type="text" name="data2" value = <%= currentdate%> />
+          </div>
+               <input type="checkbox" name="byIp" onclick="show(this, 'ip');">records with ip
+               <div id='ip' class="row" style="visibility:hidden;">
+               ip:  <input type="text" name="ip" value = '127'/>
+          </div>
+               <input type="checkbox" name="bySequence"  onclick="show(this, 'seq');">records for protein sequence<br/>                
+               <div id='seq' class="row" style="visibility:hidden;">
+               Sequence:  <input type="text" name="seq" value = "ATA"/>
+          </div>
+               <input type="submit" name="Delete" value="Delete"/>
+       </form>
+</body>
+</html>
\ No newline at end of file