1 |
64b19820
|
f.revilla
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2007 EDIT
|
4 |
45e7ca8a
|
Andreas Kohlbecker
|
* European Distributed Institute of Taxonomy
|
5 |
64b19820
|
f.revilla
|
* http://www.e-taxonomy.eu
|
6 |
45e7ca8a
|
Andreas Kohlbecker
|
*
|
7 |
64b19820
|
f.revilla
|
* 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 |
3d202d57
|
Andreas Kohlbecker
|
import java.util.Collection;
|
16 |
20d40cb9
|
Andreas Kohlbecker
|
import java.util.EnumSet;
|
17 |
64b19820
|
f.revilla
|
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 |
20d40cb9
|
Andreas Kohlbecker
|
import org.springframework.transaction.annotation.Transactional;
|
28 |
64b19820
|
f.revilla
|
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 |
20d40cb9
|
Andreas Kohlbecker
|
import org.springframework.web.servlet.ModelAndView;
|
35 |
64b19820
|
f.revilla
|
|
36 |
|
|
import eu.etaxonomy.cdm.api.service.DistributionTree;
|
37 |
|
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
38 |
b2bac578
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
39 |
20d40cb9
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO;
|
40 |
|
|
import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO.InfoPart;
|
41 |
64b19820
|
f.revilla
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
42 |
3d202d57
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.api.utility.DescriptionUtility;
|
43 |
20d40cb9
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
44 |
64b19820
|
f.revilla
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
45 |
3d202d57
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.model.common.Marker;
|
46 |
|
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
47 |
64b19820
|
f.revilla
|
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 |
b2bac578
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
|
52 |
64b19820
|
f.revilla
|
import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
|
53 |
b2bac578
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
|
54 |
64b19820
|
f.revilla
|
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
55 |
|
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
56 |
20d40cb9
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
|
57 |
64b19820
|
f.revilla
|
|
58 |
|
|
/**
|
59 |
5cf8568b
|
Andreas Kohlbecker
|
* 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 |
45e7ca8a
|
Andreas Kohlbecker
|
*
|
65 |
64b19820
|
f.revilla
|
* @author a.kohlbecker
|
66 |
5cf8568b
|
Andreas Kohlbecker
|
* @date Jun 25, 2013
|
67 |
|
|
*
|
68 |
64b19820
|
f.revilla
|
*/
|
69 |
|
|
@Controller
|
70 |
20d40cb9
|
Andreas Kohlbecker
|
@Transactional(readOnly=true)
|
71 |
38f374fc
|
Andreas Kohlbecker
|
@RequestMapping(value = {
|
72 |
|
|
"/portal/description/{uuid}",
|
73 |
|
|
"/portal/description/{uuid_list}",
|
74 |
1abedc74
|
Andreas Kohlbecker
|
"/portal/descriptionElement/{descriptionelement_uuid}"})
|
75 |
45e7ca8a
|
Andreas Kohlbecker
|
public class DescriptionPortalController extends BaseController<DescriptionBase, IDescriptionService>
|
76 |
64b19820
|
f.revilla
|
{
|
77 |
d76c4206
|
Andreas Kohlbecker
|
|
78 |
|
|
protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
|
79 |
45e7ca8a
|
Andreas Kohlbecker
|
"$",
|
80 |
|
|
"elements.$",
|
81 |
da4b3ae6
|
Andreas Kohlbecker
|
"elements.multilanguageText.*",
|
82 |
07b62255
|
Andreas Kohlbecker
|
"elements.annotations",
|
83 |
45e7ca8a
|
Andreas Kohlbecker
|
"elements.sources.citation.authorTeam.$",
|
84 |
388411cb
|
Andreas Müller
|
"elements.sources.nameUsedInSource",
|
85 |
45e7ca8a
|
Andreas Kohlbecker
|
"elements.area.level",
|
86 |
|
|
"elements.modifyingText",
|
87 |
8c2d61c7
|
Andreas Kohlbecker
|
"elements.stateData.*",
|
88 |
69e517e3
|
Andreas Kohlbecker
|
"elements.statisticalValues.*",
|
89 |
|
|
"elements.unit",
|
90 |
ff13d277
|
Andreas Kohlbecker
|
"elements.media",
|
91 |
5624aa7e
|
Andreas Kohlbecker
|
"elements.kindOfUnit"
|
92 |
|
|
|
93 |
45e7ca8a
|
Andreas Kohlbecker
|
});
|
94 |
07b62255
|
Andreas Kohlbecker
|
|
95 |
e3d48bc9
|
Andreas Müller
|
protected static final List<String> ORDERED_DISTRIBUTION_INIT_STRATEGY = Arrays.asList(new String []{
|
96 |
|
|
"elements.$",
|
97 |
07b62255
|
Andreas Kohlbecker
|
"elements.annotations",
|
98 |
de04104a
|
Andreas Müller
|
"elements.markers",
|
99 |
e3d48bc9
|
Andreas Müller
|
"elements.sources.citation.authorTeam.$",
|
100 |
388411cb
|
Andreas Müller
|
"elements.sources.nameUsedInSource",
|
101 |
e3d48bc9
|
Andreas Müller
|
"elements.area.level",
|
102 |
|
|
});
|
103 |
45e7ca8a
|
Andreas Kohlbecker
|
|
104 |
68e8e327
|
Andreas Kohlbecker
|
protected static final List<String> DISTRIBUTION_INFO_INIT_STRATEGY = Arrays.asList(new String []{
|
105 |
|
|
"sources.citation.authorTeam.$",
|
106 |
5936efd6
|
Andreas Kohlbecker
|
"sources.nameUsedInSource",
|
107 |
|
|
"annotations"
|
108 |
68e8e327
|
Andreas Kohlbecker
|
});
|
109 |
|
|
|
110 |
b2bac578
|
Andreas Kohlbecker
|
@Autowired
|
111 |
|
|
private ITermService termService;
|
112 |
|
|
|
113 |
20d40cb9
|
Andreas Kohlbecker
|
@Autowired
|
114 |
|
|
private IEditGeoService geoService;
|
115 |
|
|
|
116 |
0920ebe9
|
Andreas Kohlbecker
|
|
117 |
|
|
public DescriptionPortalController() {
|
118 |
|
|
super();
|
119 |
d76c4206
|
Andreas Kohlbecker
|
setInitializationStrategy(DESCRIPTION_INIT_STRATEGY);
|
120 |
0920ebe9
|
Andreas Kohlbecker
|
}
|
121 |
|
|
|
122 |
45e7ca8a
|
Andreas Kohlbecker
|
@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 |
b2bac578
|
Andreas Kohlbecker
|
binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<MarkerType>(termService));
|
129 |
45e7ca8a
|
Andreas Kohlbecker
|
}
|
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 |
ccfd526c
|
Andreas Kohlbecker
|
logger.info("getAnnotations() - " + requestPathAndQuery(request) );
|
146 |
45e7ca8a
|
Andreas Kohlbecker
|
DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
|
147 |
38f374fc
|
Andreas Kohlbecker
|
Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
|
148 |
45e7ca8a
|
Andreas Kohlbecker
|
return annotations;
|
149 |
|
|
}
|
150 |
|
|
|
151 |
7376a447
|
Andreas Kohlbecker
|
/**
|
152 |
|
|
* NOTICE: required to have a TreeNodeBeanProcessor configured which suppresses the
|
153 |
|
|
* redundant output of distribution.area
|
154 |
|
|
*
|
155 |
|
|
* @param descriptionUuidList
|
156 |
ccfd526c
|
Andreas Kohlbecker
|
* @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 |
3d202d57
|
Andreas Kohlbecker
|
* @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 |
ccfd526c
|
Andreas Kohlbecker
|
* @param omitLevels
|
167 |
7376a447
|
Andreas Kohlbecker
|
* @param request
|
168 |
|
|
* @param response
|
169 |
|
|
* @return
|
170 |
|
|
*/
|
171 |
45e7ca8a
|
Andreas Kohlbecker
|
@RequestMapping(value = "/portal/description/{uuid_list}/DistributionTree", method = RequestMethod.GET)
|
172 |
|
|
public DistributionTree doGetOrderedDistributionsB(
|
173 |
|
|
@PathVariable("uuid_list") UuidList descriptionUuidList,
|
174 |
ccfd526c
|
Andreas Kohlbecker
|
@RequestParam(value = "subAreaPreference", required = false) boolean subAreaPreference,
|
175 |
|
|
@RequestParam(value = "statusOrderPreference", required = false) boolean statusOrderPreference,
|
176 |
b2bac578
|
Andreas Kohlbecker
|
@RequestParam(value = "hideMarkedAreas", required = false) DefinedTermBaseList<MarkerType> hideMarkedAreasList,
|
177 |
ccfd526c
|
Andreas Kohlbecker
|
@RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> omitLevels,
|
178 |
|
|
HttpServletRequest request,
|
179 |
|
|
HttpServletResponse response) {
|
180 |
|
|
|
181 |
|
|
logger.info("getOrderedDistributionsB() - " + requestPathAndQuery(request) );
|
182 |
|
|
|
183 |
45e7ca8a
|
Andreas Kohlbecker
|
Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
|
184 |
|
|
TaxonDescription description;
|
185 |
|
|
for (UUID descriptionUuid : descriptionUuidList) {
|
186 |
e3d48bc9
|
Andreas Müller
|
logger.debug(" loading description " + descriptionUuid.toString() );
|
187 |
|
|
description = (TaxonDescription) service.load(descriptionUuid, null);
|
188 |
45e7ca8a
|
Andreas Kohlbecker
|
taxonDescriptions.add(description);
|
189 |
|
|
}
|
190 |
b2bac578
|
Andreas Kohlbecker
|
|
191 |
|
|
Set<MarkerType> hideMarkedAreas = null;
|
192 |
|
|
if(hideMarkedAreasList != null){
|
193 |
|
|
hideMarkedAreas = hideMarkedAreasList.asSet();
|
194 |
|
|
}
|
195 |
|
|
|
196 |
e3d48bc9
|
Andreas Müller
|
logger.debug(" get ordered distributions ");
|
197 |
ccfd526c
|
Andreas Kohlbecker
|
DistributionTree distTree = service.getOrderedDistributions(taxonDescriptions, subAreaPreference, statusOrderPreference,
|
198 |
3d202d57
|
Andreas Kohlbecker
|
hideMarkedAreas, omitLevels, ORDERED_DISTRIBUTION_INIT_STRATEGY);
|
199 |
637814c1
|
Andreas Müller
|
if (logger.isDebugEnabled()){ logger.debug("done");}
|
200 |
45e7ca8a
|
Andreas Kohlbecker
|
return distTree;
|
201 |
|
|
}
|
202 |
64b19820
|
f.revilla
|
|
203 |
20d40cb9
|
Andreas Kohlbecker
|
/**
|
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 |
68e8e327
|
Andreas Kohlbecker
|
hideMarkedAreas, omitLevels, LocaleContext.getLanguages(), DISTRIBUTION_INFO_INIT_STRATEGY);
|
240 |
20d40cb9
|
Andreas Kohlbecker
|
|
241 |
|
|
mv.addObject(dto);
|
242 |
|
|
|
243 |
|
|
return mv;
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
|
247 |
64b19820
|
f.revilla
|
}
|