3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
12 package eu
.etaxonomy
.cdm
.remote
.controller
;
14 import java
.util
.List
;
16 import org
.springframework
.web
.bind
.WebDataBinder
;
17 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
18 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
19 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
20 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
23 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
24 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
25 import eu
.etaxonomy
.cdm
.remote
.editor
.ClassPropertyEditor
;
29 * @author a.kohlbecker
36 public abstract class BaseListController
<T
extends CdmBase
, SERVICE
extends IService
<T
>> extends AbstractListController
<T
, SERVICE
> {
38 public static final Integer DEFAULT_PAGESIZE
= 20;
39 public static final Integer DEFAULT_PAGE_NUMBER
= 0;
42 public void initBinder(WebDataBinder binder
) {
43 binder
.registerCustomEditor(Class
.class, new ClassPropertyEditor());
49 * the number of the page to be returned, the first page has the
50 * pageNumber = 1 - <i>optional parameter</i>
52 * the maximum number of entities returned per page (can be null
53 * to return all entities in a single page) - <i>optional
56 * Further restricts the type of entities to be returned.
57 * If null the base type <code><T></code> is being used. - <i>optional parameter</i>
60 @RequestMapping(method
= RequestMethod
.GET
)
61 public Pager
<T
> doPage(
62 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
63 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
64 @RequestParam(value
= "class", required
= false) Class
<T
> type
) {
66 if(pageNumber
== null){ pageNumber
= DEFAULT_PAGE_NUMBER
;}
67 if(pageSize
== null){ pageSize
= DEFAULT_PAGESIZE
;}
69 return service
.page(type
, pageSize
, pageNumber
, null, DEFAULT_INIT_STRATEGY
);
73 * Parameter less method to be used as default when request without parameter are made. Otherwise
74 * the nameless methods {@link #doPage(Integer, Integer, Class)} and {@link #doList(Integer, Integer, Class)}
78 @RequestMapping(method
= RequestMethod
.GET
)
79 public Pager
<T
> doPage(){
80 return doPage(null, null, null);
85 * The offset index from the start of the list. The first entity
86 * has the index = 0 - <i>required parameter</i>
88 * The maximum number of entities returned. - <i>optional parameter</i>
90 * Further restricts the type of entities to be returned.
91 * If null the base type <code><T></code> is being used. - <i>optional parameter</i>
92 * @return a List of entities
94 @RequestMapping(method
= RequestMethod
.GET
)
95 public List
<T
> doList(
96 @RequestParam(value
= "start", required
= true) Integer start
,
97 @RequestParam(value
= "limit", required
= false) Integer limit
,
98 @RequestParam(value
= "class", required
= false) Class
<T
> type
) {
100 //if(start == null){ start = 0;}
101 if(limit
== null){ limit
= DEFAULT_PAGESIZE
;}
102 //TODO implement initialization
103 return service
.list(type
, limit
, start
, null, DEFAULT_INIT_STRATEGY
);
107 @RequestMapping(method = RequestMethod.POST)
108 public T doPost(@ModelAttribute("object") T object, BindingResult result) {
109 validator.validate(object, result);
110 if (result.hasErrors()) {
111 // set http status code depending upon what happened, possibly return
112 // the put object and errors so that they can be rendered into a suitable error response
114 // should set the status to 201 created and "Location" header to "/resource/uuid"
115 service.save(object);