2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.remote
.controller
;
12 import io
.swagger
.annotations
.Api
;
14 import java
.awt
.Color
;
15 import java
.io
.IOException
;
16 import java
.util
.Arrays
;
17 import java
.util
.Collection
;
18 import java
.util
.EnumSet
;
19 import java
.util
.HashSet
;
20 import java
.util
.List
;
23 import java
.util
.UUID
;
25 import javax
.servlet
.http
.HttpServletRequest
;
26 import javax
.servlet
.http
.HttpServletResponse
;
28 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
29 import org
.springframework
.stereotype
.Controller
;
30 import org
.springframework
.transaction
.annotation
.Transactional
;
31 import org
.springframework
.web
.bind
.WebDataBinder
;
32 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
33 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
34 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
35 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
36 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
37 import org
.springframework
.web
.servlet
.ModelAndView
;
39 import com
.fasterxml
.jackson
.core
.JsonParseException
;
40 import com
.fasterxml
.jackson
.databind
.JsonMappingException
;
42 import eu
.etaxonomy
.cdm
.api
.service
.DistributionTree
;
43 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
44 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
45 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DistributionInfoDTO
;
46 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DistributionInfoDTO
.InfoPart
;
47 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
48 import eu
.etaxonomy
.cdm
.api
.utility
.DescriptionUtility
;
49 import eu
.etaxonomy
.cdm
.ext
.geo
.CondensedDistributionRecipe
;
50 import eu
.etaxonomy
.cdm
.ext
.geo
.EditGeoServiceUtilities
;
51 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
52 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
53 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
54 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
55 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
56 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
57 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
58 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
59 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
60 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
61 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
62 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
63 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
64 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
65 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
69 * @author a.kohlbecker
74 @Api("portal_description")
75 @Transactional(readOnly
=true)
76 @RequestMapping(value
= {
77 "/portal/description/{uuid}",
78 "/portal/description/{uuid_list}"})
79 public class DescriptionPortalController
extends BaseController
<DescriptionBase
, IDescriptionService
>
82 protected static final List
<String
> DESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
85 "elements.multilanguageText.*",
86 "elements.annotations",
87 "elements.sources.citation.authorship.$",
88 "elements.sources.nameUsedInSource",
89 "elements.area.level",
90 "elements.modifyingText",
91 "elements.stateData.*",
92 "elements.statisticalValues.*",
99 protected static final List
<String
> ORDERED_DISTRIBUTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
101 "elements.annotations",
103 "elements.sources.citation.authorship.$",
104 "elements.sources.nameUsedInSource",
105 "elements.area.level",
108 protected static final List
<String
> DISTRIBUTION_INFO_INIT_STRATEGY
= Arrays
.asList(new String
[]{
109 "sources.citation.authorship.$",
110 "sources.nameUsedInSource",
115 private ITermService termService
;
118 private IEditGeoService geoService
;
121 public DescriptionPortalController() {
123 setInitializationStrategy(DESCRIPTION_INIT_STRATEGY
);
128 public void initBinder(WebDataBinder binder
) {
129 super.initBinder(binder
);
130 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
131 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
132 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
136 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
140 public void setService(IDescriptionService service
) {
141 this.service
= service
;
144 @RequestMapping(value
= "//portal/descriptionElement/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
) // mapped as absolute path, see CdmAntPathMatcher
145 public Pager
<Annotation
> getAnnotations(
146 @PathVariable("descriptionelement_uuid") UUID uuid
,
147 HttpServletRequest request
,
148 HttpServletResponse response
) throws IOException
{
149 logger
.info("getAnnotations() - " + requestPathAndQuery(request
) );
150 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
151 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, getInitializationStrategy());
156 * NOTICE: required to have a TreeNodeBeanProcessor configured which suppresses the
157 * redundant output of distribution.area
159 * @param descriptionUuidList
160 * @param subAreaPreference
161 * enables the <b>Sub area preference rule</b> if set to true,
162 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
163 * @param statusOrderPreference
164 * enables the <b>Status order preference rule</b> if set to true,
165 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
166 * @param hideMarkedAreas
167 * distributions where the area has a {@link Marker} with one of
168 * the specified {@link MarkerType}s will be skipped, see
169 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
175 @RequestMapping(value
= "//portal/description/{uuid_list}/DistributionTree", method
= RequestMethod
.GET
) // mapped as absolute path, see CdmAntPathMatcher
176 public DistributionTree
doGetOrderedDistributionsB(
177 @PathVariable("uuid_list") UuidList descriptionUuidList
,
178 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
179 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
180 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
181 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> omitLevels
,
182 HttpServletRequest request
,
183 HttpServletResponse response
) {
185 logger
.info("getOrderedDistributionsB() - " + requestPathAndQuery(request
) );
187 Set
<TaxonDescription
> taxonDescriptions
= new HashSet
<TaxonDescription
>();
188 TaxonDescription description
;
189 for (UUID descriptionUuid
: descriptionUuidList
) {
190 logger
.debug(" loading description " + descriptionUuid
.toString() );
191 description
= (TaxonDescription
) service
.load(descriptionUuid
, null);
192 taxonDescriptions
.add(description
);
195 Set
<MarkerType
> hideMarkedAreas
= null;
196 if(hideMarkedAreasList
!= null){
197 hideMarkedAreas
= hideMarkedAreasList
.asSet();
200 logger
.debug(" get ordered distributions ");
201 DistributionTree distTree
= service
.getOrderedDistributions(taxonDescriptions
, subAreaPreference
, statusOrderPreference
,
202 hideMarkedAreas
, omitLevels
, ORDERED_DISTRIBUTION_INIT_STRATEGY
);
203 if (logger
.isDebugEnabled()){ logger
.debug("done");}
210 * possible values: condensedStatus, tree, mapUriParams,
212 * @param subAreaPreference
213 * @param statusOrderPreference
214 * @param hideMarkedAreasList
216 * The recipe for creating the condensed distribution status
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
= "hiddenAreaMarkerType", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
232 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> omitLevels
,
233 @RequestParam(value
= "statusColors", required
= false) String statusColorsString
,
234 @RequestParam(value
= "recipe", required
= false, defaultValue
="EuroPlusMed") CondensedDistributionRecipe recipe
,
236 HttpServletRequest request
,
237 HttpServletResponse response
) throws JsonParseException
, JsonMappingException
, IOException
{
239 logger
.info("doGetDistributionInfo() - " + requestPathAndQuery(request
));
241 ModelAndView mv
= new ModelAndView();
243 Set
<MarkerType
> hideMarkedAreas
= null;
244 if(hideMarkedAreasList
!= null){
245 hideMarkedAreas
= hideMarkedAreasList
.asSet();
248 EnumSet
<InfoPart
> parts
= EnumSet
.copyOf(partSet
);
250 Map
<PresenceAbsenceTerm
, Color
> presenceAbsenceTermColors
= EditGeoServiceUtilities
.buildStatusColorMap(statusColorsString
, termService
);
252 DistributionInfoDTO dto
= geoService
.composeDistributionInfoFor(parts
, taxonUuid
, subAreaPreference
, statusOrderPreference
,
253 hideMarkedAreas
, omitLevels
, presenceAbsenceTermColors
, LocaleContext
.getLanguages(), DISTRIBUTION_INFO_INIT_STRATEGY
, recipe
);