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 |
4101f77a
|
p.kelbert
|
|
12 |
|
|
import java.util.ArrayList;
|
13 |
|
|
import java.util.List;
|
14 |
|
|
|
15 |
d1b5d01f
|
Andreas Müller
|
import org.apache.commons.lang.StringUtils;
|
16 |
|
|
|
17 |
f0008608
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
18 |
4101f77a
|
p.kelbert
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
19 |
|
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
20 |
|
|
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
|
21 |
|
|
|
22 |
01be5674
|
Andreas Müller
|
/**
|
23 |
|
|
* @author p.kelbert
|
24 |
d1b5d01f
|
Andreas Müller
|
* @created 20.10.2008
|
25 |
01be5674
|
Andreas Müller
|
* @version 1.0
|
26 |
|
|
*/
|
27 |
4101f77a
|
p.kelbert
|
public class UnitsGatheringArea {
|
28 |
|
|
|
29 |
|
|
private NamedArea area = NamedArea.NewInstance();
|
30 |
|
|
private ArrayList<NamedArea> areas = new ArrayList<NamedArea>();
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/*
|
34 |
|
|
* Constructor
|
35 |
|
|
* Set/create country
|
36 |
|
|
* @param isoCountry (try to used the isocode first)
|
37 |
|
|
* @param country
|
38 |
|
|
* @param app
|
39 |
|
|
*/
|
40 |
f0008608
|
Andreas Müller
|
public UnitsGatheringArea(String isoCountry, String country, IOccurrenceService occurrenceService){
|
41 |
|
|
this.setCountry(isoCountry, country, occurrenceService);
|
42 |
4101f77a
|
p.kelbert
|
}
|
43 |
|
|
|
44 |
|
|
/*
|
45 |
|
|
* Constructor
|
46 |
|
|
* Set a list of NamedAreas
|
47 |
|
|
*/
|
48 |
|
|
public UnitsGatheringArea(ArrayList<String> namedAreas){
|
49 |
|
|
this.setAreaNames(namedAreas);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
/*
|
53 |
|
|
* Return the current NamedArea
|
54 |
|
|
*/
|
55 |
|
|
public NamedArea getArea(){
|
56 |
|
|
return this.area;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/*
|
60 |
|
|
* Return the current list of NamedAreas
|
61 |
|
|
*/
|
62 |
|
|
public ArrayList<NamedArea> getAreas(){
|
63 |
|
|
return this.areas;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
/*
|
67 |
|
|
* Set the list of NamedAreas
|
68 |
|
|
* @param namedAreas
|
69 |
|
|
*/
|
70 |
|
|
public void setAreaNames(ArrayList<String> namedAreas){
|
71 |
d1b5d01f
|
Andreas Müller
|
for (String strNamedArea : namedAreas){
|
72 |
|
|
this.area.setLabel(strNamedArea);
|
73 |
4101f77a
|
p.kelbert
|
this.areas.add(this.area);
|
74 |
|
|
this.area = NamedArea.NewInstance();
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/*
|
79 |
|
|
* Set the current Country
|
80 |
|
|
* Search in the DB if the isoCode is known
|
81 |
|
|
* If not, search if the country name is in the DB
|
82 |
|
|
* If not, create a new Label with the Level Country
|
83 |
|
|
* @param iso: the country iso code
|
84 |
|
|
* @param fullName: the country's full name
|
85 |
|
|
* @param app: the CDM application controller
|
86 |
|
|
*/
|
87 |
f0008608
|
Andreas Müller
|
public void setCountry(String iso, String fullName, IOccurrenceService occurrenceService){
|
88 |
d1b5d01f
|
Andreas Müller
|
WaterbodyOrCountry country = null;
|
89 |
|
|
List<WaterbodyOrCountry> countries = new ArrayList<WaterbodyOrCountry>();
|
90 |
49a15a79
|
Andreas Müller
|
if (StringUtils.isNotBlank(iso)){
|
91 |
d1b5d01f
|
Andreas Müller
|
//TODO move to termservice
|
92 |
f0008608
|
Andreas Müller
|
country = occurrenceService.getCountryByIso(iso);
|
93 |
d1b5d01f
|
Andreas Müller
|
}
|
94 |
|
|
if (country != null){
|
95 |
4101f77a
|
p.kelbert
|
this.area.addWaterbodyOrCountry(country);
|
96 |
d1b5d01f
|
Andreas Müller
|
}else{
|
97 |
|
|
if (fullName != ""){
|
98 |
|
|
//TODO move to termservice
|
99 |
f0008608
|
Andreas Müller
|
countries = occurrenceService.getWaterbodyOrCountryByName(fullName);
|
100 |
d1b5d01f
|
Andreas Müller
|
}
|
101 |
|
|
if (countries.size() >0){
|
102 |
4101f77a
|
p.kelbert
|
this.area.addWaterbodyOrCountry(countries.get(0));
|
103 |
d1b5d01f
|
Andreas Müller
|
}else{
|
104 |
4101f77a
|
p.kelbert
|
this.area.setLabel(fullName);
|
105 |
|
|
this.area.setLevel(NamedAreaLevel.COUNTRY());
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
}
|