move jsp for reports to a separate dir
[proteocache.git] / server / compbio / controllers / ProteomeController.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 dealing with proteomes. This version works in the
14  * servlet style.
15  * 
16  * @author Alexander Sherstnev
17  * @author Natasha Sherstneva
18  * 
19  * @since 0.5
20  * @version 1.0 December 2014
21  */
22 @Controller
23 @RequestMapping("/proteomes")
24 public class ProteomeController extends BasicController {
25
26         @RequestMapping(value = "/load", method = RequestMethod.GET)
27         public String loadProteome(Map<String, Object> model) {
28                 model.put("username", getPrincipalName());
29                 return "support/Notimplemented";
30         }
31
32         @RequestMapping(value = "view", method = RequestMethod.GET)
33         public String viewProteome(Map<String, Object> model) {
34                 model.put("username", getPrincipalName());
35                 return "support/Notimplemented";
36         }
37
38         @RequestMapping(value = "launch", method = RequestMethod.GET)
39         public String launchjobProteome(Map<String, Object> model) {
40                 model.put("username", getPrincipalName());
41                 return "support/Notimplemented";
42         }
43
44         @RequestMapping(value = "load/result", method = RequestMethod.GET)
45         public String countSequences(@RequestParam("TypeFeatures") String typeFeature, @RequestParam("Percent") String percent,
46                         Map<String, Object> model) {
47                 model.put("username", getPrincipalName());
48                 final long startTime = System.currentTimeMillis();
49
50                 if (percent.equals("")) {
51                         model.put("error", "The value must not be empty");
52                         model.put("type", typeFeature);
53                         model.put("value", percent);
54                         return "query/SSFeatures";
55                 }
56
57                 int realpercent;
58                 try {
59                         realpercent = Integer.parseInt(percent.trim());
60                 } catch (NumberFormatException e) {
61                         model.put("error", "The value must be an integer number");
62                         model.put("value", percent);
63                         return "query/SSFeatures";
64                 }
65
66                 if (realpercent < 1) {
67                         model.put("error", "The value must be greater than 0");
68                         model.put("value", percent);
69                         return "query/SSFeatures";
70                 }
71
72                 if (realpercent > 100) {
73                         model.put("error", "The value must be less than 100");
74                         model.put("value", percent);
75                         return "query/SSFeatures";
76                 }
77
78                 CassandraRequester cr = new CassandraRequester();
79                 Map<String, String> r = cr.readProteinsPrediction(typeFeature, realpercent);
80                 model.put("results", r);
81                 model.put("njobs", 0);
82                 if (null != r) {
83                         model.put("njobs", r.size());
84                 }
85                 final long endTime = System.currentTimeMillis();
86                 model.put("timeExecution", (endTime - startTime));
87                 model.put("feature", typeFeature);
88                 model.put("percent", realpercent);
89                 return "reports/SSFeatures";
90         }
91
92 }