refactoring taxon controllers, reducing code duplication
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / PolytomousKeyListController.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.cdm.remote.controller;
11
12 import java.io.IOException;
13 import java.util.List;
14 import java.util.UUID;
15
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
18
19 import org.apache.log4j.Logger;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.stereotype.Controller;
22 import org.springframework.web.bind.annotation.PathVariable;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.bind.annotation.RequestMethod;
25 import org.springframework.web.bind.annotation.RequestParam;
26
27 import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
28 import eu.etaxonomy.cdm.api.service.ITaxonService;
29 import eu.etaxonomy.cdm.api.service.pager.Pager;
30 import eu.etaxonomy.cdm.model.description.PolytomousKey;
31 import eu.etaxonomy.cdm.model.description.TaxonDescription;
32 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
33 import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
34
35 /**
36 * @author a.kohlbecker
37 * @date 24.03.2011
38 *
39 */
40 @Controller
41 @RequestMapping(value = {"/polytomousKey"})
42 public class PolytomousKeyListController extends IdentifiableListController<PolytomousKey, IPolytomousKeyService> {
43
44 public static final Logger logger = Logger.getLogger(PolytomousKeyListController.class);
45
46 private ITaxonService taxonService;
47
48 @Autowired
49 public void setService(IPolytomousKeyService service) {
50 this.service = service;
51 }
52
53 @Autowired
54 public void setService(ITaxonService taxonService) {
55 this.taxonService = taxonService;
56 }
57
58 @RequestMapping(
59 params = {"findByTaxonomicScope"},
60 method = RequestMethod.GET)
61 public Pager<PolytomousKey> doFindByTaxonomicScope(
62 @RequestParam(value = "findByTaxonomicScope") UUID taxonUuid,
63 @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
64 @RequestParam(value = "pageSize", required = false) Integer pageSize,
65 HttpServletRequest request,
66 HttpServletResponse response)throws IOException {
67
68 logger.info("doFindByTaxonomicScope: " + request.getRequestURI() + request.getQueryString());
69
70 PagerParameters pagerParameters = new PagerParameters(pageSize, pageNumber);
71 pagerParameters.normalizeAndValidate(response);
72
73
74 TaxonBase taxon = taxonService.find(taxonUuid);
75 Pager<PolytomousKey> pager = service.findByTaxonomicScope(taxon, pagerParameters.getPageSize(), pagerParameters.getPageIndex(), null, null);
76 return pager;
77 }
78
79 }
80