1 package compbio.controllers;
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;
11 import compbio.cassandra.TotalByCounterBean;
12 import compbio.cassandra.UserBean;
13 import compbio.statistic.CassandraRequester;
16 * @author Alexander Sherstnev
17 * @author Natasha Sherstneva
20 public class IPDataController {
22 @RequestMapping(value = "/ip/stat", method = RequestMethod.GET)
23 public String initStatisticsForm(Map<String, Object> model) {
24 model.put("value", 5);
25 return "queryIPStatistics";
28 @RequestMapping(value = "/ip", method = RequestMethod.GET)
29 public String initOneIPForm(Map<String, Object> model) {
30 model.put("value", "127.0.0.1");
34 @RequestMapping(value = "/ip/stat/querycounter", method = RequestMethod.GET)
35 public String findIPwithCounter(@RequestParam("JobCounter") String counter, Map<String, Object> model) {
37 if (counter.equals("")) {
38 model.put("error", "The value must not be empty");
39 model.put("value", counter);
40 return "queryIPStatistics";
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";
52 if (realcounter < 1) {
53 model.put("error", "The value must be greater than 0");
54 model.put("value", counter);
55 return "queryIPStatistics";
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);
64 model.put("njobs", r.size());
66 final long endTime = System.currentTimeMillis();
67 model.put("timeExecution", (endTime - startTime));
68 model.put("counter", realcounter);
69 return "reportIPstatistics";
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);
80 model.put("njobs", r.getMainInfo().size());
82 final long endTime = System.currentTimeMillis();
83 model.put("timeExecution", (endTime - startTime));