\r
package eu.etaxonomy.cdm.remote.controller;\r
\r
+import java.util.List;\r
+\r
+import org.springframework.web.bind.WebDataBinder;\r
+import org.springframework.web.bind.annotation.InitBinder;\r
import org.springframework.web.bind.annotation.RequestMapping;\r
import org.springframework.web.bind.annotation.RequestMethod;\r
import org.springframework.web.bind.annotation.RequestParam;\r
import eu.etaxonomy.cdm.api.service.IService;\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
+import eu.etaxonomy.cdm.remote.editor.ClassPropertyEditor;\r
\r
\r
+/**\r
+ * @author a.kohlbecker\r
+ * @date 22.07.2009\r
+ *\r
+ * @param <T>\r
+ * @param <SERVICE>\r
+ * \r
+ */\r
public abstract class BaseListController <T extends CdmBase, SERVICE extends IService<T>> extends AbstractListController<T, SERVICE> {\r
\r
public static final Integer DEFAULT_PAGESIZE = 20;\r
- public static final Integer DEFAULT_PAGE = 0;\r
+ public static final Integer DEFAULT_PAGE_NUMBER = 0;\r
\r
+ @InitBinder\r
+ public void initBinder(WebDataBinder binder) {\r
+ binder.registerCustomEditor(Class.class, new ClassPropertyEditor());\r
+ }\r
+ \r
+\r
+ /**\r
+ * @param pageNumber\r
+ * the number of the page to be returned, the first page has the\r
+ * pageNumber = 1 - <i>optional parameter</i>\r
+ * @param pageSize\r
+ * the maximum number of entities returned per page (can be null\r
+ * to return all entities in a single page) - <i>optional\r
+ * parameter</i>\r
+ * @param type\r
+ * Further restricts the type of entities to be returned. \r
+ * If null the base type <code><T></code> is being used. - <i>optional parameter</i>\r
+ * @return\r
+ */\r
@RequestMapping(method = RequestMethod.GET)\r
- public Pager<T> doGet(\r
- @RequestParam(value = "page", required = false) Integer page,\r
- @RequestParam(value = "pageSize", required = false) Integer pageSize) {\r
+ public Pager<T> doPage(\r
+ @RequestParam(value = "pageNumber", required = false) Integer pageNumber,\r
+ @RequestParam(value = "pageSize", required = false) Integer pageSize,\r
+ @RequestParam(value = "class", required = false) Class<T> type) {\r
\r
- if(page == null){ page = DEFAULT_PAGE;}\r
+ if(pageNumber == null){ pageNumber = DEFAULT_PAGE_NUMBER;}\r
if(pageSize == null){ pageSize = DEFAULT_PAGESIZE;}\r
\r
- return (Pager<T>) service.list(pageSize, page);\r
+ return service.page(type, pageSize, pageNumber, null, DEFAULT_INIT_STRATEGY);\r
+ }\r
+ \r
+ /**\r
+ * Parameter less method to be used as default when request without parameter are made. Otherwise\r
+ * the nameless methods {@link #doPage(Integer, Integer, Class)} and {@link #doList(Integer, Integer, Class)}\r
+ * are ambigous.\r
+ * @return\r
+ */\r
+ @RequestMapping(method = RequestMethod.GET)\r
+ public Pager<T> doPage(){\r
+ return doPage(null, null, null);\r
+ }\r
+ \r
+ /**\r
+ * @param start\r
+ * The offset index from the start of the list. The first entity\r
+ * has the index = 0 - <i>required parameter</i>\r
+ * @param limit\r
+ * The maximum number of entities returned. - <i>optional parameter</i>\r
+ * @param type\r
+ * Further restricts the type of entities to be returned. \r
+ * If null the base type <code><T></code> is being used. - <i>optional parameter</i>\r
+ * @return a List of entities\r
+ */\r
+ @RequestMapping(method = RequestMethod.GET)\r
+ public List<T> doList(\r
+ @RequestParam(value = "start", required = true) Integer start,\r
+ @RequestParam(value = "limit", required = false) Integer limit,\r
+ @RequestParam(value = "class", required = false) Class<T> type) {\r
+ \r
+ //if(start == null){ start = 0;}\r
+ if(limit == null){ limit = DEFAULT_PAGESIZE;}\r
+ //TODO implement initialization\r
+ return service.list(type, limit, start, null, DEFAULT_INIT_STRATEGY);\r
}\r
\r
/* TODO \r