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