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.DataBase;
12 import compbio.cassandra.TotalByCounterBean;
13 import compbio.cassandra.UserBean;
14 import compbio.statistic.CassandraRequester;
17 * @author Alexander Sherstnev
18 * @author Natasha Sherstneva
21 public class IPDataController {
23 @RequestMapping(value = "/ip/stat", method = RequestMethod.GET)
24 public String initStatisticsForm(Map<String, Object> model) {
25 model.put("value", 5);
26 return "queryIPStatistics";
29 @RequestMapping(value = "/ip", method = RequestMethod.GET)
30 public String initOneIPForm(Map<String, Object> model) {
31 model.put("value", "127.0.0.1");
35 @RequestMapping(value = "/ip/stat/querycounter", method = RequestMethod.GET)
36 public String findIPwithCounter(@RequestParam("JobCounter") String counter, Map<String, Object> model) {
38 if (counter.equals("")) {
39 model.put("error", "The value must not be empty");
40 model.put("value", counter);
41 return "queryIPStatistics";
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";
53 if (realcounter < 1) {
54 model.put("error", "The value must be greater than 0");
55 model.put("value", counter);
56 return "queryIPStatistics";
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);
65 model.put("njobs", r.size());
67 final long endTime = System.currentTimeMillis();
68 model.put("timeExecution", (endTime - startTime));
69 model.put("counter", realcounter);
70 return "reportIPstatistics";
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);
81 model.put("njobs", r.getMainInfo().size());
83 final long endTime = System.currentTimeMillis();
84 model.put("timeExecution", (endTime - startTime));