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