bugfix for generics
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / ext / ExternalGeoController.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.cdm.remote.controller.ext;
11
12 import java.awt.Color;
13 import java.io.IOException;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.UUID;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.apache.log4j.Logger;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.web.bind.annotation.PathVariable;
25 import org.springframework.web.bind.annotation.RequestMapping;
26 import org.springframework.web.bind.annotation.RequestMethod;
27 import org.springframework.web.servlet.ModelAndView;
28
29 import eu.etaxonomy.cdm.api.service.IDescriptionService;
30 import eu.etaxonomy.cdm.api.service.ITaxonService;
31 import eu.etaxonomy.cdm.api.service.pager.Pager;
32 import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
33 import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
34 import eu.etaxonomy.cdm.model.common.Language;
35 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
36 import eu.etaxonomy.cdm.model.description.TaxonDescription;
37 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
38 import eu.etaxonomy.cdm.model.taxon.Taxon;
39 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
40 import eu.etaxonomy.cdm.remote.controller.BaseController;
41 import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
42
43 /**
44 * The ExternalGeoController class is a Spring MVC Controller.
45 * <p>
46 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
47 * The available {datasource-name}s are defined in a configuration file which
48 * is loaded by the {@link UpdatableRoutingDataSource}. If the
49 * UpdatableRoutingDataSource is not being used in the actual application
50 * context any arbitrary {datasource-name} may be used.
51 * <p>
52 * @author a.kohlbecker
53 * @date 18.06.2009
54 *
55 */
56 @Controller
57 @RequestMapping(value = { "ext/edit/mapServiceParameters/" })
58 public class ExternalGeoController extends BaseController<TaxonBase, ITaxonService> {
59
60 public static final Logger logger = Logger.getLogger(ExternalGeoController.class);
61
62 @Autowired
63 private IEditGeoService geoservice;
64 @Autowired
65 private IDescriptionService descriptionService;
66
67 /*
68 * (non-Javadoc)
69 *
70 * @see
71 * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy
72 * .cdm.api.service.IService)
73 */
74 @Autowired
75 @Override
76 public void setService(ITaxonService service) {
77 this.service = service;
78 }
79
80 /**
81 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
82 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
83 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
84 * nested sub-areas.
85 * <p>
86 * URI: <b>&#x002F;{datasource-name}&#x002F;geo&#x002F;map&#x002F;distribution&#x002F;{taxon-uuid}</b>
87 *
88 * @param request
89 * @param response
90 * @return URI parameter Strings for the EDIT Map Service
91 * @throws IOException TODO write controller method documentation
92 */
93 @RequestMapping(value = { "taxonDistributionFor/{uuid}" }, method = RequestMethod.GET)
94 public ModelAndView doGetDistributionMapUriParams(
95 @PathVariable("uuid") UUID uuid,
96 HttpServletRequest request,
97 HttpServletResponse response)
98 throws IOException {
99
100
101 int width = 0;
102 int height = 0;
103 String bbox = null;
104 String backLayer = null;
105
106 logger.info("doGetDistributionMapUriParams() " + request.getServletPath());
107 ModelAndView mv = new ModelAndView();
108
109 // get the descriptions for the taxon
110 Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
111
112 Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors = null;
113 //languages
114 List<Language> langs = LocaleContext.getLanguages();
115
116 Pager<TaxonDescription> page = descriptionService.getTaxonDescriptions(taxon, null, null, null, null, null);
117 List<TaxonDescription> taxonDescriptions = page.getRecords();
118 String uriParams = geoservice.getDistributionServiceRequestParameterString(taxonDescriptions, presenceAbsenceTermColors, width, height, bbox,
119 backLayer, langs);
120 mv.addObject(uriParams);
121 return mv;
122 }
123
124
125 /**
126 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
127 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
128 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
129 * nested sub-areas.
130 * <p>
131 * URI: <b>&#x002F;{datasource-name}&#x002F;geo&#x002F;map&#x002F;distribution&#x002F;{taxon-uuid}</b>
132 *
133 * @param request
134 * @param response
135 * @return URI parameter Strings for the EDIT Map Service
136 * @throws IOException TODO write controller method documentation
137 */
138 @RequestMapping(value = { "taxonOccurrencesFor/{uuid}" }, method = RequestMethod.GET)
139 public ModelAndView doGetOccurrenceMapUriParams(
140 @PathVariable("uuid") UUID uuid,
141 HttpServletRequest request,
142 HttpServletResponse response)
143 throws IOException {
144
145 Integer width = null;
146 Integer height = null;
147 String bbox = null;
148 String backLayer = null;
149 Boolean doReturnImage = null;
150 Map<Class<? extends SpecimenOrObservationBase>, Color> specimenOrObservationTypeColors = null;
151
152 logger.info("doGetOccurrenceMapUriParams() " + request.getServletPath());
153 ModelAndView mv = new ModelAndView();
154
155 // get the descriptions for the taxon
156 Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
157
158 Pager<TaxonDescription> page = descriptionService.getTaxonDescriptions(taxon, null, null, null, null, null);
159 List<TaxonDescription> taxonDescriptions = page.getRecords();
160
161 String uriParams = geoservice.getOccurrenceServiceRequestParameterString(taxonDescriptions, specimenOrObservationTypeColors, doReturnImage, width , height , bbox , backLayer );
162 mv.addObject(uriParams);
163 return mv;
164 }
165
166 }