Project

General

Profile

Download (4.91 KB) Statistics
| Branch: | Tag: | Revision:
1 01be5674 Andreas Müller
/**
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 d1b5d01f Andreas Müller
package eu.etaxonomy.cdm.io.specimen;
11 d1b1103d p.kelbert
12
13
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.ListIterator;
16
17 ce2f42eb p.kelbert
import org.apache.log4j.Logger;
18
19 01be5674 Andreas Müller
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
20 f0008608 Andreas Müller
import eu.etaxonomy.cdm.api.service.ITermService;
21 08b9a163 ben.clark
import eu.etaxonomy.cdm.model.agent.AgentBase;
22 d1b1103d p.kelbert
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;
29
30 01be5674 Andreas Müller
/**
31
 * @author p.kelbert
32
 * @created 20.10.2008
33
 * @version 1.0
34
 */
35 d1b1103d p.kelbert
public class UnitsGatheringEvent {
36
37 ce2f42eb p.kelbert
	private static final Logger logger = Logger.getLogger(UnitsGatheringEvent.class);
38 d1b1103d p.kelbert
	private GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
39
40
	/*
41
	 * Constructor
42
	 * Fill in the locality, coordinates and the collector(s) for the current GatheringEvent
43
	 * @param app: the CDM Application Controller
44
	 * @param locality
45
	 * @param languageIso
46
	 * @param longitude
47
	 * @param latitude
48
	 * @param collectorNames
49
	 */
50 f0008608 Andreas Müller
	public UnitsGatheringEvent(ITermService termService, String locality, String languageIso, Double longitude, Double latitude, ArrayList<String> collectorNames){
51
		this.setLocality(termService, locality, languageIso);
52 d1b1103d p.kelbert
		this.setCoordinates(longitude, latitude);
53
		this.setCollector(collectorNames);
54
	}
55
56
	public GatheringEvent getGatheringEvent(){
57
		return this.gatheringEvent;
58
	}
59
60
	/*
61
	 * Set the locality for the current GatheringEvent
62
	 * @param locality
63
	 * @param langageIso
64
	 */
65 f0008608 Andreas Müller
	public void setLocality(ITermService termService, String locality, String languageIso){
66 d1b1103d p.kelbert
		LanguageString loc;
67 f0008608 Andreas Müller
		if (languageIso == null || termService.getLanguageByIso(languageIso) == null){
68
			if (languageIso != null && termService.getLanguageByIso(languageIso) == null ){
69 ce2f42eb p.kelbert
				logger.info("unknown iso used for the locality: "+languageIso);
70 d1b5d01f Andreas Müller
			}
71 f0008608 Andreas Müller
			//FIXME should be UNKNOWN
72
			loc = LanguageString.NewInstance(locality, Language.DEFAULT());
73 d1b5d01f Andreas Müller
		}else{
74 f0008608 Andreas Müller
			loc = LanguageString.NewInstance(locality, termService.getLanguageByIso(languageIso));
75 d1b5d01f Andreas Müller
		}
76 d1b1103d p.kelbert
		this.gatheringEvent.setLocality(loc);
77
	}
78 ce2f42eb p.kelbert
79 d1b1103d p.kelbert
	/*
80
	 * return the locality associated to the GatheringEvent
81
	 */
82
	public LanguageString getLocality(){
83
		return this.gatheringEvent.getLocality();
84
	}
85
86
	/*
87
	 * Set the coordinates for the current GatheringEvent
88
	 * @param: longitude
89
	 * @param: latitude
90
	 */
91
	public void setCoordinates(Double longitude, Double latitude){
92
		//create coordinates point
93 0465ccd1 Andreas Kohlbecker
		if(longitude == null || latitude == null){
94
			return;
95
		}
96 d1b1103d p.kelbert
		Point coordinates = Point.NewInstance();
97
		//add coordinates
98
		coordinates.setLongitude(longitude);
99
		coordinates.setLatitude(latitude);
100
		this.gatheringEvent.setExactLocation(coordinates);
101 0465ccd1 Andreas Kohlbecker
		
102 d1b1103d p.kelbert
	}
103
104
	public void setElevation(Integer elevation){
105
		this.gatheringEvent.setAbsoluteElevation(elevation);
106
	}
107
108
	/*
109
	 * Add a NamedArea to the GatheringEvent
110
	 * @param area: the NamedArea to add
111
	 */
112
113
	public void addArea(NamedArea area){
114
		this.gatheringEvent.addCollectingArea(area);
115
	}
116
117
	/*
118
	 * If the collector already exists, then use it
119
	 * if not, create a new collector
120
	 * NOT USED
121
	 */
122 01be5674 Andreas Müller
	public void setCollector(ICdmApplicationConfiguration config, ArrayList<String> collectorNames,boolean getExisting){
123 d1b1103d p.kelbert
		//create collector
124 08b9a163 ben.clark
		AgentBase collector;
125 d1b1103d p.kelbert
		ListIterator<String> collectors = collectorNames.listIterator();
126
		//add the collectors
127
		String collName;
128
		while (collectors.hasNext()){
129
			collName = collectors.next();
130
			/*check if the collector does already exist*/
131
			try{
132 3b12e61e ben.clark
				List<AgentBase> col = config.getAgentService().findByTitle(null,collName,null,null,null,null,null, null).getRecords();
133 d1b1103d p.kelbert
				collector=col.get(0);
134
			}catch (Exception e) {
135
				collector = Person.NewInstance();
136 892efc69 Andreas Kohlbecker
				collector.setTitleCache(collName, true);
137 d1b1103d p.kelbert
			}
138
			this.gatheringEvent.setCollector(collector);
139
		}
140
	}
141
142
	/*
143
	 * Create a new collector or collector's team
144
	 * @param: collectorNames: the list of names to add as collector/collectorTeam
145
	 * USED - create each time a new Collector
146
	 */
147
	public void setCollector(ArrayList<String> collectorNames){
148
		Person collector;
149
		String collName;
150
151
		if (collectorNames.size()>1){
152
			Team team = new Team();
153 d1b5d01f Andreas Müller
			for (String strCollectorName : collectorNames){
154 d1b1103d p.kelbert
				collector = Person.NewInstance();
155 d1b5d01f Andreas Müller
				collector.setTitleCache(strCollectorName, true);
156 d1b1103d p.kelbert
				team.addTeamMember(collector);
157
				this.gatheringEvent.setCollector(team);
158
			}
159 d1b5d01f Andreas Müller
		}else if (collectorNames.size() == 1) {
160 d1b1103d p.kelbert
			collName = collectorNames.get(0);
161
			collector = Person.NewInstance();
162 892efc69 Andreas Kohlbecker
			collector.setTitleCache(collName, true);
163 d1b1103d p.kelbert
			this.gatheringEvent.setCollector(collector);
164
		}
165
166
	}
167
168
169
}