Project

General

Profile

Download (2.77 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
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
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.service.IOccurrenceService;
18
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
/**
23
 * @author p.kelbert
24
 * @created 20.10.2008
25
 * @version 1.0
26
 */
27
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
	public UnitsGatheringArea(String isoCountry, String country, IOccurrenceService occurrenceService){
41
		this.setCountry(isoCountry, country, occurrenceService);
42
	}
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
		for (String strNamedArea : namedAreas){
72
			this.area.setLabel(strNamedArea);
73
			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
	public void setCountry(String iso, String fullName, IOccurrenceService occurrenceService){
88
		WaterbodyOrCountry country = null;
89
		List<WaterbodyOrCountry> countries = new ArrayList<WaterbodyOrCountry>();
90
		if (StringUtils.isNotBlank(iso)){
91
			//TODO move to termservice
92
			country = occurrenceService.getCountryByIso(iso);
93
		}
94
		if (country != null){
95
			this.area.addWaterbodyOrCountry(country);
96
		}else{
97
			if (fullName != ""){
98
				//TODO move to termservice
99
				countries = occurrenceService.getWaterbodyOrCountryByName(fullName);
100
			}
101
			if (countries.size() >0){
102
				this.area.addWaterbodyOrCountry(countries.get(0));
103
			}else{
104
				this.area.setLabel(fullName);
105
				this.area.setLevel(NamedAreaLevel.COUNTRY()); 
106
			}
107
		}
108
	}
109
	
110
}
(2-2/3)