2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.synthesys
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.ListIterator
;
16 import org
.apache
.log4j
.Logger
;
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
;
33 public class UnitsGatheringEvent
{
35 private static final Logger logger
= Logger
.getLogger(UnitsGatheringEvent
.class);
36 private GatheringEvent gatheringEvent
= GatheringEvent
.NewInstance();
40 * Fill in the locality, coordinates and the collector(s) for the current GatheringEvent
41 * @param app: the CDM Application Controller
46 * @param collectorNames
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
);
54 public GatheringEvent
getGatheringEvent(){
55 return this.gatheringEvent
;
59 * Set the locality for the current GatheringEvent
63 public void setLocality(ICdmApplicationConfiguration config
, String locality
, String languageIso
){
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());
71 loc
= LanguageString
.NewInstance(locality
,config
.getTermService().getLanguageByIso(languageIso
));
72 this.gatheringEvent
.setLocality(loc
);
76 * return the locality associated to the GatheringEvent
78 public LanguageString
getLocality(){
79 return this.gatheringEvent
.getLocality();
83 * Set the coordinates for the current GatheringEvent
87 public void setCoordinates(Double longitude
, Double latitude
){
88 //create coordinates point
89 Point coordinates
= Point
.NewInstance();
91 coordinates
.setLongitude(longitude
);
92 coordinates
.setLatitude(latitude
);
93 this.gatheringEvent
.setExactLocation(coordinates
);
96 public void setElevation(Integer elevation
){
97 this.gatheringEvent
.setAbsoluteElevation(elevation
);
101 * Add a NamedArea to the GatheringEvent
102 * @param area: the NamedArea to add
105 public void addArea(NamedArea area
){
106 this.gatheringEvent
.addCollectingArea(area
);
110 * If the collector already exists, then use it
111 * if not, create a new collector
114 public void setCollector(ICdmApplicationConfiguration config
, ArrayList
<String
> collectorNames
,boolean getExisting
){
117 ListIterator
<String
> collectors
= collectorNames
.listIterator();
120 while (collectors
.hasNext()){
121 collName
= collectors
.next();
122 /*check if the collector does already exist*/
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
);
130 this.gatheringEvent
.setCollector(collector
);
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
139 public void setCollector(ArrayList
<String
> collectorNames
){
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
);
153 else if (collectorNames
.size() == 1) {
154 collName
= collectorNames
.get(0);
155 collector
= Person
.NewInstance();
156 collector
.setTitleCache(collName
);
157 this.gatheringEvent
.setCollector(collector
);