1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 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
|
|
11
|
package eu.etaxonomy.cdm.remote.controller;
|
12
|
|
13
|
import java.io.IOException;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.Collection;
|
16
|
import java.util.EnumSet;
|
17
|
import java.util.HashSet;
|
18
|
import java.util.List;
|
19
|
import java.util.Set;
|
20
|
import java.util.UUID;
|
21
|
|
22
|
import javax.servlet.http.HttpServletRequest;
|
23
|
import javax.servlet.http.HttpServletResponse;
|
24
|
|
25
|
import org.springframework.beans.factory.annotation.Autowired;
|
26
|
import org.springframework.stereotype.Controller;
|
27
|
import org.springframework.transaction.annotation.Transactional;
|
28
|
import org.springframework.web.bind.WebDataBinder;
|
29
|
import org.springframework.web.bind.annotation.InitBinder;
|
30
|
import org.springframework.web.bind.annotation.PathVariable;
|
31
|
import org.springframework.web.bind.annotation.RequestMapping;
|
32
|
import org.springframework.web.bind.annotation.RequestMethod;
|
33
|
import org.springframework.web.bind.annotation.RequestParam;
|
34
|
import org.springframework.web.servlet.ModelAndView;
|
35
|
|
36
|
import eu.etaxonomy.cdm.api.service.DistributionTree;
|
37
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
38
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
39
|
import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO;
|
40
|
import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO.InfoPart;
|
41
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
42
|
import eu.etaxonomy.cdm.api.utility.DescriptionUtility;
|
43
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
44
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
45
|
import eu.etaxonomy.cdm.model.common.Marker;
|
46
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
47
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
48
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
49
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
50
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
51
|
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
|
52
|
import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
|
53
|
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
|
54
|
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
55
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
56
|
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
|
57
|
|
58
|
/**
|
59
|
* IMPORTANT:
|
60
|
*
|
61
|
* This controller is mostly a 1:1 copy of the DescriptionController
|
62
|
* and this provides identical end points which only differ in the depth of the
|
63
|
* object graphs returned.
|
64
|
*
|
65
|
* @author a.kohlbecker
|
66
|
* @date Jun 25, 2013
|
67
|
*
|
68
|
*/
|
69
|
@Controller
|
70
|
@Transactional(readOnly=true)
|
71
|
@RequestMapping(value = {
|
72
|
"/portal/description/{uuid}",
|
73
|
"/portal/description/{uuid_list}",
|
74
|
"/portal/descriptionElement/{descriptionelement_uuid}"})
|
75
|
public class DescriptionPortalController extends BaseController<DescriptionBase, IDescriptionService>
|
76
|
{
|
77
|
|
78
|
protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
|
79
|
"$",
|
80
|
"elements.$",
|
81
|
"elements.multilanguageText.*",
|
82
|
"elements.annotations",
|
83
|
"elements.sources.citation.authorTeam.$",
|
84
|
"elements.sources.nameUsedInSource",
|
85
|
"elements.area.level",
|
86
|
"elements.modifyingText",
|
87
|
"elements.stateData.*",
|
88
|
"elements.statisticalValues.*",
|
89
|
"elements.unit",
|
90
|
"elements.media",
|
91
|
"elements.kindOfUnit"
|
92
|
|
93
|
});
|
94
|
|
95
|
protected static final List<String> ORDERED_DISTRIBUTION_INIT_STRATEGY = Arrays.asList(new String []{
|
96
|
"elements.$",
|
97
|
"elements.annotations",
|
98
|
"elements.markers",
|
99
|
"elements.sources.citation.authorTeam.$",
|
100
|
"elements.sources.nameUsedInSource",
|
101
|
"elements.area.level",
|
102
|
});
|
103
|
|
104
|
protected static final List<String> DISTRIBUTION_INFO_INIT_STRATEGY = Arrays.asList(new String []{
|
105
|
"sources.citation.authorTeam.$",
|
106
|
"sources.nameUsedInSource",
|
107
|
"annotations"
|
108
|
});
|
109
|
|
110
|
@Autowired
|
111
|
private ITermService termService;
|
112
|
|
113
|
@Autowired
|
114
|
private IEditGeoService geoService;
|
115
|
|
116
|
|
117
|
public DescriptionPortalController() {
|
118
|
super();
|
119
|
setInitializationStrategy(DESCRIPTION_INIT_STRATEGY);
|
120
|
}
|
121
|
|
122
|
@InitBinder
|
123
|
@Override
|
124
|
public void initBinder(WebDataBinder binder) {
|
125
|
super.initBinder(binder);
|
126
|
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
127
|
binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
|
128
|
binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<MarkerType>(termService));
|
129
|
}
|
130
|
|
131
|
/* (non-Javadoc)
|
132
|
* @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
|
133
|
*/
|
134
|
@Autowired
|
135
|
@Override
|
136
|
public void setService(IDescriptionService service) {
|
137
|
this.service = service;
|
138
|
}
|
139
|
|
140
|
@RequestMapping(value = "/portal/descriptionElement/{descriptionelement_uuid}/annotation", method = RequestMethod.GET)
|
141
|
public Pager<Annotation> getAnnotations(
|
142
|
@PathVariable("descriptionelement_uuid") UUID uuid,
|
143
|
HttpServletRequest request,
|
144
|
HttpServletResponse response) throws IOException {
|
145
|
logger.info("getAnnotations() - " + requestPathAndQuery(request) );
|
146
|
DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
|
147
|
Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
|
148
|
return annotations;
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* NOTICE: required to have a TreeNodeBeanProcessor configured which suppresses the
|
153
|
* redundant output of distribution.area
|
154
|
*
|
155
|
* @param descriptionUuidList
|
156
|
* @param subAreaPreference
|
157
|
* enables the <b>Sub area preference rule</b> if set to true,
|
158
|
* see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
|
159
|
* @param statusOrderPreference
|
160
|
* enables the <b>Status order preference rule</b> if set to true,
|
161
|
* see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
|
162
|
* @param hideMarkedAreas
|
163
|
* distributions where the area has a {@link Marker} with one of
|
164
|
* the specified {@link MarkerType}s will be skipped, see
|
165
|
* {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
|
166
|
* @param omitLevels
|
167
|
* @param request
|
168
|
* @param response
|
169
|
* @return
|
170
|
*/
|
171
|
@RequestMapping(value = "/portal/description/{uuid_list}/DistributionTree", method = RequestMethod.GET)
|
172
|
public DistributionTree doGetOrderedDistributionsB(
|
173
|
@PathVariable("uuid_list") UuidList descriptionUuidList,
|
174
|
@RequestParam(value = "subAreaPreference", required = false) boolean subAreaPreference,
|
175
|
@RequestParam(value = "statusOrderPreference", required = false) boolean statusOrderPreference,
|
176
|
@RequestParam(value = "hideMarkedAreas", required = false) DefinedTermBaseList<MarkerType> hideMarkedAreasList,
|
177
|
@RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> omitLevels,
|
178
|
HttpServletRequest request,
|
179
|
HttpServletResponse response) {
|
180
|
|
181
|
logger.info("getOrderedDistributionsB() - " + requestPathAndQuery(request) );
|
182
|
|
183
|
Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
|
184
|
TaxonDescription description;
|
185
|
for (UUID descriptionUuid : descriptionUuidList) {
|
186
|
logger.debug(" loading description " + descriptionUuid.toString() );
|
187
|
description = (TaxonDescription) service.load(descriptionUuid, null);
|
188
|
taxonDescriptions.add(description);
|
189
|
}
|
190
|
|
191
|
Set<MarkerType> hideMarkedAreas = null;
|
192
|
if(hideMarkedAreasList != null){
|
193
|
hideMarkedAreas = hideMarkedAreasList.asSet();
|
194
|
}
|
195
|
|
196
|
logger.debug(" get ordered distributions ");
|
197
|
DistributionTree distTree = service.getOrderedDistributions(taxonDescriptions, subAreaPreference, statusOrderPreference,
|
198
|
hideMarkedAreas, omitLevels, ORDERED_DISTRIBUTION_INIT_STRATEGY);
|
199
|
if (logger.isDebugEnabled()){ logger.debug("done");}
|
200
|
return distTree;
|
201
|
}
|
202
|
|
203
|
/**
|
204
|
* @param taxonUuid
|
205
|
* @param parts
|
206
|
* possible values: condensedStatusString, tree, mapUriParams,
|
207
|
* elements,
|
208
|
* @param subAreaPreference
|
209
|
* @param statusOrderPreference
|
210
|
* @param hideMarkedAreasList
|
211
|
* @param omitLevels
|
212
|
* @param request
|
213
|
* @param response
|
214
|
* @return
|
215
|
*/
|
216
|
@RequestMapping(value = "/portal/description/distributionInfoFor/{uuid}", method = RequestMethod.GET)
|
217
|
public ModelAndView doGetDistributionInfo(
|
218
|
@PathVariable("uuid") UUID taxonUuid,
|
219
|
@RequestParam("part") Set<InfoPart> partSet,
|
220
|
@RequestParam(value = "subAreaPreference", required = false) boolean subAreaPreference,
|
221
|
@RequestParam(value = "statusOrderPreference", required = false) boolean statusOrderPreference,
|
222
|
@RequestParam(value = "hideMarkedAreas", required = false) DefinedTermBaseList<MarkerType> hideMarkedAreasList,
|
223
|
@RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> omitLevels,
|
224
|
HttpServletRequest request,
|
225
|
HttpServletResponse response) {
|
226
|
|
227
|
logger.debug("doGetDistributionInfo() - " + requestPathAndQuery(request));
|
228
|
|
229
|
ModelAndView mv = new ModelAndView();
|
230
|
|
231
|
Set<MarkerType> hideMarkedAreas = null;
|
232
|
if(hideMarkedAreasList != null){
|
233
|
hideMarkedAreas = hideMarkedAreasList.asSet();
|
234
|
}
|
235
|
|
236
|
EnumSet<InfoPart> parts = EnumSet.copyOf(partSet);
|
237
|
|
238
|
DistributionInfoDTO dto = geoService.composeDistributionInfoFor(parts, taxonUuid, subAreaPreference, statusOrderPreference,
|
239
|
hideMarkedAreas, omitLevels, LocaleContext.getLanguages(), DISTRIBUTION_INFO_INIT_STRATEGY);
|
240
|
|
241
|
mv.addObject(dto);
|
242
|
|
243
|
return mv;
|
244
|
}
|
245
|
|
246
|
|
247
|
}
|