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
.specimen
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
15 import java
.util
.ListIterator
;
17 import org
.apache
.log4j
.Logger
;
19 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
24 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
25 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
26 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
27 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
35 public class UnitsGatheringEvent
{
37 private static final Logger logger
= Logger
.getLogger(UnitsGatheringEvent
.class);
38 private GatheringEvent gatheringEvent
= GatheringEvent
.NewInstance();
42 * Fill in the locality, coordinates and the collector(s) for the current GatheringEvent
43 * @param app: the CDM Application Controller
48 * @param collectorNames
50 public UnitsGatheringEvent(ITermService termService
, String locality
, String languageIso
, Double longitude
, Double latitude
, ArrayList
<String
> collectorNames
){
51 this.setLocality(termService
, locality
, languageIso
);
52 this.setCoordinates(longitude
, latitude
);
53 this.setCollector(collectorNames
);
56 public GatheringEvent
getGatheringEvent(){
57 return this.gatheringEvent
;
61 * Set the locality for the current GatheringEvent
65 public void setLocality(ITermService termService
, String locality
, String languageIso
){
67 if (languageIso
== null || termService
.getLanguageByIso(languageIso
) == null){
68 if (languageIso
!= null && termService
.getLanguageByIso(languageIso
) == null ){
69 logger
.info("unknown iso used for the locality: "+languageIso
);
71 //FIXME should be UNKNOWN
72 loc
= LanguageString
.NewInstance(locality
, Language
.DEFAULT());
74 loc
= LanguageString
.NewInstance(locality
, termService
.getLanguageByIso(languageIso
));
76 this.gatheringEvent
.setLocality(loc
);
80 * return the locality associated to the GatheringEvent
82 public LanguageString
getLocality(){
83 return this.gatheringEvent
.getLocality();
87 * Set the coordinates for the current GatheringEvent
91 public void setCoordinates(Double longitude
, Double latitude
){
92 //create coordinates point
93 Point coordinates
= Point
.NewInstance();
95 coordinates
.setLongitude(longitude
);
96 coordinates
.setLatitude(latitude
);
97 this.gatheringEvent
.setExactLocation(coordinates
);
100 public void setElevation(Integer elevation
){
101 this.gatheringEvent
.setAbsoluteElevation(elevation
);
105 * Add a NamedArea to the GatheringEvent
106 * @param area: the NamedArea to add
109 public void addArea(NamedArea area
){
110 this.gatheringEvent
.addCollectingArea(area
);
114 * If the collector already exists, then use it
115 * if not, create a new collector
118 public void setCollector(ICdmApplicationConfiguration config
, ArrayList
<String
> collectorNames
,boolean getExisting
){
121 ListIterator
<String
> collectors
= collectorNames
.listIterator();
124 while (collectors
.hasNext()){
125 collName
= collectors
.next();
126 /*check if the collector does already exist*/
128 List
<AgentBase
> col
= config
.getAgentService().findByTitle(null,collName
,null,null,null,null,null, null).getRecords();
129 collector
=col
.get(0);
130 }catch (Exception e
) {
131 collector
= Person
.NewInstance();
132 collector
.setTitleCache(collName
, true);
134 this.gatheringEvent
.setCollector(collector
);
139 * Create a new collector or collector's team
140 * @param: collectorNames: the list of names to add as collector/collectorTeam
141 * USED - create each time a new Collector
143 public void setCollector(ArrayList
<String
> collectorNames
){
147 if (collectorNames
.size()>1){
148 Team team
= new Team();
149 for (String strCollectorName
: collectorNames
){
150 collector
= Person
.NewInstance();
151 collector
.setTitleCache(strCollectorName
, true);
152 team
.addTeamMember(collector
);
153 this.gatheringEvent
.setCollector(team
);
155 }else if (collectorNames
.size() == 1) {
156 collName
= collectorNames
.get(0);
157 collector
= Person
.NewInstance();
158 collector
.setTitleCache(collName
, true);
159 this.gatheringEvent
.setCollector(collector
);