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.UUID;
|
14
|
|
15
|
import javax.servlet.http.HttpServletRequest;
|
16
|
import javax.servlet.http.HttpServletResponse;
|
17
|
|
18
|
import org.apache.commons.lang.StringUtils;
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
import org.springframework.web.bind.WebDataBinder;
|
21
|
import org.springframework.web.bind.annotation.InitBinder;
|
22
|
import org.springframework.web.bind.annotation.RequestMapping;
|
23
|
import org.springframework.web.bind.annotation.RequestMethod;
|
24
|
import org.springframework.web.bind.annotation.RequestParam;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.service.IIdentifiableEntityService;
|
27
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
28
|
import eu.etaxonomy.cdm.api.service.dto.FindByIdentifierDTO;
|
29
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
30
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
31
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
32
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
33
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
34
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
35
|
import eu.etaxonomy.cdm.remote.editor.MatchModePropertyEditor;
|
36
|
|
37
|
/**
|
38
|
* @author l.morris
|
39
|
* @date 27 Mar 2012
|
40
|
*
|
41
|
*/
|
42
|
public abstract class IdentifiableListController <T extends IdentifiableEntity, SERVICE extends IIdentifiableEntityService<T>> extends BaseListController<T,SERVICE> {
|
43
|
|
44
|
|
45
|
@InitBinder
|
46
|
@Override
|
47
|
public void initBinder(WebDataBinder binder) {
|
48
|
super.initBinder(binder);
|
49
|
binder.registerCustomEditor(MatchMode.class, new MatchModePropertyEditor());
|
50
|
}
|
51
|
|
52
|
@Autowired
|
53
|
private ITermService termservice;
|
54
|
|
55
|
/**
|
56
|
* Find IdentifiableEntity objects by name
|
57
|
* <p>
|
58
|
*
|
59
|
* @param query
|
60
|
* the string to query for. Since the wildcard character '*'
|
61
|
* internally always is appended to the query string, a search
|
62
|
* always compares the query string with the beginning of a name.
|
63
|
* - <i>required parameter</i>
|
64
|
* @param pageNumber
|
65
|
* the number of the page to be returned, the first page has the
|
66
|
* pageNumber = 1 - <i>optional parameter</i>
|
67
|
* @param pageSize
|
68
|
* the maximum number of entities returned per page (can be -1
|
69
|
* to return all entities in a single page) - <i>optional parameter</i>
|
70
|
* @param matchMode
|
71
|
* valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
|
72
|
* @return a Pager on a list of {@link IdentifiableEntity}s
|
73
|
* @throws IOException
|
74
|
*/
|
75
|
@RequestMapping(method = RequestMethod.GET, value={"findByTitle"})
|
76
|
public Pager<T> doFindByTitle(
|
77
|
@RequestParam(value = "query", required = true) String query,
|
78
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
79
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
80
|
@RequestParam(value = "matchMode", required = false) MatchMode matchMode,
|
81
|
HttpServletRequest request,
|
82
|
HttpServletResponse response
|
83
|
)
|
84
|
throws IOException {
|
85
|
|
86
|
|
87
|
|
88
|
logger.info("doFind : " + request.getRequestURI() + "?" + request.getQueryString() );
|
89
|
|
90
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
91
|
pagerParams.normalizeAndValidate(response);
|
92
|
|
93
|
matchMode = matchMode != null ? matchMode : MatchMode.BEGINNING;
|
94
|
|
95
|
return service.findByTitle(null, query, matchMode, null, pagerParams.getPageSize(), pagerParams.getPageIndex(), null, initializationStrategy);
|
96
|
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* list IdentifiableEntity objects by identifiers
|
101
|
*
|
102
|
* @param type
|
103
|
* @param identifierType
|
104
|
* @param identifier
|
105
|
* @param pageNumber
|
106
|
* @param pageSize
|
107
|
* @param matchMode
|
108
|
* @param request
|
109
|
* @param response
|
110
|
* @param includeEntity
|
111
|
* @return
|
112
|
* @throws IOException
|
113
|
*/
|
114
|
@RequestMapping(method = RequestMethod.GET, value={"findByIdentifier"})
|
115
|
public Pager<FindByIdentifierDTO<T>> doFindByIdentifier(
|
116
|
@RequestParam(value = "class", required = false) Class type,
|
117
|
@RequestParam(value = "identifierType", required = false) String identifierType,
|
118
|
@RequestParam(value = "identifier", required = false) String identifier,
|
119
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
120
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
121
|
@RequestParam(value = "matchMode", required = false) MatchMode matchMode,
|
122
|
@RequestParam(value = "includeEntity", required = false) Boolean includeEntity,
|
123
|
HttpServletRequest request,
|
124
|
HttpServletResponse response
|
125
|
)
|
126
|
throws IOException {
|
127
|
|
128
|
DefinedTerm definedTerm = null;
|
129
|
if(StringUtils.isNotBlank(identifierType)){
|
130
|
identifierType = StringUtils.trim(identifierType);
|
131
|
UUID identifierTypeUUID = UUID.fromString(identifierType);
|
132
|
definedTerm = CdmBase.deproxy(termservice.find(identifierTypeUUID), DefinedTerm.class);
|
133
|
}
|
134
|
|
135
|
logger.info("doFind : " + request.getRequestURI() + "?" + request.getQueryString() );
|
136
|
|
137
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber).normalizeAndValidate(response);
|
138
|
|
139
|
matchMode = matchMode != null ? matchMode : MatchMode.EXACT;
|
140
|
boolean includeCdmEntity = includeEntity == null || includeEntity == true ? true : false;
|
141
|
return service.findByIdentifier(type, identifier, definedTerm , matchMode, includeCdmEntity, pagerParams.getPageSize(), pagerParams.getPageIndex(), initializationStrategy);
|
142
|
}
|
143
|
|
144
|
|
145
|
}
|