1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.remote.controller;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.util.List;
|
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.IdentifiedEntityDTO;
|
29
|
import eu.etaxonomy.cdm.api.service.dto.MarkedEntityDTO;
|
30
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
33
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
34
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
35
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
36
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
37
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
38
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
39
|
import eu.etaxonomy.cdm.remote.editor.MatchModePropertyEditor;
|
40
|
|
41
|
/**
|
42
|
* @author l.morris
|
43
|
* @since 27 Mar 2012
|
44
|
*/
|
45
|
public abstract class AbstractIdentifiableListController <T extends IdentifiableEntity, SERVICE extends IIdentifiableEntityService<T>>
|
46
|
extends BaseListController<T,SERVICE> {
|
47
|
|
48
|
@InitBinder
|
49
|
@Override
|
50
|
public void initBinder(WebDataBinder binder) {
|
51
|
super.initBinder(binder);
|
52
|
binder.registerCustomEditor(MatchMode.class, new MatchModePropertyEditor());
|
53
|
}
|
54
|
|
55
|
@Autowired
|
56
|
private ITermService termService;
|
57
|
|
58
|
/**
|
59
|
* Find IdentifiableEntity objects by name
|
60
|
* <p>
|
61
|
*
|
62
|
* @param query
|
63
|
* the string to query for. Since the wild-card character '*'
|
64
|
* internally always is appended to the query string, a search
|
65
|
* always compares the query string with the beginning of a name.
|
66
|
* - <i>required parameter</i>
|
67
|
* @param pageIndex
|
68
|
* the number of the page to be returned, the first page has the
|
69
|
* pageNumber = 1 - <i>optional parameter</i>
|
70
|
* @param pageSize
|
71
|
* the maximum number of entities returned per page (can be -1
|
72
|
* to return all entities in a single page) - <i>optional parameter</i>
|
73
|
* @param matchMode
|
74
|
* valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
|
75
|
* @return a Pager on a list of {@link IdentifiableEntity}s
|
76
|
* @throws IOException
|
77
|
*/
|
78
|
@RequestMapping(method = RequestMethod.GET, value={"findByTitle"})
|
79
|
public Pager<T> doFindByTitle(
|
80
|
@RequestParam(value = "query", required = true) String query,
|
81
|
@RequestParam(value = "pageIndex", required = false) Integer pageIndex,
|
82
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
83
|
@RequestParam(value = "matchMode", required = false) MatchMode matchMode,
|
84
|
HttpServletRequest request,
|
85
|
HttpServletResponse response
|
86
|
)
|
87
|
throws IOException {
|
88
|
|
89
|
logger.info("doFind() : " + requestPathAndQuery(request) );
|
90
|
|
91
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageIndex);
|
92
|
pagerParams.normalizeAndValidate(response);
|
93
|
|
94
|
matchMode = matchMode != null ? matchMode : MatchMode.BEGINNING;
|
95
|
|
96
|
return service.findByTitleWithRestrictions(null, query, matchMode, null, pagerParams.getPageSize(), pagerParams.getPageIndex(), null, initializationStrategy);
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* List IdentifiableEntity objects by identifiers
|
101
|
*/
|
102
|
@RequestMapping(method = RequestMethod.GET, value={"findByIdentifier"})
|
103
|
public Pager<IdentifiedEntityDTO<T>> doFindByIdentifier(
|
104
|
@RequestParam(value = "class", required = false) Class<T> type,
|
105
|
@RequestParam(value = "identifierType", required = false) String identifierType,
|
106
|
@RequestParam(value = "identifier", required = false) String identifier,
|
107
|
@RequestParam(value = "pageIndex", required = false) Integer pageIndex,
|
108
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
109
|
@RequestParam(value = "matchMode", required = false) MatchMode matchMode,
|
110
|
@RequestParam(value = "includeEntity", required = false) Boolean includeEntity,
|
111
|
HttpServletRequest request,
|
112
|
HttpServletResponse response
|
113
|
)
|
114
|
throws IOException {
|
115
|
|
116
|
DefinedTerm definedTerm = null;
|
117
|
if(StringUtils.isNotBlank(identifierType)){
|
118
|
identifierType = StringUtils.trim(identifierType);
|
119
|
UUID identifierTypeUUID = UUID.fromString(identifierType);
|
120
|
definedTerm = CdmBase.deproxy(termService.find(identifierTypeUUID), DefinedTerm.class);
|
121
|
}
|
122
|
|
123
|
logger.info("doFindByIdentifier() : " + requestPathAndQuery(request) );
|
124
|
|
125
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageIndex).normalizeAndValidate(response);
|
126
|
|
127
|
matchMode = matchMode != null ? matchMode : MatchMode.EXACT;
|
128
|
boolean includeCdmEntity = includeEntity == null || includeEntity == true ? true : false;
|
129
|
return service.findByIdentifier(type, identifier, definedTerm , matchMode, includeCdmEntity, pagerParams.getPageSize(), pagerParams.getPageIndex(), initializationStrategy);
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* List identifiable entities by markers
|
134
|
*
|
135
|
* @param type
|
136
|
* @param markerType
|
137
|
* @param value
|
138
|
* @param pageIndex
|
139
|
* @param pageSize
|
140
|
* @param request
|
141
|
* @param response
|
142
|
* @return
|
143
|
* @see AbstractIdentifiableListController#doFindByIdentifier(Class, String, String, Integer, Integer, MatchMode, Boolean, HttpServletRequest, HttpServletResponse)
|
144
|
* @throws IOException
|
145
|
*/
|
146
|
@RequestMapping(method = RequestMethod.GET, value={"findByMarker"})
|
147
|
public Pager<MarkedEntityDTO<T>> doFindByMarker(
|
148
|
@RequestParam(value = "class", required = false) Class<T> type,
|
149
|
@RequestParam(value = "markerType", required = true) UUID markerTypeUuid,
|
150
|
@RequestParam(value = "value", required = false) Boolean value,
|
151
|
@RequestParam(value = "pageIndex", required = false) Integer pageIndex,
|
152
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
153
|
@RequestParam(value = "includeEntity", required = false, defaultValue="false") Boolean includeEntity,
|
154
|
HttpServletRequest request,
|
155
|
HttpServletResponse response
|
156
|
)
|
157
|
throws IOException {
|
158
|
|
159
|
MarkerType markerType = null;
|
160
|
if(markerTypeUuid != null){
|
161
|
DefinedTermBase<?> term = CdmBase.deproxy(termService.find(markerTypeUuid), MarkerType.class);
|
162
|
if (term != null && term.isInstanceOf(MarkerType.class)){
|
163
|
markerType = CdmBase.deproxy(term, MarkerType.class);
|
164
|
}
|
165
|
}
|
166
|
|
167
|
logger.info("doFindByMarker() " + requestPathAndQuery(request));
|
168
|
|
169
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageIndex).normalizeAndValidate(response);
|
170
|
|
171
|
Pager<MarkedEntityDTO<T>> result = service.findByMarker(type, markerType, value, includeEntity, pagerParams.getPageSize(), pagerParams.getPageIndex(), initializationStrategy);
|
172
|
return result;
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* List identifiable entities by markers
|
177
|
*
|
178
|
* @param type
|
179
|
* @param request
|
180
|
* @param response
|
181
|
* @return
|
182
|
* @see AbstractIdentifiableListController#doFindByIdentifier(Class, String, String, Integer, Integer, MatchMode, Boolean, HttpServletRequest, HttpServletResponse)
|
183
|
* @throws IOException
|
184
|
*/
|
185
|
@RequestMapping(method = RequestMethod.GET, value={"uuidAndTitleCache"})
|
186
|
public List<UuidAndTitleCache<T>> doGetUuidAndTitleCache(
|
187
|
@RequestParam(value = "class", required = false) Class<T> type,
|
188
|
@RequestParam(value = "limit", required = false) Integer limit,
|
189
|
@RequestParam(value = "pattern", required = false) String pattern,
|
190
|
HttpServletRequest request,
|
191
|
HttpServletResponse response
|
192
|
)
|
193
|
throws IOException {
|
194
|
|
195
|
logger.info("doGetUuidAndTitleCache() " + requestPathAndQuery(request));
|
196
|
|
197
|
return service.getUuidAndTitleCache(type, limit, pattern);
|
198
|
}
|
199
|
|
200
|
}
|