Project

General

Profile

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

    
3
import java.util.ArrayList;
4
import java.util.List;
5

    
6
import eu.etaxonomy.cdm.model.location.NamedArea;
7
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
8
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
9

    
10
public class UnitsGatheringArea {
11

    
12
	private NamedArea area = NamedArea.NewInstance();
13
	private ArrayList<NamedArea> areas = new ArrayList<NamedArea>();
14

    
15

    
16
	/*
17
	 * Constructor
18
	 * Set/create country
19
	 * @param isoCountry (try to used the isocode first)
20
	 * @param country
21
	 * @param app
22
	 */
23
	public UnitsGatheringArea(String isoCountry, String country, SpecimenImportConfigurator config){
24
		this.setCountry(isoCountry, country, config);
25
	}
26
	
27
	/*
28
	 * Constructor
29
	 * Set a list of NamedAreas
30
	 */
31
	public UnitsGatheringArea(ArrayList<String> namedAreas){
32
		this.setAreaNames(namedAreas);
33
	}
34

    
35
	/*
36
	 * Return the current NamedArea
37
	 */
38
	public NamedArea getArea(){
39
		return this.area;
40
	}
41
	
42
	/*
43
	 * Return the current list of NamedAreas
44
	 */
45
	public ArrayList<NamedArea> getAreas(){
46
		return this.areas;
47
	}
48
	
49
	/*
50
	 * Set the list of NamedAreas
51
	 * @param namedAreas
52
	 */
53
	public void setAreaNames(ArrayList<String> namedAreas){
54
		for (int i=0; i< namedAreas.size(); i++){
55
			this.area.setLabel(namedAreas.get(i));
56
			this.areas.add(this.area);
57
			this.area = NamedArea.NewInstance();
58
		}
59
	}
60
	
61
	/*
62
	 * Set the current Country
63
	 * Search in the DB if the isoCode is known
64
	 * If not, search if the country name is in the DB
65
	 * If not, create a new Label with the Level Country
66
	 * @param iso: the country iso code
67
	 * @param fullName: the country's full name
68
	 * @param app: the CDM application controller
69
	 */
70
	public void setCountry(String iso, String fullName, SpecimenImportConfigurator config){
71
		WaterbodyOrCountry country=null;
72
		List<WaterbodyOrCountry>countries = new ArrayList<WaterbodyOrCountry>();
73
		if (iso != null && iso !="")
74
			country = config.getCdmAppController().getOccurrenceService().getCountryByIso(iso);
75
		if (country != null)
76
			this.area.addWaterbodyOrCountry(country);
77

    
78
		else{
79
			if (fullName != "")
80
			countries = config.getCdmAppController().getOccurrenceService().getWaterbodyOrCountryByName(fullName);
81
			if (countries.size() >0)
82
				this.area.addWaterbodyOrCountry(countries.get(0));
83
			else{
84
				this.area.setLabel(fullName);
85
				this.area.setLevel(NamedAreaLevel.COUNTRY()); 
86
			}
87
		}
88
	}
89
	
90
}
(4-4/5)