Add additional checks of input parameters
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Tue, 3 Dec 2013 14:04:05 +0000 (14:04 +0000)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Tue, 3 Dec 2013 14:04:05 +0000 (14:04 +0000)
server/compbio/controllers/DailyStatisticsController.java
server/compbio/controllers/JobExecutionTimeController.java
server/compbio/controllers/SequenceController.java
webapp/view/queryProteinSequence.jsp
webapp/view/reportJobStatistics.jsp
webapp/view/reportTimeExecution.jsp

index edfe876..c9df6be 100644 (file)
@@ -52,6 +52,7 @@ public class DailyStatisticsController {
                model.put("date2", date2);
                List<DataBase> res = cr.countJobs(date1, date2);
                model.put("result", res);
+               model.put("ndays", res.size());
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("option", option);
index 191a40c..6170078 100644 (file)
@@ -1,6 +1,7 @@
 package compbio.controllers;
 
 import java.util.Calendar;
+import java.util.List;
 import java.util.Map;
 
 import org.springframework.stereotype.Controller;
@@ -8,7 +9,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
+
 import compbio.statistic.CassandraRequester;
+import compbio.cassandra.DataBase;
 import compbio.statistic.StatisticsProt;
 
 /**
@@ -44,7 +47,9 @@ public class JobExecutionTimeController {
                model.put("date1", date1);
                model.put("date2", date2);
                model.put("option", option);
-               model.put("result", sp.extractExecutionTime(date1, date2));
+               List<DataBase> res = sp.extractExecutionTime(date1, date2);
+               model.put("result", res);
+               model.put("ndays", res.size() - 1);
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                return "/reportTimeExecution";
index 2986312..0f154d3 100644 (file)
@@ -2,6 +2,7 @@ package compbio.controllers;
 
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -10,14 +11,25 @@ import org.springframework.web.bind.annotation.RequestParam;
 
 import compbio.cassandra.ProteinBean;
 import compbio.cassandra.DataBase;
+import compbio.data.sequence.SequenceUtil;
 import compbio.statistic.CassandraRequester;
 
 /**
+ * Spring controller for sequence search. This version works in the servlet style.
+ * 
  * @author Alexander Sherstnev
  * @author Natasha Sherstneva
+ * 
+ * @since 0.5
+ * @version 1.0 December 2013
  */
 @Controller
 public class SequenceController {
+       
+       /**
+        * pattern for NON-protein alphabet  symbols
+        */
+       private final Pattern NONPROTEIN = Pattern.compile("[^ARNDCQEGHILKMFPSTWYV]+", Pattern.CASE_INSENSITIVE);
 
        @RequestMapping(value = "/sequence/query1", method = RequestMethod.GET)
        public String formSequenceQuery(Map<String, Object> model) {
@@ -35,7 +47,19 @@ public class SequenceController {
        public String findSequence(@RequestParam("sequence") String sequence, @RequestParam("protein") String flag, Map<String, Object> model) {
                final long startTime = System.currentTimeMillis();
 
+               // input checks
                String trimmedsequence = sequence.replaceAll("\\s", "");
+               if (trimmedsequence.equalsIgnoreCase("")) {
+                       model.put("error", "The sequence cann't be empty");
+                       model.put("value", sequence);
+                       return "queryProteinSequence";
+               }
+               if (NONPROTEIN.matcher(trimmedsequence).find()) {
+                       model.put("error", "The sequence contains symbols not from the standard protein alphabet");
+                       model.put("value", sequence);
+                       return "queryProteinSequence";
+               }
+
                model.put("njobs", 0);
                model.put("prot", trimmedsequence);
                model.put("flag", flag);
index a0bde5a..7feeb4e 100644 (file)
@@ -1,6 +1,7 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
 <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
 <body>
        <div class="container">
        <jsp:include page="fragments/mainmenu.jsp" />
+       <spring:url value="/sequence/querysequence" var="query"/>
 
        <div class="panel panel-default">
                <div class="panel-heading">
                        <div style="font-weight:bold;">Enter protein sequence</div>
                </div>
                <div class="panel-body">
-                       <spring:url value="/sequence/querysequence" var="formurl"/>
-                       <form method="get" action="${fn:escapeXml(formurl)}">
-                               <p><textarea class="form-control" rows="3" name="sequence">${value}</textarea></p>
-                               <p><input type="radio" name="protein" value="whole">search for the whole sequence<br/>
-                               <input type="radio" name="protein" value="part" Checked>search for partial sequence matching</p>
-                               <input type="submit" name="Search" value="Search"/>
+                       <form method="get" action="${query}">
+                       <c:choose>
+                       <c:when test="${error == null}">
+                               <div class="form-group">
+                                       <p><textarea class="form-control" rows="3" name="sequence">${value}</textarea></p>
+                                       <p><input type="radio" name="protein" value="whole">search for the whole sequence<br/>
+                                       <input type="radio" name="protein" value="part" Checked>search for partial sequence matching</p>
+                                       <input type="submit" name="Search" value="Search"/>
+                               </div>
+                       </c:when>
+                       <c:otherwise>
+                               <div class="form-group has-error">
+                                       <p><textarea class="form-control" rows="3" name="sequence">${value}</textarea></p>
+                                       <p class="help-block">${error}</p>
+                                       <p><input type="radio" name="protein" value="whole">search for the whole sequence<br/>
+                                       <input type="radio" name="protein" value="part" Checked>search for partial sequence matching</p>
+                                       <input type="submit" name="Search" value="Search"/>
+                               </div>
+                       </c:otherwise>
+                       </c:choose>
                        </form>
                </div>
        </div>
index 5c707b7..59a0cb1 100644 (file)
        <div class="panel-heading">
                <c:choose>
                        <c:when test="${option == 'AllDates,off'}">
-                               <p style="font-weight:bold;">Jobs statistics for the whole period</p>
+                               <p style="font-weight:bold;">Jobs statistics for the whole period (${ndays} days)</p>
                        </c:when>
                        <c:otherwise>
                                <p style="font-weight:bold;">
-                               Jobs statistics for the time period: <c:out value="${date1}" /> to <c:out value="${date2}"/>
+                               Jobs statistics for the time period: <c:out value="${date1}" /> to <c:out value="${date2}"/> (${ndays} days)
                                </p>
                        </c:otherwise>
                </c:choose>
index 907a578..fceb06e 100644 (file)
        <div class="panel-heading">
                <c:choose>
                        <c:when test="${option == 'AllDates,off'}">
-                               <p style="font-weight:bold;">Time execution for the whole period</p>
+                               <p style="font-weight:bold;">Time execution for the whole period (${ndays} days)</p>
                        </c:when>
                        <c:otherwise>
-                               <p style="font-weight:bold;">Time execution for the interval: ${date1} - ${date2}</p>
+                               <p style="font-weight:bold;">Time execution for the interval: ${date1} - ${date2} (${ndays} days)</p>
                        </c:otherwise>
                </c:choose>
        </div>
                                                <c:when test="${loop.last}">
                                                        <tr style="font-weight: bolder;">
                                                                <td style="text-align: right">Total numbers:</td>
-                                                               <td style="text-align: right">0</td>
+                                                               <c:set var="alldaytotal" value="0"/>
+                                                               <c:forEach items="${res.timeTotalExec}" var="total">
+                                                                       <c:set var="alldaytotal" value="${alldaytotal + total}"/>
+                                                               </c:forEach>
+                                                               <td style="text-align: right">${alldaytotal}</td>
                                                                <c:forEach items="${res.timeTotalExec}" var="total">
                                                                        <td style="text-align: right">${total}</td>
                                                                </c:forEach>
                                                <c:when test="${not loop.last}">
                                                        <tr>
                                                                <td style="text-align: center">${res.date}</td>
-                                                               <td style="text-align: right">0</td>
+                                                               <c:set var="daytotal" value="0"/>
+                                                               <c:forEach items="${res.timeRez}" var="time">
+                                                                       <c:set var="daytotal" value="${daytotal + time}"/>
+                                                               </c:forEach>
+                                                               <td style="text-align: right">${daytotal}</td>
                                                                <c:forEach items="${res.timeRez}" var="time">
                                                                        <td style="text-align: right">${time}</td>
                                                                </c:forEach>