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.beans.TotalByCounterBean;
12 import compbio.beans.UserBean;
13 import compbio.cassandra.readers.CassandraReader;
14 import compbio.cassandra.readers.IpReader;
15 import compbio.cassandra.readers.ReaderByCounter;
20 * @author Alexander Sherstnev
21 * @author Natasha Sherstneva
25 public class IPDataController extends BasicController {
27 * default minimal jobs to consider a user "heavy user"
29 private int minimalJobsFromIP = 5;
32 * for initial page for request "heavy users"
35 @RequestMapping(value = "/admin/ip/counts/query", method = RequestMethod.GET)
36 public String initStatisticsForm(Map<String, Object> model) {
37 model.put("username", getPrincipalName());
38 model.put("value", minimalJobsFromIP);
39 return "query/IPStatistics";
43 * form query page for requesting a single IP
45 * @param model - MVC abstract model
48 @RequestMapping(value = "/admin/ip/query", method = RequestMethod.GET)
49 public String initOneIPForm(Map<String, Object> model) {
50 model.put("username", getPrincipalName());
51 CassandraReader cr = new CassandraReader();
52 model.put("value", cr.getExample("ip"));
57 * Form output model with statistics on "heavy users"
58 * @param counter - the number of jobs for requested "heavy users"
59 * @param model - abstract MVC model
62 @RequestMapping(value = "/admin/ip/counts/results", method = RequestMethod.GET)
63 public String findIPwithCounter(@RequestParam("JobCounter") String counter, Map<String, Object> model) {
64 model.put("username", getPrincipalName());
65 if (counter.equals("")) {
66 model.put("error", "The value must not be empty");
67 model.put("value", counter);
68 return "query/IPStatistics";
73 realcounter = Integer.parseInt(counter.trim());
74 } catch (NumberFormatException e) {
75 model.put("error", "The value must be an integer number");
76 model.put("value", counter);
77 return "query/IPStatistics";
80 if (realcounter < 1) {
81 model.put("error", "The value must be greater than 0");
82 model.put("value", counter);
83 return "query/IPStatistics";
86 final long startTime = System.currentTimeMillis();
87 ReaderByCounter reader = new ReaderByCounter();
88 List<TotalByCounterBean> r = reader.readIpByCounter(realcounter);
89 model.put("results", r);
90 model.put("njobs", 0);
93 model.put("njobs", r.size());
94 csvline = "\'Job%20 count\', \'IP\'%0A";
96 // form line for CSV file
97 for (TotalByCounterBean b : r) {
98 csvline += "\'" + b.getTotaljobs() + "\',\'" + b.getName() + "\'%0A";
100 model.put("csvfile", csvline);
101 final long endTime = System.currentTimeMillis();
102 model.put("timeExecution", (endTime - startTime));
103 model.put("counter", realcounter);
104 return "reports/IPstatistics";
107 @RequestMapping(value = "/admin/ip/results", method = RequestMethod.GET)
108 public String findIP(@RequestParam("ip") String ip, Map<String, Object> model) {
109 model.put("username", getPrincipalName());
110 final long startTime = System.currentTimeMillis();
111 IpReader reader = new IpReader();
112 UserBean r = reader.readIp(ip);
113 model.put("results", r);
114 model.put("njobs", 0);
116 model.put("njobs", r.getMainInfo().size());
118 final long endTime = System.currentTimeMillis();
119 model.put("timeExecution", (endTime - startTime));