created features report
[proteocache.git] / server / compbio / controllers / SSFeaturesController.java
1 package compbio.controllers;
2
3 import java.util.List;
4 import java.util.Map;
5
6 import org.springframework.stereotype.Controller;
7 import org.springframework.web.bind.annotation.RequestMapping;
8 import org.springframework.web.bind.annotation.RequestMethod;
9 import org.springframework.web.bind.annotation.RequestParam;
10
11 import compbio.cassandra.ProteinBean;
12 import compbio.cassandra.TotalByCounterBean;
13 import compbio.statistic.CassandraRequester;
14
15 /**
16  * Spring controller for sequence queries. This version works in the servlet
17  * style.
18  * 
19  * @author Alexander Sherstnev
20  * @author Natasha Sherstneva
21  * 
22  * @since 0.5
23  * @version 1.0 December 2013
24  */
25 @Controller
26 @RequestMapping("/features")
27 public class SSFeaturesController extends BasicController {
28
29                 @RequestMapping(value = "query", method = RequestMethod.GET)
30                 public String formCounterQuery(Map<String, Object> model) {
31                         model.put("username", getPrincipalName());
32                         model.put("type", 'E');
33                         model.put("value", 80);
34                         return "query/SSFeatures";
35                 }
36                         
37                 @RequestMapping(value = "features/results", method = RequestMethod.GET)
38                 public String countSequences(@RequestParam("TypeFeatures") String typeFeature, @RequestParam("Percent") String percent,Map<String, Object> model) {
39                         model.put("username", getPrincipalName());
40                         final long startTime = System.currentTimeMillis();
41
42                         if (percent.equals("")) {
43                                 model.put("error", "The value must not be empty");
44                                 model.put("type", typeFeature);
45                                 model.put("value", percent);
46                                 return "query/SSFeatures";
47                         }
48
49                         int realpercent;
50                         try {
51                                 realpercent = Integer.parseInt(percent.trim());
52                         } catch (NumberFormatException e) {
53                                 model.put("error", "The value must be an integer number");
54                                 model.put("value", percent);
55                                 return "query/SSFeatures";
56                         }
57
58                         if (realpercent < 1) {
59                                 model.put("error", "The value must be greater than 0");
60                                 model.put("value", percent);
61                                 return "query/SSFeatures";
62                         }
63                         
64                         if (realpercent > 100) {
65                                 model.put("error", "The value must be less than 100");
66                                 model.put("value", percent);
67                                 return "query/SSFeatures";
68                         }
69
70                         CassandraRequester cr = new CassandraRequester();
71                         Map<String, String> r = cr.readProteinsPrediction(typeFeature, realpercent);
72                         model.put("results", r);
73                         model.put("njobs", 0);
74                         if (null != r) {
75                                 model.put("njobs", r.size());
76                         }
77                         final long endTime = System.currentTimeMillis();
78                         model.put("timeExecution", (endTime - startTime));
79                         model.put("feature", typeFeature);
80                         model.put("percent", realpercent);
81                         return "reportSSFeatures";
82                 }
83
84         
85
86 }