Moving IPNI service to new package and adding new functionality.
[cdmlib.git] / cdmlib-ext / src / main / java / eu / etaxonomy / cdm / ext / EditGeoService.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.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 public static final Logger logger = Logger.getLogger(EditGeoService.class);
42
43 private static final String DEFAULT_BACK_LAYER = "tdwg4";
44
45 @Autowired
46 private IDescriptionDao dao;
47 @Autowired
48 private IDefinedTermDao termDao;
49
50 private Set<Feature> getDistributionFeatures() {
51 Set<Feature> distributionFeature = new HashSet<Feature>();
52 Feature feature = (Feature) termDao.findByUuid(Feature.DISTRIBUTION().getUuid());
53 distributionFeature.add(feature);
54 return distributionFeature;
55 }
56
57 /* (non-Javadoc)
58 * @see eu.etaxonomy.cdm.ext.IEditGeoService#getEditGeoServiceUrlParameterString(java.util.List, java.util.Map, int, int, java.lang.String, java.lang.String, java.util.List)
59 */
60 public String getEditGeoServiceUrlParameterString(
61 List<TaxonDescription> taxonDescriptions,
62 Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors,
63 int width, int height, String bbox, String backLayer,
64 List<Language> langs) {
65 Set<Distribution> distributions = new HashSet<Distribution>();
66 for(TaxonDescription taxonDescription : taxonDescriptions){
67 List<Distribution> result = (List)dao.getDescriptionElements(taxonDescription, getDistributionFeatures(), Distribution.class, null, null, null);
68 distributions.addAll(result);
69 }
70
71 if(backLayer == null){
72 backLayer = DEFAULT_BACK_LAYER;
73 }
74 String uriParams = EditGeoServiceUtilities.getEditGeoServiceUrlParameterString(distributions, presenceAbsenceTermColors, width, height, bbox, backLayer, langs);
75
76 return uriParams;
77 }
78
79 /* (non-Javadoc)
80 * @see eu.etaxonomy.cdm.ext.IEditGeoService#getEditGeoServiceUrlParameterString(eu.etaxonomy.cdm.model.description.TaxonDescription, java.util.Map, int, int, java.lang.String, java.lang.String)
81 */
82 public String getEditGeoServiceUrlParameterString(
83 TaxonDescription taxonDescription,
84 Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors,
85 int width, int height, String bbox, String backLayer,
86 List<Language> langs) {
87
88 List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();
89 taxonDescriptions.add(taxonDescription);
90
91 return getEditGeoServiceUrlParameterString(taxonDescriptions, presenceAbsenceTermColors, width, height, bbox, backLayer, langs);
92 }
93
94 /* (non-Javadoc)
95 * @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)
96 */
97 public String getEditGeoServiceUrlParameterString(Taxon taxon,
98 Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors, int width, int height, String bbox,
99 String backLayer,
100 List<Language> langs) {
101
102 List<TaxonDescription> taxonDescriptions = dao.getTaxonDescriptions(taxon, null, null, null, null, null);
103
104 Set<Distribution> distCollection = new HashSet<Distribution>();
105 // get descriptions elements for each description
106 for (TaxonDescription td : taxonDescriptions) {
107 List<Distribution> dists = (List)dao.getDescriptionElements(td, getDistributionFeatures(), Distribution.class, null, null, null);
108 distCollection.addAll(dists);
109 }
110 // generate the uri parameter string
111 if(backLayer == null){
112 backLayer = DEFAULT_BACK_LAYER;
113 }
114 String uriParams = EditGeoServiceUtilities.getEditGeoServiceUrlParameterString(distCollection,
115 presenceAbsenceTermColors, width, height, bbox, backLayer, langs);
116
117 return uriParams;
118 }
119
120 }