1
|
package eu.etaxonomy.cdm.io.synthesys;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.List;
|
5
|
|
6
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
7
|
import eu.etaxonomy.cdm.model.common.Language;
|
8
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
9
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
10
|
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
|
11
|
|
12
|
public class UnitsGatheringArea {
|
13
|
|
14
|
private NamedArea area = NamedArea.NewInstance();
|
15
|
private ArrayList<NamedArea> areas = new ArrayList<NamedArea>();
|
16
|
|
17
|
|
18
|
/*
|
19
|
* Constructor
|
20
|
* Set/create country
|
21
|
* @param isoCountry (try to used the isocode first)
|
22
|
* @param country
|
23
|
* @param app
|
24
|
*/
|
25
|
public UnitsGatheringArea(String isoCountry, String country, CdmApplicationController app){
|
26
|
this.setCountry(isoCountry, country, app);
|
27
|
}
|
28
|
|
29
|
/*
|
30
|
* Constructor
|
31
|
* Set a list of NamedAreas
|
32
|
*/
|
33
|
public UnitsGatheringArea(ArrayList<String> namedAreas){
|
34
|
this.setAreaNames(namedAreas);
|
35
|
}
|
36
|
|
37
|
/*
|
38
|
* Return the current NamedArea
|
39
|
*/
|
40
|
public NamedArea getArea(){
|
41
|
return this.area;
|
42
|
}
|
43
|
|
44
|
/*
|
45
|
* Return the current list of NamedAreas
|
46
|
*/
|
47
|
public ArrayList<NamedArea> getAreas(){
|
48
|
return this.areas;
|
49
|
}
|
50
|
|
51
|
/*
|
52
|
* Set the list of NamedAreas
|
53
|
* @param namedAreas
|
54
|
*/
|
55
|
public void setAreaNames(ArrayList<String> namedAreas){
|
56
|
for (int i=0; i< namedAreas.size(); i++){
|
57
|
this.area.setLabel(namedAreas.get(i));
|
58
|
this.areas.add(this.area);
|
59
|
this.area = NamedArea.NewInstance();
|
60
|
}
|
61
|
}
|
62
|
|
63
|
/*
|
64
|
* Set the current Country
|
65
|
* Search in the DB if the isoCode is known
|
66
|
* If not, search if the country name is in the DB
|
67
|
* If not, create a new Label with the Level Country
|
68
|
* @param iso: the country iso code
|
69
|
* @param fullName: the country's full name
|
70
|
* @param app: the CDM application controller
|
71
|
*/
|
72
|
public void setCountry(String iso, String fullName, CdmApplicationController app){
|
73
|
WaterbodyOrCountry country=null;
|
74
|
List<WaterbodyOrCountry>countries;
|
75
|
if (iso != null)
|
76
|
country = app.getOccurrenceService().getCountryByIso(iso);
|
77
|
if (country != null)
|
78
|
this.area.addWaterbodyOrCountry(country);
|
79
|
|
80
|
else{
|
81
|
countries = app.getOccurrenceService().getWaterbodyOrCountryByName(fullName);
|
82
|
if (countries.size() >0)
|
83
|
this.area.addWaterbodyOrCountry(countries.get(0));
|
84
|
else{
|
85
|
this.area.setLabel(fullName);
|
86
|
this.area.setLevel(NamedAreaLevel.COUNTRY());
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
|
91
|
// public void setAreaName(String areaName, String langIso, CdmApplicationController app){
|
92
|
// Language language = app.getTermService().getLanguageByIso(langIso);
|
93
|
// this.area.setLabel(areaName, language);
|
94
|
// }
|
95
|
|
96
|
}
|