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
.awt
.Color
;
14 import java
.io
.IOException
;
15 import java
.util
.Arrays
;
16 import java
.util
.Collection
;
17 import java
.util
.EnumSet
;
18 import java
.util
.HashSet
;
19 import java
.util
.List
;
22 import java
.util
.UUID
;
24 import javax
.servlet
.http
.HttpServletRequest
;
25 import javax
.servlet
.http
.HttpServletResponse
;
27 import org
.codehaus
.jackson
.JsonParseException
;
28 import org
.codehaus
.jackson
.map
.JsonMappingException
;
29 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
30 import org
.springframework
.stereotype
.Controller
;
31 import org
.springframework
.transaction
.annotation
.Transactional
;
32 import org
.springframework
.web
.bind
.WebDataBinder
;
33 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
34 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
35 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
36 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
37 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
38 import org
.springframework
.web
.servlet
.ModelAndView
;
40 import eu
.etaxonomy
.cdm
.api
.service
.DistributionTree
;
41 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
42 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
43 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DistributionInfoDTO
;
44 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DistributionInfoDTO
.InfoPart
;
45 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
46 import eu
.etaxonomy
.cdm
.api
.utility
.DescriptionUtility
;
47 import eu
.etaxonomy
.cdm
.ext
.geo
.EditGeoServiceUtilities
;
48 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
49 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
50 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
51 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
52 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
53 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
54 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
55 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
56 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
57 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
58 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
59 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
60 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
61 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
62 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
67 * This controller is mostly a 1:1 copy of the DescriptionController
68 * and this provides identical end points which only differ in the depth of the
69 * object graphs returned.
71 * @author a.kohlbecker
76 @Transactional(readOnly
=true)
77 @RequestMapping(value
= {
78 "/portal/description/{uuid}",
79 "/portal/description/{uuid_list}",
80 "/portal/descriptionElement/{descriptionelement_uuid}"})
81 public class DescriptionPortalController
extends BaseController
<DescriptionBase
, IDescriptionService
>
84 protected static final List
<String
> DESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
87 "elements.multilanguageText.*",
88 "elements.annotations",
89 "elements.sources.citation.authorship.$",
90 "elements.sources.nameUsedInSource",
91 "elements.area.level",
92 "elements.modifyingText",
93 "elements.stateData.*",
94 "elements.statisticalValues.*",
101 protected static final List
<String
> ORDERED_DISTRIBUTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
103 "elements.annotations",
105 "elements.sources.citation.authorship.$",
106 "elements.sources.nameUsedInSource",
107 "elements.area.level",
110 protected static final List
<String
> DISTRIBUTION_INFO_INIT_STRATEGY
= Arrays
.asList(new String
[]{
111 "sources.citation.authorship.$",
112 "sources.nameUsedInSource",
117 private ITermService termService
;
120 private IEditGeoService geoService
;
123 public DescriptionPortalController() {
125 setInitializationStrategy(DESCRIPTION_INIT_STRATEGY
);
130 public void initBinder(WebDataBinder binder
) {
131 super.initBinder(binder
);
132 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
133 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
134 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
138 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
142 public void setService(IDescriptionService service
) {
143 this.service
= service
;
146 @RequestMapping(value
= "//portal/descriptionElement/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
) // mapped as absolute path, see CdmAntPathMatcher
147 public Pager
<Annotation
> getAnnotations(
148 @PathVariable("descriptionelement_uuid") UUID uuid
,
149 HttpServletRequest request
,
150 HttpServletResponse response
) throws IOException
{
151 logger
.info("getAnnotations() - " + requestPathAndQuery(request
) );
152 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
153 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, getInitializationStrategy());
158 * NOTICE: required to have a TreeNodeBeanProcessor configured which suppresses the
159 * redundant output of distribution.area
161 * @param descriptionUuidList
162 * @param subAreaPreference
163 * enables the <b>Sub area preference rule</b> if set to true,
164 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
165 * @param statusOrderPreference
166 * enables the <b>Status order preference rule</b> if set to true,
167 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
168 * @param hideMarkedAreas
169 * distributions where the area has a {@link Marker} with one of
170 * the specified {@link MarkerType}s will be skipped, see
171 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
177 @RequestMapping(value
= "//portal/description/{uuid_list}/DistributionTree", method
= RequestMethod
.GET
) // mapped as absolute path, see CdmAntPathMatcher
178 public DistributionTree
doGetOrderedDistributionsB(
179 @PathVariable("uuid_list") UuidList descriptionUuidList
,
180 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
181 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
182 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
183 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> omitLevels
,
184 HttpServletRequest request
,
185 HttpServletResponse response
) {
187 logger
.info("getOrderedDistributionsB() - " + requestPathAndQuery(request
) );
189 Set
<TaxonDescription
> taxonDescriptions
= new HashSet
<TaxonDescription
>();
190 TaxonDescription description
;
191 for (UUID descriptionUuid
: descriptionUuidList
) {
192 logger
.debug(" loading description " + descriptionUuid
.toString() );
193 description
= (TaxonDescription
) service
.load(descriptionUuid
, null);
194 taxonDescriptions
.add(description
);
197 Set
<MarkerType
> hideMarkedAreas
= null;
198 if(hideMarkedAreasList
!= null){
199 hideMarkedAreas
= hideMarkedAreasList
.asSet();
202 logger
.debug(" get ordered distributions ");
203 DistributionTree distTree
= service
.getOrderedDistributions(taxonDescriptions
, subAreaPreference
, statusOrderPreference
,
204 hideMarkedAreas
, omitLevels
, ORDERED_DISTRIBUTION_INIT_STRATEGY
);
205 if (logger
.isDebugEnabled()){ logger
.debug("done");}
212 * possible values: condensedStatusString, tree, mapUriParams,
214 * @param subAreaPreference
215 * @param statusOrderPreference
216 * @param hideMarkedAreasList
221 * @throws IOException
222 * @throws JsonMappingException
223 * @throws JsonParseException
225 @RequestMapping(value
= "//portal/description/distributionInfoFor/{uuid}", method
= RequestMethod
.GET
) // mapped as absolute path, see CdmAntPathMatcher
226 public ModelAndView
doGetDistributionInfo(
227 @PathVariable("uuid") UUID taxonUuid
,
228 @RequestParam("part") Set
<InfoPart
> partSet
,
229 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
230 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
231 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
232 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> omitLevels
,
233 @RequestParam(value
= "statusColors", required
= false) String statusColorsString
,
234 HttpServletRequest request
,
235 HttpServletResponse response
) throws JsonParseException
, JsonMappingException
, IOException
{
237 logger
.info("doGetDistributionInfo() - " + requestPathAndQuery(request
));
239 ModelAndView mv
= new ModelAndView();
241 Set
<MarkerType
> hideMarkedAreas
= null;
242 if(hideMarkedAreasList
!= null){
243 hideMarkedAreas
= hideMarkedAreasList
.asSet();
246 EnumSet
<InfoPart
> parts
= EnumSet
.copyOf(partSet
);
248 Map
<PresenceAbsenceTerm
, Color
> presenceAbsenceTermColors
= EditGeoServiceUtilities
.buildStatusColorMap(statusColorsString
, termService
);
250 DistributionInfoDTO dto
= geoService
.composeDistributionInfoFor(parts
, taxonUuid
, subAreaPreference
, statusOrderPreference
,
251 hideMarkedAreas
, omitLevels
, presenceAbsenceTermColors
, LocaleContext
.getLanguages(), DISTRIBUTION_INFO_INIT_STRATEGY
);