Project

General

Profile

Download (4.24 KB) Statistics
| Branch: | Tag: | Revision:
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;
11

    
12
import java.awt.Color;
13
import java.io.IOException;
14
import java.util.List;
15
import java.util.Map;
16

    
17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
19

    
20
import org.apache.log4j.Logger;
21
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.stereotype.Controller;
23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestMethod;
25
import org.springframework.web.servlet.ModelAndView;
26

    
27
import eu.etaxonomy.cdm.api.service.IDescriptionService;
28
import eu.etaxonomy.cdm.api.service.ITaxonService;
29
import eu.etaxonomy.cdm.api.service.pager.Pager;
30
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
31
import eu.etaxonomy.cdm.ext.IEditGeoService;
32
import eu.etaxonomy.cdm.model.common.Language;
33
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
34
import eu.etaxonomy.cdm.model.description.TaxonDescription;
35
import eu.etaxonomy.cdm.model.taxon.Taxon;
36
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
37
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
38

    
39
/**
40
 * The ExternalGeoController class is a Spring MVC Controller.
41
 * <p>
42
 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
43
 * The available {datasource-name}s are defined in a configuration file which
44
 * is loaded by the {@link UpdatableRoutingDataSource}. If the
45
 * UpdatableRoutingDataSource is not being used in the actual application
46
 * context any arbitrary {datasource-name} may be used.
47
 * <p> 
48
 * @author a.kohlbecker
49
 * @date 18.06.2009
50
 * 
51
 */
52
@Controller
53
@RequestMapping(value = { "/geo/map/distribution/*" })
54
public class ExternalGeoController extends BaseController<TaxonBase, ITaxonService> {
55
	
56
	public static final Logger logger = Logger.getLogger(ExternalGeoController.class);
57

    
58
	@Autowired
59
	private IEditGeoService geoservice;
60
	@Autowired
61
	private IDescriptionService descriptionService;
62
	
63
	public ExternalGeoController() {
64
		super();
65
		setUuidParameterPattern("^/geo/(?:[^/]+)/(?:[^/]+)/([^/?#&\\.]+).*");
66
	}
67

    
68
	/*
69
	 * (non-Javadoc)
70
	 * 
71
	 * @see
72
	 * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy
73
	 * .cdm.api.service.IService)
74
	 */
75
	@Autowired
76
	@Override
77
	public void setService(ITaxonService service) {
78
		this.service = service;
79
	}
80

    
81
	/**
82
	 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the  
83
	 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into 
84
	 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all 
85
	 * nested sub-areas. 
86
	 * <p>
87
	 * URI: <b>&#x002F;{datasource-name}&#x002F;geo&#x002F;map&#x002F;distribution&#x002F;{taxon-uuid}</b>
88
	 * 
89
	 * @param request
90
	 * @param response
91
	 * @return URI parameter Strings for the EDIT Map Service
92
	 * @throws IOException TODO write controller method documentation
93
	 */
94
	@RequestMapping(value = { "/geo/map/distribution/*" }, method = RequestMethod.GET)
95
	public ModelAndView doGetDistributionMapUriParams(HttpServletRequest request, HttpServletResponse response)
96
			throws IOException {
97
		
98
		logger.info("doGetDistributionMapUriParams() " + request.getServletPath());
99
		ModelAndView mv = new ModelAndView();
100
		// get the descriptions for the taxon
101
		Taxon taxon = getCdmBase(request, response, null, Taxon.class);
102

    
103
		Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors = null;
104
		//languages
105
		List<Language> langs = LocaleContext.getLanguages();
106

    
107
		Pager<TaxonDescription> page = descriptionService.getTaxonDescriptions(taxon, null, null, null, null, null);
108
		List<TaxonDescription> taxonDescriptions = page.getRecords();
109
		String uriParams = geoservice.getEditGeoServiceUrlParameterString(taxonDescriptions, presenceAbsenceTermColors, 0, 0, null,
110
			null, langs);
111
		mv.addObject(uriParams);
112
		return mv;
113
	}
114

    
115
}
(14-14/36)