Project

General

Profile

Download (3.73 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.io.unitsPortal;
2

    
3

    
4
import java.util.ArrayList;
5
import java.util.List;
6
import java.util.ListIterator;
7

    
8
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
9
import eu.etaxonomy.cdm.model.agent.Agent;
10
import eu.etaxonomy.cdm.model.agent.Person;
11
import eu.etaxonomy.cdm.model.agent.Team;
12
import eu.etaxonomy.cdm.model.common.Language;
13
import eu.etaxonomy.cdm.model.common.LanguageString;
14
import eu.etaxonomy.cdm.model.common.LanguageStringBase;
15
import eu.etaxonomy.cdm.model.location.NamedArea;
16
import eu.etaxonomy.cdm.model.location.Point;
17
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
18

    
19
public class UnitsGatheringEvent {
20

    
21
	private GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
22
	CdmApplicationController app;
23

    
24
	public UnitsGatheringEvent(CdmApplicationController app, String locality, String languageIso, Double longitude, Double latitude, ArrayList<String> collectorNames){
25
		//this.setLocality(locality, languageIso);//TODO
26
		this.setCoordinates(longitude, latitude);
27
		this.setCollector(collectorNames);
28
		this.app = app;
29
	}
30

    
31
	public GatheringEvent getGatheringEvent(){
32
		return this.gatheringEvent;
33
	}
34
//	protected GatheringEvent MyGatheringEvent(){
35
//		//create gathering event
36
//		gatheringEvent = GatheringEvent.NewInstance();
37
//		return gatheringEvent;
38
//	}
39
//
40
//	private GatheringEvent getInstance(){
41
//		if (gatheringEvent == null)
42
//			gatheringEvent = MyGatheringEvent();
43
//		return gatheringEvent;
44
//	}
45

    
46
	public void setLocality(String locality, String languageIso){
47
		System.out.println(locality);
48
		LanguageStringBase loc;
49
		if (languageIso == null)
50
			loc = LanguageString.NewInstance(locality,Language.DEFAULT());
51
		else
52
			loc = LanguageString.NewInstance(locality,this.app.getTermService().getLanguageByIso(languageIso));
53
		this.gatheringEvent.setLocality(loc);
54
	}
55
	
56
	public LanguageStringBase getLocality(){
57
		return this.gatheringEvent.getLocality();
58
	}
59

    
60
	public void setCoordinates(Double longitude, Double latitude){
61
		//create coordinates point
62
		Point coordinates = Point.NewInstance();
63
		//add coordinates
64
		coordinates.setLongitude(longitude);
65
		coordinates.setLatitude(latitude);
66
		this.gatheringEvent.setExactLocation(coordinates);
67
	}
68

    
69
	public void setElevation(Integer elevation){
70
		this.gatheringEvent.setAbsoluteElevation(elevation);
71
	}
72

    
73
	/**/
74

    
75
	public void addArea(NamedArea area){
76
		this.gatheringEvent.addCollectingArea(area);
77
	}
78

    
79
	/*
80
	 * If the collector already exists, then use it
81
	 * if not, create a new collector
82
	 */
83
	public void setCollector(ArrayList<String> collectorNames,boolean getExisting){
84
		//create collector
85
		Agent collector;
86
		ListIterator<String> collectors = collectorNames.listIterator();
87
		//add the collectors
88
		String collName;
89
		while (collectors.hasNext()){
90
			collName = collectors.next();
91
			/*check if the collector does already exist*/
92
			try{
93
				List<Agent> col = this.app.getAgentService().findAgentsByTitle(collName);
94
				collector=col.get(0);
95
			}catch (Exception e) {
96
				collector = Person.NewInstance();
97
				collector.setTitleCache(collName);
98
			}
99
			this.gatheringEvent.setCollector(collector);
100
		}
101
	}
102

    
103
	/*
104
	 * Create a new collector or collector's team
105
	 */
106
	public void setCollector(ArrayList<String> collectorNames){
107
		Person collector;
108
		String collName;
109

    
110
		if (collectorNames.size()>1){
111
			Team team = new Team();
112
			for (int i=0;i<collectorNames.size();i++){
113
				collName = collectorNames.get(i);
114
				collector = Person.NewInstance();
115
				collector.setTitleCache(collName);
116
				team.addTeamMember(collector);
117
				this.gatheringEvent.setCollector(team);
118
			}
119
		}
120
		else if (collectorNames.size() == 1) {
121
			collName = collectorNames.get(0);
122
			collector = Person.NewInstance();
123
			collector.setTitleCache(collName);
124
			this.gatheringEvent.setCollector(collector);
125
		}
126

    
127
	}
128

    
129

    
130
}
(5-5/5)