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.*",
91 protected static final List
<String
> ORDERED_DISTRIBUTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
93 "elements.annotations",
95 "elements.sources.citation.authorTeam.$",
96 "elements.sources.nameUsedInSource",
97 "elements.area.level",
100 protected static final List
<String
> DISTRIBUTION_INFO_INIT_STRATEGY
= Arrays
.asList(new String
[]{
101 "sources.citation.authorTeam.$",
102 "sources.nameUsedInSource"
106 private ITermService termService
;
109 private IEditGeoService geoService
;
112 public DescriptionPortalController() {
114 setInitializationStrategy(DESCRIPTION_INIT_STRATEGY
);
119 public void initBinder(WebDataBinder binder
) {
120 super.initBinder(binder
);
121 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
122 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
123 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
127 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
131 public void setService(IDescriptionService service
) {
132 this.service
= service
;
135 @RequestMapping(value
= "/portal/descriptionElement/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
)
136 public Pager
<Annotation
> getAnnotations(
137 @PathVariable("descriptionelement_uuid") UUID uuid
,
138 HttpServletRequest request
,
139 HttpServletResponse response
) throws IOException
{
140 logger
.info("getAnnotations() - " + requestPathAndQuery(request
) );
141 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
142 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, getInitializationStrategy());
147 * NOTICE: required to have a TreeNodeBeanProcessor configured which suppresses the
148 * redundant output of distribution.area
150 * @param descriptionUuidList
151 * @param subAreaPreference
152 * enables the <b>Sub area preference rule</b> if set to true,
153 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
154 * @param statusOrderPreference
155 * enables the <b>Status order preference rule</b> if set to true,
156 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
157 * @param hideMarkedAreas
158 * distributions where the area has a {@link Marker} with one of
159 * the specified {@link MarkerType}s will be skipped, see
160 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
166 @RequestMapping(value
= "/portal/description/{uuid_list}/DistributionTree", method
= RequestMethod
.GET
)
167 public DistributionTree
doGetOrderedDistributionsB(
168 @PathVariable("uuid_list") UuidList descriptionUuidList
,
169 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
170 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
171 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
172 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> omitLevels
,
173 HttpServletRequest request
,
174 HttpServletResponse response
) {
176 logger
.info("getOrderedDistributionsB() - " + requestPathAndQuery(request
) );
178 Set
<TaxonDescription
> taxonDescriptions
= new HashSet
<TaxonDescription
>();
179 TaxonDescription description
;
180 for (UUID descriptionUuid
: descriptionUuidList
) {
181 logger
.debug(" loading description " + descriptionUuid
.toString() );
182 description
= (TaxonDescription
) service
.load(descriptionUuid
, null);
183 taxonDescriptions
.add(description
);
186 Set
<MarkerType
> hideMarkedAreas
= null;
187 if(hideMarkedAreasList
!= null){
188 hideMarkedAreas
= hideMarkedAreasList
.asSet();
191 logger
.debug(" get ordered distributions ");
192 DistributionTree distTree
= service
.getOrderedDistributions(taxonDescriptions
, subAreaPreference
, statusOrderPreference
,
193 hideMarkedAreas
, omitLevels
, ORDERED_DISTRIBUTION_INIT_STRATEGY
);
194 if (logger
.isDebugEnabled()){ logger
.debug("done");}
201 * possible values: condensedStatusString, tree, mapUriParams,
203 * @param subAreaPreference
204 * @param statusOrderPreference
205 * @param hideMarkedAreasList
211 @RequestMapping(value
= "/portal/description/distributionInfoFor/{uuid}", method
= RequestMethod
.GET
)
212 public ModelAndView
doGetDistributionInfo(
213 @PathVariable("uuid") UUID taxonUuid
,
214 @RequestParam("part") Set
<InfoPart
> partSet
,
215 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
216 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
217 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
218 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> omitLevels
,
219 HttpServletRequest request
,
220 HttpServletResponse response
) {
222 logger
.debug("doGetDistributionInfo() - " + requestPathAndQuery(request
));
224 ModelAndView mv
= new ModelAndView();
226 Set
<MarkerType
> hideMarkedAreas
= null;
227 if(hideMarkedAreasList
!= null){
228 hideMarkedAreas
= hideMarkedAreasList
.asSet();
231 EnumSet
<InfoPart
> parts
= EnumSet
.copyOf(partSet
);
233 DistributionInfoDTO dto
= geoService
.composeDistributionInfoFor(parts
, taxonUuid
, subAreaPreference
, statusOrderPreference
,
234 hideMarkedAreas
, omitLevels
, LocaleContext
.getLanguages(), DISTRIBUTION_INFO_INIT_STRATEGY
);