2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.specimen
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import org
.apache
.commons
.lang
.StringUtils
;
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
;
28 public class UnitsGatheringArea
{
30 private NamedArea area
= NamedArea
.NewInstance();
31 private ArrayList
<NamedArea
> areas
= new ArrayList
<NamedArea
>();
37 * @param isoCountry (try to used the isocode first)
41 public UnitsGatheringArea(String isoCountry
, String country
, IOccurrenceService occurrenceService
){
42 this.setCountry(isoCountry
, country
, occurrenceService
);
47 * Set a list of NamedAreas
49 public UnitsGatheringArea(ArrayList
<String
> namedAreas
){
50 this.setAreaNames(namedAreas
);
54 * Return the current NamedArea
56 public NamedArea
getArea(){
61 * Return the current list of NamedAreas
63 public ArrayList
<NamedArea
> getAreas(){
68 * Set the list of NamedAreas
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();
80 * Set the current Country
81 * Search in the DB if the isoCode is known
82 * If not, search if the country name is in the DB
83 * If not, create a new Label with the Level Country
84 * @param iso: the country iso code
85 * @param fullName: the country's full name
86 * @param app: the CDM application controller
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 //TODO move to termservice
93 country
= occurrenceService
.getCountryByIso(iso
);
96 this.area
.addWaterbodyOrCountry(country
);
99 //TODO move to termservice
100 countries
= occurrenceService
.getWaterbodyOrCountryByName(fullName
);
102 if (countries
.size() >0){
103 this.area
.addWaterbodyOrCountry(countries
.get(0));
105 this.area
.setLabel(fullName
);
106 this.area
.setLevel(NamedAreaLevel
.COUNTRY());