package compbio.controllers; import java.util.List; import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import compbio.beans.TotalByCounterBean; import compbio.beans.UserBean; import compbio.cassandra.readers.CassandraReader; import compbio.cassandra.readers.IpReader; import compbio.cassandra.readers.ReaderByCounter; /** * The controller * * @author Alexander Sherstnev * @author Natasha Sherstneva * @version 1.0 */ @Controller public class IPDataController extends BasicController { /** * default minimal jobs to consider a user "heavy user" */ private int minimalJobsFromIP = 5; /** * for initial page for request "heavy users" * */ @RequestMapping(value = "/admin/ip/counts/query", method = RequestMethod.GET) public String initStatisticsForm(Map model) { model.put("username", getPrincipalName()); model.put("value", minimalJobsFromIP); return "query/IPStatistics"; } /** * form query page for requesting a single IP * * @param model - MVC abstract model * @return */ @RequestMapping(value = "/admin/ip/query", method = RequestMethod.GET) public String initOneIPForm(Map model) { model.put("username", getPrincipalName()); CassandraReader cr = new CassandraReader(); model.put("value", cr.getExample("ip")); return "query/IP"; } /** * Form output model with statistics on "heavy users" * @param counter - the number of jobs for requested "heavy users" * @param model - abstract MVC model * @return */ @RequestMapping(value = "/admin/ip/counts/results", method = RequestMethod.GET) public String findIPwithCounter(@RequestParam("JobCounter") String counter, Map model) { model.put("username", getPrincipalName()); if (counter.equals("")) { model.put("error", "The value must not be empty"); model.put("value", counter); return "query/IPStatistics"; } int realcounter; try { realcounter = Integer.parseInt(counter.trim()); } catch (NumberFormatException e) { model.put("error", "The value must be an integer number"); model.put("value", counter); return "query/IPStatistics"; } if (realcounter < 1) { model.put("error", "The value must be greater than 0"); model.put("value", counter); return "query/IPStatistics"; } final long startTime = System.currentTimeMillis(); ReaderByCounter reader = new ReaderByCounter(); List r = reader.readIpByCounter(realcounter); model.put("results", r); model.put("njobs", 0); String csvline = ""; if (null != r) { model.put("njobs", r.size()); csvline = "\'Job%20 count\', \'IP\'%0A"; } // form line for CSV file for (TotalByCounterBean b : r) { csvline += "\'" + b.getTotaljobs() + "\',\'" + b.getName() + "\'%0A"; } model.put("csvfile", csvline); final long endTime = System.currentTimeMillis(); model.put("timeExecution", (endTime - startTime)); model.put("counter", realcounter); return "reports/IPstatistics"; } @RequestMapping(value = "/admin/ip/results", method = RequestMethod.GET) public String findIP(@RequestParam("ip") String ip, Map model) { model.put("username", getPrincipalName()); final long startTime = System.currentTimeMillis(); IpReader reader = new IpReader(); UserBean r = reader.readIp(ip); model.put("results", r); model.put("njobs", 0); if (null != r) { model.put("njobs", r.getMainInfo().size()); } final long endTime = System.currentTimeMillis(); model.put("timeExecution", (endTime - startTime)); model.put("ip", ip); return "reports/IP"; } }