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.cassandra.TotalByCounterBean; import compbio.cassandra.UserBean; import compbio.statistic.CassandraRequester; /** * @author Alexander Sherstnev * @author Natasha Sherstneva */ @Controller public class IPDataController extends BasicController { @RequestMapping(value = "/admin/ip/counts/query", method = RequestMethod.GET) public String initStatisticsForm(Map model) { model.put("username", getPrincipalName()); model.put("value", 5); return "query/IPStatistics"; } @RequestMapping(value = "/admin/ip/query", method = RequestMethod.GET) public String initOneIPForm(Map model) { model.put("username", getPrincipalName()); CassandraRequester cr = new CassandraRequester(); model.put("value", cr.getExample("ip")); return "query/IP"; } @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(); CassandraRequester cr = new CassandraRequester(); List r = cr.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 "reportIPstatistics"; } @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(); CassandraRequester cr = new CassandraRequester(); UserBean r = cr.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 "reportIP"; } }