3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.remote
.controller
;
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
;
20 import java
.util
.UUID
;
22 import javax
.servlet
.http
.HttpServletRequest
;
23 import javax
.servlet
.http
.HttpServletResponse
;
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
;
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
;
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.
65 * @author a.kohlbecker
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
>
78 protected static final List
<String
> DESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
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.*",
95 protected static final List
<String
> ORDERED_DISTRIBUTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
97 "elements.annotations",
99 "elements.sources.citation.authorTeam.$",
100 "elements.sources.nameUsedInSource",
101 "elements.area.level",
104 protected static final List
<String
> DISTRIBUTION_INFO_INIT_STRATEGY
= Arrays
.asList(new String
[]{
105 "sources.citation.authorTeam.$",
106 "sources.nameUsedInSource",
111 private ITermService termService
;
114 private IEditGeoService geoService
;
117 public DescriptionPortalController() {
119 setInitializationStrategy(DESCRIPTION_INIT_STRATEGY
);
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
));
132 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
136 public void setService(IDescriptionService service
) {
137 this.service
= service
;
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());
152 * NOTICE: required to have a TreeNodeBeanProcessor configured which suppresses the
153 * redundant output of distribution.area
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)}
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
) {
181 logger
.info("getOrderedDistributionsB() - " + requestPathAndQuery(request
) );
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
);
191 Set
<MarkerType
> hideMarkedAreas
= null;
192 if(hideMarkedAreasList
!= null){
193 hideMarkedAreas
= hideMarkedAreasList
.asSet();
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");}
206 * possible values: condensedStatusString, tree, mapUriParams,
208 * @param subAreaPreference
209 * @param statusOrderPreference
210 * @param hideMarkedAreasList
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
) {
227 logger
.debug("doGetDistributionInfo() - " + requestPathAndQuery(request
));
229 ModelAndView mv
= new ModelAndView();
231 Set
<MarkerType
> hideMarkedAreas
= null;
232 if(hideMarkedAreasList
!= null){
233 hideMarkedAreas
= hideMarkedAreasList
.asSet();
236 EnumSet
<InfoPart
> parts
= EnumSet
.copyOf(partSet
);
238 DistributionInfoDTO dto
= geoService
.composeDistributionInfoFor(parts
, taxonUuid
, subAreaPreference
, statusOrderPreference
,
239 hideMarkedAreas
, omitLevels
, LocaleContext
.getLanguages(), DISTRIBUTION_INFO_INIT_STRATEGY
);