// $Id$\r
/**\r
* Copyright (C) 2009 EDIT\r
- * European Distributed Institute of Taxonomy \r
+ * European Distributed Institute of Taxonomy\r
* http://www.e-taxonomy.eu\r
- * \r
+ *\r
* The contents of this file are subject to the Mozilla Public License Version 1.1\r
* See LICENSE.TXT at the top of this package for the full license terms.\r
*/\r
\r
import java.awt.Color;\r
import java.io.IOException;\r
+import java.util.ArrayList;\r
import java.util.List;\r
import java.util.Map;\r
+import java.util.Set;\r
import java.util.UUID;\r
\r
import javax.servlet.http.HttpServletRequest;\r
import org.apache.log4j.Logger;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.stereotype.Controller;\r
+import org.springframework.web.bind.WebDataBinder;\r
+import org.springframework.web.bind.annotation.InitBinder;\r
import org.springframework.web.bind.annotation.PathVariable;\r
import org.springframework.web.bind.annotation.RequestMapping;\r
import org.springframework.web.bind.annotation.RequestMethod;\r
+import org.springframework.web.bind.annotation.RequestParam;\r
import org.springframework.web.servlet.ModelAndView;\r
\r
import eu.etaxonomy.cdm.api.service.IDescriptionService;\r
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
import eu.etaxonomy.cdm.api.service.ITaxonService;\r
+import eu.etaxonomy.cdm.api.service.ITermService;\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
+import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;\r
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;\r
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;\r
+import eu.etaxonomy.cdm.model.common.DefinedTerm;\r
import eu.etaxonomy.cdm.model.common.Language;\r
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;\r
import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
+import eu.etaxonomy.cdm.model.location.NamedArea;\r
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
+import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
+import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;\r
import eu.etaxonomy.cdm.remote.controller.BaseController;\r
+import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;\r
+import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;\r
+import eu.etaxonomy.cdm.remote.editor.UuidList;\r
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;\r
\r
/**\r
* is loaded by the {@link UpdatableRoutingDataSource}. If the\r
* UpdatableRoutingDataSource is not being used in the actual application\r
* context any arbitrary {datasource-name} may be used.\r
- * <p> \r
+ * <p>\r
* @author a.kohlbecker\r
* @date 18.06.2009\r
- * \r
+ *\r
*/\r
@Controller\r
@RequestMapping(value = { "ext/edit/mapServiceParameters/" })\r
public class ExternalGeoController extends BaseController<TaxonBase, ITaxonService> {\r
- \r
- public static final Logger logger = Logger.getLogger(ExternalGeoController.class);\r
-\r
- @Autowired\r
- private IEditGeoService geoservice;\r
- @Autowired\r
- private IDescriptionService descriptionService;\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy\r
- * .cdm.api.service.IService)\r
- */\r
- @Autowired\r
- @Override\r
- public void setService(ITaxonService service) {\r
- this.service = service;\r
- }\r
-\r
- /**\r
- * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the \r
- * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into \r
- * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all \r
- * nested sub-areas. \r
- * <p>\r
- * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>\r
- * \r
- * @param request\r
- * @param response\r
- * @return URI parameter Strings for the EDIT Map Service\r
- * @throws IOException TODO write controller method documentation\r
- */\r
- @RequestMapping(value = { "taxonDistributionFor/{uuid}" }, method = RequestMethod.GET)\r
- public ModelAndView doGetDistributionMapUriParams(\r
- @PathVariable("uuid") UUID uuid,\r
- HttpServletRequest request, \r
- HttpServletResponse response)\r
- throws IOException {\r
- \r
- \r
- int width = 0;\r
- int height = 0;\r
- String bbox = null;\r
- String backLayer = null;\r
- \r
- logger.info("doGetDistributionMapUriParams() " + request.getServletPath());\r
- ModelAndView mv = new ModelAndView();\r
- \r
- // get the descriptions for the taxon\r
- Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
- \r
- Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors = null;\r
- //languages\r
- List<Language> langs = LocaleContext.getLanguages();\r
-\r
- Pager<TaxonDescription> page = descriptionService.getTaxonDescriptions(taxon, null, null, null, null, null);\r
- List<TaxonDescription> taxonDescriptions = page.getRecords();\r
- String uriParams = geoservice.getDistributionServiceRequestParameterString(taxonDescriptions, presenceAbsenceTermColors, width, height, bbox,\r
- backLayer, langs);\r
- mv.addObject(uriParams);\r
- return mv;\r
- }\r
- \r
- \r
- /**\r
- * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the \r
- * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into \r
- * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all \r
- * nested sub-areas. \r
- * <p>\r
- * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>\r
- * \r
- * @param request\r
- * @param response\r
- * @return URI parameter Strings for the EDIT Map Service\r
- * @throws IOException TODO write controller method documentation\r
- */\r
- @RequestMapping(value = { "taxonOccurrencesFor/{uuid}" }, method = RequestMethod.GET)\r
- public ModelAndView doGetOccurrenceMapUriParams(\r
- @PathVariable("uuid") UUID uuid,\r
- HttpServletRequest request, \r
- HttpServletResponse response)\r
- throws IOException {\r
- \r
- Integer width = null;\r
- Integer height = null;\r
- String bbox = null;\r
- String backLayer = null;\r
- Boolean doReturnImage = null;\r
- Map<Class<? extends SpecimenOrObservationBase<?>>, Color> specimenOrObservationTypeColors = null;\r
- \r
- logger.info("doGetOccurrenceMapUriParams() " + request.getServletPath());\r
- ModelAndView mv = new ModelAndView();\r
- \r
- // get the descriptions for the taxon\r
- Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
-\r
- Pager<TaxonDescription> page = descriptionService.getTaxonDescriptions(taxon, null, null, null, null, null);\r
- List<TaxonDescription> taxonDescriptions = page.getRecords();\r
- \r
- String uriParams = geoservice.getOccurrenceServiceRequestParameterString(taxonDescriptions, specimenOrObservationTypeColors, doReturnImage, width , height , bbox , backLayer );\r
- mv.addObject(uriParams);\r
- return mv;\r
- }\r
+\r
+ public static final Logger logger = Logger.getLogger(ExternalGeoController.class);\r
+\r
+ @Autowired\r
+ private IEditGeoService geoservice;\r
+\r
+ @Autowired\r
+ private IDescriptionService descriptionService;\r
+\r
+ @Autowired\r
+ private IOccurrenceService occurrenceService;\r
+\r
+ @Autowired\r
+ private ITermService termService;\r
+\r
+ @InitBinder\r
+ @Override\r
+ public void initBinder(WebDataBinder binder) {\r
+ super.initBinder(binder);\r
+ binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy\r
+ * .cdm.api.service.IService)\r
+ */\r
+ @Autowired\r
+ @Override\r
+ public void setService(ITaxonService service) {\r
+ this.service = service;\r
+ }\r
+\r
+ /**\r
+ * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the\r
+ * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into\r
+ * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all\r
+ * nested sub-areas.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return URI parameter Strings for the EDIT Map Service\r
+ * @throws IOException TODO write controller method documentation\r
+ */\r
+ @RequestMapping(value = { "taxonDistributionFor/{uuid}" }, method = RequestMethod.GET)\r
+ public ModelAndView doGetDistributionMapUriParams(\r
+ @PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response)\r
+ throws IOException {\r
+\r
+\r
+ int width = 0;\r
+ int height = 0;\r
+ String bbox = null;\r
+ String backLayer = null;\r
+\r
+ logger.info("doGetDistributionMapUriParams() " + request.getRequestURI());\r
+ ModelAndView mv = new ModelAndView();\r
+\r
+ // get the descriptions for the taxon\r
+ Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
+\r
+ Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors = null;\r
+ //languages\r
+ List<Language> langs = LocaleContext.getLanguages();\r
+\r
+ Set<DefinedTerm> scopes = null;\r
+ Set<NamedArea> geographicalScope = null;\r
+ Integer pageSize = null;\r
+ Integer pageNumber = null;\r
+ List<String> propertyPaths = null;\r
+ Pager<TaxonDescription> page = descriptionService.pageTaxonDescriptions(taxon, scopes, geographicalScope, pageSize, pageNumber, propertyPaths);\r
+\r
+ List<TaxonDescription> taxonDescriptions = page.getRecords();\r
+ String uriParams = geoservice.getDistributionServiceRequestParameterString(taxonDescriptions, presenceAbsenceTermColors, width, height, bbox,\r
+ backLayer, langs);\r
+ mv.addObject(uriParams);\r
+ return mv;\r
+ }\r
+\r
+\r
+ /**\r
+ * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the\r
+ * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into\r
+ * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all\r
+ * nested sub-areas.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return URI parameter Strings for the EDIT Map Service\r
+ * @throws IOException TODO write controller method documentation\r
+ */\r
+ @RequestMapping(value = { "taxonOccurrencesFor/{uuid}" }, method = RequestMethod.GET)\r
+ public ModelAndView doGetOccurrenceMapUriParams(\r
+ @PathVariable("uuid") UUID uuid,\r
+ @RequestParam(value = "relationships", required = false) UuidList relationshipUuids,\r
+ @RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,\r
+ @RequestParam(value = "maxDepth", required = false) Integer maxDepth,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response)\r
+ throws IOException {\r
+\r
+ Integer width = null;\r
+ Integer height = null;\r
+ String bbox = null;\r
+ String backLayer = null;\r
+ Boolean doReturnImage = null;\r
+ Map<SpecimenOrObservationType, Color> specimenOrObservationTypeColors = null;\r
+\r
+ logger.info("doGetOccurrenceMapUriParams() " + request.getRequestURI() + "?" + request.getQueryString());\r
+ ModelAndView mv = new ModelAndView();\r
+\r
+ Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);\r
+\r
+ Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);\r
+\r
+ List<OrderHint> orderHints = new ArrayList<OrderHint>();\r
+ orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));\r
+\r
+ List<SpecimenOrObservationBase> specimensOrObersvations = occurrenceService.listByAssociatedTaxon(null, includeRelationships, taxon, maxDepth, null, null, orderHints, null);\r
+\r
+ String uriParams = geoservice.getOccurrenceServiceRequestParameterString(specimensOrObersvations, specimenOrObservationTypeColors, doReturnImage, width , height , bbox , backLayer );\r
+ mv.addObject(uriParams);\r
+ return mv;\r
+ }\r
\r
}\r