Work in Progress, basic region filter implemented yet
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / StatisticsController.java
1 package eu.etaxonomy.cdm.remote.controller;
2
3 import java.io.IOException;
4 import java.util.List;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.apache.log4j.Logger;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.stereotype.Controller;
12 import org.springframework.web.bind.annotation.RequestMapping;
13 import org.springframework.web.bind.annotation.RequestMethod;
14 import org.springframework.web.bind.annotation.RequestParam;
15 import org.springframework.web.servlet.ModelAndView;
16
17 import eu.etaxonomy.cdm.api.service.IStatisticsService;
18 import eu.etaxonomy.cdm.api.service.statistics.Statistics;
19 import eu.etaxonomy.cdm.api.service.statistics.StatisticsConfigurator;
20 import eu.etaxonomy.cdm.api.service.statistics.StatisticsPartEnum;
21 import eu.etaxonomy.cdm.api.service.statistics.StatisticsTypeEnum;
22
23 /**
24 * @author sybille
25 * @created 07.11.2012 this class provides counting of different entities in a
26 * database
27 *
28 */
29 @Controller
30 @RequestMapping(value = { "/statistic" })
31 public class StatisticsController {
32
33 private static final Logger logger = Logger
34 .getLogger(StatisticsController.class);
35
36 private static final List<StatisticsTypeEnum> D = null;
37
38 private IStatisticsService service;
39
40 @Autowired
41 public void setService(IStatisticsService service) {
42 this.service = service;
43 }
44
45 StatisticsConfigurator configurator;
46
47 /**
48 * example query:
49 *
50 * <pre>
51 * part=ALL&part=CLASSIFICATION&type=DESCRIPTIVE_SOURCE_REFERENCES&type=ALL_TAXA&type=ACCEPTED_TAXA&type=SYNONYMS&type=TAXON_NAMES&type=ALL_REFERENCES&type=NOMECLATURAL_REFERENCES
52 * </pre>
53 *
54 * @param part
55 * @param type
56 * @param request
57 * @param response
58 * @return
59 * @throws IOException
60 */
61 @RequestMapping(method = RequestMethod.GET)
62 public ModelAndView doStatistics(
63 @RequestParam(value = "part", required = false) String[] part,
64 @RequestParam(value = "type", required = false) String[] type,
65 HttpServletRequest request, HttpServletResponse response)
66 throws IOException {
67
68 configurator = new StatisticsConfigurator();
69 ModelAndView mv = new ModelAndView();
70
71 createConfigurator(part, type);
72 // service.getStatistics(configurator);
73 Statistics statistics = service.getCountStatistics(configurator);
74 logger.info("doStatistics() - " + request.getServletPath());
75
76 mv.addObject(statistics);
77 return mv;
78 }
79
80 private void createConfigurator(String[] part, String[] type) {
81
82 if (part != null) {
83 for (String string : part) {
84 configurator.addPart(StatisticsPartEnum.valueOf(string));
85 }
86 } else
87 configurator.addPart(StatisticsPartEnum.ALL);
88
89 if (type != null) {
90 for (String string : type) {
91 configurator.addType(StatisticsTypeEnum.valueOf(string));
92 }
93 } else
94 setDefaultType();
95 }
96
97 private void setDefaultType() {
98 // for default choose all types:
99 for (StatisticsTypeEnum type : StatisticsTypeEnum.values()) {
100 configurator.addType(type);
101 }
102
103 }
104 }