Merge branch 'servlets' of https://source.jalview.org/git/proteocache into servlets
authorNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 5 Dec 2013 10:22:53 +0000 (10:22 +0000)
committerNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 5 Dec 2013 10:22:53 +0000 (10:22 +0000)
Conflicts:
server/compbio/controllers/JobExecutionTimeController.java
server/compbio/controllers/SequenceController.java
server/compbio/statistic/CassandraRequester.java

15 files changed:
.classpath
WEB-INF/lib/spring-security-acl-3.1.4.RELEASE.jar [new file with mode: 0644]
WEB-INF/lib/spring-security-config-3.1.4.RELEASE.jar [new file with mode: 0644]
WEB-INF/lib/spring-security-core-3.1.4.RELEASE.jar [new file with mode: 0644]
WEB-INF/lib/spring-security-taglibs-3.1.4.RELEASE.jar [new file with mode: 0644]
WEB-INF/lib/spring-security-web-3.1.4.RELEASE.jar [new file with mode: 0644]
WEB-INF/spring-security.xml [new file with mode: 0644]
server/compbio/controllers/DailyStatisticsController.java
server/compbio/controllers/HelpController.java
server/compbio/controllers/JobExecutionTimeController.java
server/compbio/controllers/SequenceController.java
server/compbio/statistic/CassandraRequester.java
webapp/view/queryProteinSequence.jsp
webapp/view/reportJobStatistics.jsp
webapp/view/reportTimeExecution.jsp

index b86a25c..5931fd0 100644 (file)
@@ -24,8 +24,6 @@
        <classpathentry kind="lib" path="WEB-INF/lib/commons-logging-1.1.1.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/spring-aop-3.2.3.RELEASE.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/spring-beans-3.2.3.RELEASE.jar"/>
-       <classpathentry kind="lib" path="WEB-INF/lib/spring-context-3.2.3.RELEASE.jar"/>
-       <classpathentry kind="lib" path="WEB-INF/lib/spring-context-support-3.2.3.RELEASE.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/spring-core-3.2.3.RELEASE.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/spring-data-commons-1.5.2.RELEASE.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/spring-data-jpa-1.3.4.RELEASE.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/spring-tx-3.2.3.RELEASE.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/spring-web-3.2.3.RELEASE.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/spring-webmvc-3.2.3.RELEASE.jar" sourcepath="/home/asherstnev/.m2/repository/org/springframework/spring-webmvc/3.2.3.RELEASE/spring-webmvc-3.2.3.RELEASE-sources.jar"/>
+       <classpathentry kind="lib" path="WEB-INF/lib/spring-context-3.2.3.RELEASE.jar"/>
+       <classpathentry kind="lib" path="WEB-INF/lib/spring-context-support-3.2.3.RELEASE.jar"/>
+       <classpathentry kind="lib" path="WEB-INF/lib/spring-security-acl-3.1.4.RELEASE.jar"/>
+       <classpathentry kind="lib" path="WEB-INF/lib/spring-security-config-3.1.4.RELEASE.jar"/>
+       <classpathentry kind="lib" path="WEB-INF/lib/spring-security-core-3.1.4.RELEASE.jar"/>
+       <classpathentry kind="lib" path="WEB-INF/lib/spring-security-taglibs-3.1.4.RELEASE.jar"/>
+       <classpathentry kind="lib" path="WEB-INF/lib/spring-security-web-3.1.4.RELEASE.jar"/>
        <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_45"/>
        <classpathentry kind="output" path="WEB-INF/classes"/>
diff --git a/WEB-INF/lib/spring-security-acl-3.1.4.RELEASE.jar b/WEB-INF/lib/spring-security-acl-3.1.4.RELEASE.jar
new file mode 100644 (file)
index 0000000..fef6607
Binary files /dev/null and b/WEB-INF/lib/spring-security-acl-3.1.4.RELEASE.jar differ
diff --git a/WEB-INF/lib/spring-security-config-3.1.4.RELEASE.jar b/WEB-INF/lib/spring-security-config-3.1.4.RELEASE.jar
new file mode 100644 (file)
index 0000000..8eafd04
Binary files /dev/null and b/WEB-INF/lib/spring-security-config-3.1.4.RELEASE.jar differ
diff --git a/WEB-INF/lib/spring-security-core-3.1.4.RELEASE.jar b/WEB-INF/lib/spring-security-core-3.1.4.RELEASE.jar
new file mode 100644 (file)
index 0000000..768896d
Binary files /dev/null and b/WEB-INF/lib/spring-security-core-3.1.4.RELEASE.jar differ
diff --git a/WEB-INF/lib/spring-security-taglibs-3.1.4.RELEASE.jar b/WEB-INF/lib/spring-security-taglibs-3.1.4.RELEASE.jar
new file mode 100644 (file)
index 0000000..a5ee3ab
Binary files /dev/null and b/WEB-INF/lib/spring-security-taglibs-3.1.4.RELEASE.jar differ
diff --git a/WEB-INF/lib/spring-security-web-3.1.4.RELEASE.jar b/WEB-INF/lib/spring-security-web-3.1.4.RELEASE.jar
new file mode 100644 (file)
index 0000000..a241e24
Binary files /dev/null and b/WEB-INF/lib/spring-security-web-3.1.4.RELEASE.jar differ
diff --git a/WEB-INF/spring-security.xml b/WEB-INF/spring-security.xml
new file mode 100644 (file)
index 0000000..b5f0040
--- /dev/null
@@ -0,0 +1,24 @@
+<beans:beans xmlns="http://www.springframework.org/schema/security"
+       xmlns:beans="http://www.springframework.org/schema/beans" 
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+       http://www.springframework.org/schema/security
+       http://www.springframework.org/schema/security/spring-security-3.1.xsd">
+
+       <http auto-config="true">
+               <intercept-url pattern="/home/*" access="ROLE_USER" />
+               <form-login login-page="/login" default-target-url="/welcome"
+                       authentication-failure-url="/loginfailed" />
+               <logout logout-success-url="/logout" />
+       </http>
+
+       <authentication-manager>
+               <authentication-provider>
+                       <user-service>
+                               <user name="sherstnev" password="sasha12345" authorities="ROLE_USER" />
+                       </user-service>
+               </authentication-provider>
+       </authentication-manager>
+
+</beans:beans>
index 8bd718e..b6d5bde 100644 (file)
@@ -32,7 +32,7 @@ public class DailyStatisticsController {
 
                model.put("date1", date1);
                model.put("date2", date2);
-               
+
                return "queryJobStatistics";
        }
 
@@ -51,12 +51,13 @@ public class DailyStatisticsController {
                model.put("date2", date2);
                TotalJobsStatisticBean res = cr.countJobs(date1, date2);
                model.put("result", res);
+               model.put("ndays", res.getDateTotal().size());
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("option", option);
                return "/reportJobStatistics";
        }
-       
+
        @RequestMapping(value = "/stat/oneday", method = RequestMethod.GET)
        public String findJobsInOneDay(@RequestParam("date") String date, Map<String, Object> model) throws ParseException {
                final long startTime = System.currentTimeMillis();
index cd16fff..e0345b1 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Map;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+
 //import org.springframework.web.bind.annotation.RequestParam;
 
 /**
@@ -24,12 +25,10 @@ public class HelpController {
                return "support/Notimplemented";
        }
 
-
        @RequestMapping(value = "/help/doc", method = RequestMethod.GET)
        public String formDocPage(Map<String, Object> model) {
                return "support/Notimplemented";
        }
-       
 
        @RequestMapping(value = "/help/javadoc", method = RequestMethod.GET)
        public String formJavadoc(Map<String, Object> model) {
index 13c606d..a5e9b63 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,8 +9,8 @@ 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.statistic.CassandraRequester;
 
 /**
  * @author Alexander Sherstnev
@@ -44,7 +45,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 c57ed1f..a5b1757 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;
@@ -9,16 +10,28 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import compbio.cassandra.ProteinBean;
+import compbio.data.sequence.SequenceUtil;
 import compbio.cassandra.TotalByCounterBean;
 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) {
                model.put("value", "AAAAA");
@@ -30,12 +43,24 @@ public class SequenceController {
                model.put("value", 5);
                return "queryProteinSequenceCounter";
        }
-       
+
        @RequestMapping(value = "/sequence/querysequence", method = RequestMethod.GET)
        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);
@@ -46,7 +71,7 @@ public class SequenceController {
                        model.put("results", r);
                        if (null != r) {
                                if (flag.equals("whole"))
-                                       model.put("njobs",r.get(0).getJobid().size());
+                                       model.put("njobs", r.get(0).getJobid().size());
                                else
                                        model.put("njobs", r.size());
                        }
index 5de5066..6a54800 100755 (executable)
@@ -37,7 +37,7 @@ public class CassandraRequester {
                if (null == date2) {
                        date1 = "2100/1/1";
                }
-               if (!isThisDateValid(date1,formatYYMMDD) || !isThisDateValid(date2,formatYYMMDD)) {
+               if (!isThisDateValid(date1, formatYYMMDD) || !isThisDateValid(date2, formatYYMMDD)) {
                        System.out.println("CassandraRequester.extractExecutionTime: wrong format for date1 " + date1 + "or date2 " + date2);
                        return null;
                }
@@ -113,10 +113,11 @@ public class CassandraRequester {
                db.setTimeTotalExec(totalTime);
                query.add(db);
                return query;
+<<<<<<< HEAD
        }*/
        
        /*
-        * query: total number of jobs  for the period from date1 till date2
+        * query: total number of jobs for the period from date1 till date2
         */
        public TotalJobsStatisticBean countJobs(String date1, String date2) {
                if (null == date1) {
@@ -144,7 +145,7 @@ public class CassandraRequester {
                Calendar end = Calendar.getInstance();
                end.setTime(new Date(dateEnd));
                TotalJobsStatisticBean query = new TotalJobsStatisticBean();
-               Total wholeTotal = new Total(0,0,0,0,0);
+               Total wholeTotal = new Total(0, 0, 0, 0, 0);
                for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
                        Total res = db.ReadDateTable(date.getTime());
                        if (res == null)
@@ -163,7 +164,7 @@ public class CassandraRequester {
        /*
         * query: jobs and sequence at date
         */
-       public DateBean readJobByDay (String date) {
+       public DateBean readJobByDay(String date) {
                if (!isThisDateValid(date, formatDDMMYY)) {
                        System.out.println("CassandraRequester.readJobByDay: Wrong date format for " + date);
                        return null;
@@ -171,36 +172,34 @@ public class CassandraRequester {
                SetDateRange();
                long day = DateParsing(date, formatDDMMYY);
                if (day < earlestDate || day > currentDate)
-                       return null;    
+                       return null;
                return db.ReadProteinData(day, date);
        }
 
-
-       /* 
+       /*
         * query: protein sequence
-        **/
+        */
        public List<ProteinBean> readProteins(String protIn, String flag) {
                List<ProteinBean> result;
-               if (flag.equals("whole")) 
+               if (flag.equals("whole"))
                        result = db.ReadWholeSequence(protIn);
-                else 
-                        result = db.ReadPartOfSequence(protIn);
+               else
+                       result = db.ReadPartOfSequence(protIn);
                if (result == null)
                        return null;
-               
+
                if (flag.equals("part")) {
                        for (ProteinBean entry : result) {
                                entry.setSubProt(CreateSubprot(entry.getSequence(), protIn));
                        }
-               }                                       
+               }
                return result;
        }
-       
 
-       /* 
+       /*
         * query protein sequences with number of jobs
         */
-       public List<TotalByCounterBean> readProteinByCounter(int minimalcounter) {              
+       public List<TotalByCounterBean> readProteinByCounter(int minimalcounter) {
                List<TotalByCounterBean> query = new ArrayList<TotalByCounterBean>();
                Map<String, Integer> map = db.ReadProteinSequenceByCounter();
                if (map == null)
@@ -215,8 +214,8 @@ public class CassandraRequester {
                }
                return query;
        }
-       
-       /* 
+
+       /*
         * query ip with number of jobs
         */
        public List<TotalByCounterBean> readIpByCounter(Integer minimalcounter) {
@@ -236,6 +235,7 @@ public class CassandraRequester {
                }
                return query;
        }
+
        /*
         * query jobs log info
         */
@@ -244,8 +244,7 @@ public class CassandraRequester {
                        return null;
                return db.ReadJobLog(jobid);
        }
-       
-       
+
        /*
         * query jobs by ipStructureJobLog
         */
@@ -253,17 +252,17 @@ public class CassandraRequester {
                if (ip == null)
                        return null;
                Map<String, String[]> res = db.ReadIpWithJobs(ip);
-               if (res == null) 
+               if (res == null)
                        return null;
                UserBean query = new UserBean(ip);
                query.setMainInfo(res);
                return query;
        }
-       
+
        /*
         * create list of parts of protein sequence;
         */
-       private static List<String> CreateSubprot (String protein, String subprot) {
+       private static List<String> CreateSubprot(String protein, String subprot) {
                List<String> sub = new ArrayList<String>();
                String subStr = protein;
                while (subStr.length() > 0 && subStr.contains(subprot)) {
@@ -277,6 +276,7 @@ public class CassandraRequester {
                        sub.add(subStr);
                return sub;
        }
+
        /*
         * convert String date into long date (miliseconds since the epoch start)
         */
@@ -285,7 +285,7 @@ public class CassandraRequester {
                        return 0;
                }
                long dateWorkSt = 0;
-               
+
                try {
                        dateWorkSt = formatter.parse(datInput).getTime();
                } catch (ParseException e) {
@@ -312,7 +312,8 @@ public class CassandraRequester {
         */
        private static void SetDateRange() {
                Calendar cal = Calendar.getInstance();
-               currentDate = DateParsing(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH), formatYYMMDD);
+               currentDate = DateParsing(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH),
+                               formatYYMMDD);
                if (0 == earlestDate) {
                        CassandraRequester cr = new CassandraRequester();
                        earlestDate = cr.earliestDate();
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 7b7a515..509a539 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>