a little bit documentation
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / IdentifiableListController.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.Arrays;
14 import java.util.List;
15 import java.util.UUID;
16
17 import javax.servlet.http.HttpServletRequest;
18 import javax.servlet.http.HttpServletResponse;
19
20 import org.springframework.web.bind.annotation.RequestMapping;
21 import org.springframework.web.bind.annotation.RequestMethod;
22 import org.springframework.web.bind.annotation.RequestParam;
23
24 import eu.etaxonomy.cdm.api.service.IIdentifiableEntityService;
25 import eu.etaxonomy.cdm.api.service.pager.Pager;
26 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
27 import eu.etaxonomy.cdm.model.location.NamedArea;
28 import eu.etaxonomy.cdm.model.taxon.Classification;
29 import eu.etaxonomy.cdm.model.taxon.Synonym;
30 import eu.etaxonomy.cdm.model.taxon.Taxon;
31 import eu.etaxonomy.cdm.persistence.query.MatchMode;
32 import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
33
34 /**
35 * @author l.morris
36 * @date 27 Mar 2012
37 *
38 */
39 public abstract class IdentifiableListController <T extends IdentifiableEntity, SERVICE extends IIdentifiableEntityService<T>> extends BaseListController<T,SERVICE> {
40
41
42 /**
43 * Find IdentifiableEntity objects by name
44 * <p>
45 *
46 * @param query
47 * the string to query for. Since the wildcard character '*'
48 * internally always is appended to the query string, a search
49 * always compares the query string with the beginning of a name.
50 * - <i>required parameter</i>
51 * @param pageNumber
52 * the number of the page to be returned, the first page has the
53 * pageNumber = 1 - <i>optional parameter</i>
54 * @param pageSize
55 * the maximum number of entities returned per page (can be -1
56 * to return all entities in a single page) - <i>optional parameter</i>
57 * @param matchMode
58 * valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
59 * @return a Pager on a list of {@link IdentifiableEntity}s
60 * @throws IOException
61 */
62 @RequestMapping(method = RequestMethod.GET, value={"findByTitle"})
63 public Pager<T> doFindByTitle(
64 @RequestParam(value = "query", required = true) String query,
65 @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
66 @RequestParam(value = "pageSize", required = false) Integer pageSize,
67 @RequestParam(value = "matchMode", required = false) MatchMode matchMode,
68 HttpServletRequest request,
69 HttpServletResponse response
70 )
71 throws IOException {
72
73
74
75 logger.info("doFind : " + request.getRequestURI() + "?" + request.getQueryString() );
76
77 PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
78 pagerParams.normalizeAndValidate(response);
79
80 matchMode = matchMode != null ? matchMode : MatchMode.BEGINNING;
81
82 return (Pager<T>) service.findByTitle(null, query, matchMode, null, pagerParams.getPageSize(), pagerParams.getPageIndex(), null, initializationStrategy);
83
84 }
85
86
87 }