1
2
3
4
5
6
7
8
9
10 package eu.etaxonomy.cdm.io.specimen;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.apache.commons.lang.StringUtils;
16
17 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
18 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
19 import eu.etaxonomy.cdm.model.location.NamedArea;
20 import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
21 import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
22
23
24
25
26
27
28 public class UnitsGatheringArea {
29
30 private NamedArea area = NamedArea.NewInstance();
31 private ArrayList<NamedArea> areas = new ArrayList<NamedArea>();
32
33
34
35
36
37
38
39
40
41 public UnitsGatheringArea(String isoCountry, String country, IOccurrenceService occurrenceService){
42 this.setCountry(isoCountry, country, occurrenceService);
43 }
44
45
46
47
48
49 public UnitsGatheringArea(ArrayList<String> namedAreas){
50 this.setAreaNames(namedAreas);
51 }
52
53
54
55
56 public NamedArea getArea(){
57 return this.area;
58 }
59
60
61
62
63 public ArrayList<NamedArea> getAreas(){
64 return this.areas;
65 }
66
67
68
69
70
71 public void setAreaNames(ArrayList<String> namedAreas){
72 for (String strNamedArea : namedAreas){
73 this.area.setLabel(strNamedArea);
74 this.areas.add(this.area);
75 this.area = NamedArea.NewInstance();
76 }
77 }
78
79
80
81
82
83
84
85
86
87
88 public void setCountry(String iso, String fullName, IOccurrenceService occurrenceService){
89 WaterbodyOrCountry country = null;
90 List<WaterbodyOrCountry> countries = new ArrayList<WaterbodyOrCountry>();
91 if (StringUtils.isBlank(iso)){
92
93 country = occurrenceService.getCountryByIso(iso);
94 }
95 if (country != null){
96 this.area.addWaterbodyOrCountry(country);
97 }else{
98 if (fullName != ""){
99
100 countries = occurrenceService.getWaterbodyOrCountryByName(fullName);
101 }
102 if (countries.size() >0){
103 this.area.addWaterbodyOrCountry(countries.get(0));
104 }else{
105 this.area.setLabel(fullName);
106 this.area.setLevel(NamedAreaLevel.COUNTRY());
107 }
108 }
109 }
110
111 }