Committing large number of changes relating to versioning implementation (#108) ...
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / synthesys / UnitsGatheringEvent.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.io.synthesys;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.ListIterator;
15
16 import org.apache.log4j.Logger;
17
18 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
19 import eu.etaxonomy.cdm.model.agent.AgentBase;
20 import eu.etaxonomy.cdm.model.agent.Person;
21 import eu.etaxonomy.cdm.model.agent.Team;
22 import eu.etaxonomy.cdm.model.common.Language;
23 import eu.etaxonomy.cdm.model.common.LanguageString;
24 import eu.etaxonomy.cdm.model.location.NamedArea;
25 import eu.etaxonomy.cdm.model.location.Point;
26 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
27
28 /**
29 * @author p.kelbert
30 * @created 29.10.2008
31 * @version 1.0
32 */
33 public class UnitsGatheringEvent {
34
35 private static final Logger logger = Logger.getLogger(UnitsGatheringEvent.class);
36 private GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
37
38 /*
39 * Constructor
40 * Fill in the locality, coordinates and the collector(s) for the current GatheringEvent
41 * @param app: the CDM Application Controller
42 * @param locality
43 * @param languageIso
44 * @param longitude
45 * @param latitude
46 * @param collectorNames
47 */
48 public UnitsGatheringEvent(ICdmApplicationConfiguration config, String locality, String languageIso, Double longitude, Double latitude, ArrayList<String> collectorNames){
49 this.setLocality(config, locality, languageIso);
50 this.setCoordinates(longitude, latitude);
51 this.setCollector(collectorNames);
52 }
53
54 public GatheringEvent getGatheringEvent(){
55 return this.gatheringEvent;
56 }
57
58 /*
59 * Set the locality for the current GatheringEvent
60 * @param locality
61 * @param langageIso
62 */
63 public void setLocality(ICdmApplicationConfiguration config, String locality, String languageIso){
64 LanguageString loc;
65 if (languageIso == null || config.getTermService().getLanguageByIso(languageIso) == null){
66 if (languageIso != null && config.getTermService().getLanguageByIso(languageIso) == null )
67 logger.info("unknown iso used for the locality: "+languageIso);
68 loc = LanguageString.NewInstance(locality,Language.DEFAULT());
69 }
70 else
71 loc = LanguageString.NewInstance(locality,config.getTermService().getLanguageByIso(languageIso));
72 this.gatheringEvent.setLocality(loc);
73 }
74
75 /*
76 * return the locality associated to the GatheringEvent
77 */
78 public LanguageString getLocality(){
79 return this.gatheringEvent.getLocality();
80 }
81
82 /*
83 * Set the coordinates for the current GatheringEvent
84 * @param: longitude
85 * @param: latitude
86 */
87 public void setCoordinates(Double longitude, Double latitude){
88 //create coordinates point
89 Point coordinates = Point.NewInstance();
90 //add coordinates
91 coordinates.setLongitude(longitude);
92 coordinates.setLatitude(latitude);
93 this.gatheringEvent.setExactLocation(coordinates);
94 }
95
96 public void setElevation(Integer elevation){
97 this.gatheringEvent.setAbsoluteElevation(elevation);
98 }
99
100 /*
101 * Add a NamedArea to the GatheringEvent
102 * @param area: the NamedArea to add
103 */
104
105 public void addArea(NamedArea area){
106 this.gatheringEvent.addCollectingArea(area);
107 }
108
109 /*
110 * If the collector already exists, then use it
111 * if not, create a new collector
112 * NOT USED
113 */
114 public void setCollector(ICdmApplicationConfiguration config, ArrayList<String> collectorNames,boolean getExisting){
115 //create collector
116 AgentBase collector;
117 ListIterator<String> collectors = collectorNames.listIterator();
118 //add the collectors
119 String collName;
120 while (collectors.hasNext()){
121 collName = collectors.next();
122 /*check if the collector does already exist*/
123 try{
124 List<AgentBase> col = config.getAgentService().findAgentsByTitle(collName);
125 collector=col.get(0);
126 }catch (Exception e) {
127 collector = Person.NewInstance();
128 collector.setTitleCache(collName);
129 }
130 this.gatheringEvent.setCollector(collector);
131 }
132 }
133
134 /*
135 * Create a new collector or collector's team
136 * @param: collectorNames: the list of names to add as collector/collectorTeam
137 * USED - create each time a new Collector
138 */
139 public void setCollector(ArrayList<String> collectorNames){
140 Person collector;
141 String collName;
142
143 if (collectorNames.size()>1){
144 Team team = new Team();
145 for (int i=0;i<collectorNames.size();i++){
146 collName = collectorNames.get(i);
147 collector = Person.NewInstance();
148 collector.setTitleCache(collName);
149 team.addTeamMember(collector);
150 this.gatheringEvent.setCollector(team);
151 }
152 }
153 else if (collectorNames.size() == 1) {
154 collName = collectorNames.get(0);
155 collector = Person.NewInstance();
156 collector.setTitleCache(collName);
157 this.gatheringEvent.setCollector(collector);
158 }
159
160 }
161
162
163 }