delete DataBase beans
[proteocache.git] / server / compbio / controllers / IPDataController.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.TotalByCounterBean;
12 import compbio.cassandra.UserBean;
13 import compbio.statistic.CassandraRequester;
14
15 /**
16  * @author Alexander Sherstnev
17  * @author Natasha Sherstneva
18  */
19 @Controller
20 public class IPDataController {
21
22         @RequestMapping(value = "/ip/stat", method = RequestMethod.GET)
23         public String initStatisticsForm(Map<String, Object> model) {
24                 model.put("value", 5);
25                 return "queryIPStatistics";
26         }
27
28         @RequestMapping(value = "/ip", method = RequestMethod.GET)
29         public String initOneIPForm(Map<String, Object> model) {
30                 model.put("value", "127.0.0.1");
31                 return "queryIP";
32         }
33         
34         @RequestMapping(value = "/ip/stat/querycounter", method = RequestMethod.GET)
35         public String findIPwithCounter(@RequestParam("JobCounter") String counter, Map<String, Object> model) {
36
37                 if (counter.equals("")) {
38                         model.put("error", "The value must not be empty");
39                         model.put("value", counter);
40                         return "queryIPStatistics";
41                 }
42         
43                 int realcounter;
44                 try {
45                         realcounter = Integer.parseInt(counter.trim());
46                 } catch (NumberFormatException e) {
47                         model.put("error", "The value must be an integer number");
48                         model.put("value", counter);
49                         return "queryIPStatistics";
50                 }
51
52                 if (realcounter < 1) {
53                         model.put("error", "The value must be greater than 0");
54                         model.put("value", counter);
55                         return "queryIPStatistics";
56                 }
57
58                 final long startTime = System.currentTimeMillis();
59                 CassandraRequester cr = new CassandraRequester();
60                 List<TotalByCounterBean> r = cr.readIpByCounter(realcounter);
61                 model.put("results", r);
62                 model.put("njobs", 0);
63                 if (null != r) {
64                         model.put("njobs", r.size());
65                 }
66                 final long endTime = System.currentTimeMillis();
67                 model.put("timeExecution", (endTime - startTime));
68                 model.put("counter", realcounter);
69                 return "reportIPstatistics";
70         }
71
72         @RequestMapping(value = "/ip/query", method = RequestMethod.GET)
73         public String findIP(@RequestParam("ip") String ip, Map<String, Object> model) {
74                 final long startTime = System.currentTimeMillis();
75                 CassandraRequester cr = new CassandraRequester();
76                 UserBean r = cr.readIp(ip);
77                 model.put("results", r);
78                 model.put("njobs", 0);
79                 if (null != r) {
80                         model.put("njobs", r.getMainInfo().size());
81                 }
82                 final long endTime = System.currentTimeMillis();
83                 model.put("timeExecution", (endTime - startTime));
84                 model.put("ip", ip);
85                 return "reportIP";
86         }
87 }