Project

General

Profile

Download (4.69 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.ext;
11

    
12
import java.awt.Color;
13
import java.util.ArrayList;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Set;
18

    
19
import org.apache.log4j.Logger;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.stereotype.Service;
22
import org.springframework.transaction.annotation.Transactional;
23

    
24
import eu.etaxonomy.cdm.model.common.Language;
25
import eu.etaxonomy.cdm.model.description.Distribution;
26
import eu.etaxonomy.cdm.model.description.Feature;
27
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
28
import eu.etaxonomy.cdm.model.description.TaxonDescription;
29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
31
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
32

    
33
/**
34
 * @author a.kohlbecker
35
 * @date 18.06.2009
36
 *
37
 */
38
@Service
39
@Transactional(readOnly=true)
40
public class EditGeoService implements IEditGeoService{
41
	
42
	private static final String DEFAULT_BACK_LAYER = "tdwg4";
43

    
44
	public static final Logger logger = Logger.getLogger(EditGeoService.class);
45
	
46
	@Autowired
47
	private IDescriptionDao dao;
48
	@Autowired
49
	private IDefinedTermDao termDao;
50

    
51
	private Set<Feature> getDistributionFeatures() {
52
		Set<Feature> distributionFeature = new HashSet<Feature>();
53
		Feature feature = (Feature) termDao.findByUuid(Feature.DISTRIBUTION().getUuid());
54
		distributionFeature.add(feature);
55
		return distributionFeature;
56
	}
57
	
58
	/* (non-Javadoc)
59
	 * @see eu.etaxonomy.cdm.ext.IEditGeoService#getEditGeoServiceUrlParameterString(java.util.List, java.util.Map, int, int, java.lang.String, java.lang.String, java.util.List)
60
	 */
61
	public String getEditGeoServiceUrlParameterString(
62
			List<TaxonDescription> taxonDescriptions,
63
			Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors,
64
			int width, int height, String bbox, String backLayer,
65
			List<Language> langs) {
66
		Set<Distribution> distributions = new HashSet<Distribution>();
67
		for(TaxonDescription taxonDescription : taxonDescriptions){
68
			List<Distribution> result = (List)dao.getDescriptionElements(taxonDescription, getDistributionFeatures(), Distribution.class, null, null, null);
69
			distributions.addAll(result);
70
		}
71
		
72
		if(backLayer == null){
73
			backLayer = DEFAULT_BACK_LAYER;
74
		}
75
		String uriParams = EditGeoServiceUtilities.getEditGeoServiceUrlParameterString(distributions, presenceAbsenceTermColors, width, height, bbox, backLayer, langs);
76

    
77
		return uriParams;
78
	}
79

    
80
	/* (non-Javadoc)
81
	 * @see eu.etaxonomy.cdm.ext.IEditGeoService#getEditGeoServiceUrlParameterString(eu.etaxonomy.cdm.model.description.TaxonDescription, java.util.Map, int, int, java.lang.String, java.lang.String)
82
	 */
83
	public String getEditGeoServiceUrlParameterString(
84
			TaxonDescription taxonDescription,
85
			Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors,
86
			int width, int height, String bbox, String backLayer,
87
			List<Language> langs) {
88
		
89
		List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();
90
		taxonDescriptions.add(taxonDescription);
91
		
92
		return getEditGeoServiceUrlParameterString(taxonDescriptions, presenceAbsenceTermColors, width, height, bbox, backLayer, langs);
93
	}
94
	
95
	/* (non-Javadoc)
96
	 * @see eu.etaxonomy.cdm.api.service.IEditGeoService#getEditGeoServiceUrlParameterString(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.Map, int, int, java.lang.String, java.lang.String)
97
	 */
98
	public String getEditGeoServiceUrlParameterString(Taxon taxon,
99
			Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors, int width, int height, String bbox,
100
			String backLayer,
101
			List<Language> langs) {
102
		
103
		List<TaxonDescription> taxonDescriptions = dao.getTaxonDescriptions(taxon, null, null, null, null, null);
104
		
105
		Set<Distribution> distCollection = new HashSet<Distribution>();
106
		// get descriptions elements for each description
107
		for (TaxonDescription td : taxonDescriptions) {
108
			List<Distribution> dists = (List)dao.getDescriptionElements(td, getDistributionFeatures(), Distribution.class, null, null, null);
109
			distCollection.addAll(dists);
110
		}
111
		// generate the uri parameter string
112
		if(backLayer == null){
113
			backLayer = DEFAULT_BACK_LAYER;
114
		}
115
		String uriParams = EditGeoServiceUtilities.getEditGeoServiceUrlParameterString(distCollection,
116
			presenceAbsenceTermColors, width, height, bbox, backLayer, langs);
117

    
118
		return uriParams;
119
	}	
120
	
121
}
(1-1/3)