2 * Copyright (C) 2009 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
.excel
.common
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashMap
;
14 import java
.util
.List
;
17 import java
.util
.TreeMap
;
18 import java
.util
.UUID
;
20 import org
.apache
.log4j
.Logger
;
22 import eu
.etaxonomy
.cdm
.io
.excel
.common
.ExcelTaxonOrSpecimenImportBase
.SourceType
;
23 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
24 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
25 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
30 * Base class for data holder classes for excel or similar imports.
35 public abstract class ExcelRowBase
{
36 @SuppressWarnings("unused")
37 private static final Logger logger
= Logger
.getLogger(ExcelRowBase
.class);
39 private UUID cdmUuid
= null;
41 private String ecology
;
42 private String plantDescription
;
45 // private String family;
46 // private String genus;
47 // private String specificEpithet;
50 private TreeMap
<Integer
, IdentifiableSource
> sources
= new TreeMap
<Integer
, IdentifiableSource
>();
51 private TreeMap
<Integer
, SpecimenTypeDesignation
> types
= new TreeMap
<Integer
, SpecimenTypeDesignation
>();
52 private List
<PostfixTerm
> extensions
= new ArrayList
<PostfixTerm
>();
55 private Map
<UUID
, TreeMap
<Integer
, String
>> featureTexts
= new HashMap
<UUID
, TreeMap
<Integer
, String
>>();
56 private Map
<UUID
, TreeMap
<Integer
, String
>> featureLanguages
= new HashMap
<UUID
, TreeMap
<Integer
, String
>>();
58 private Map
<UUID
, TreeMap
<Integer
, SourceDataHolder
>> textSources
= new HashMap
<UUID
, TreeMap
<Integer
, SourceDataHolder
>>();
61 public ExcelRowBase() {
64 public class PostfixTerm
{
65 public PostfixTerm(){}
67 public String postfix
;
71 public class SourceDataHolder
{
72 private TreeMap
<Integer
, Map
<SourceType
, String
>> sources
= new TreeMap
<Integer
, Map
<SourceType
, String
>>();
74 public void putSource(int index
, SourceType type
, String value
){
75 Map
<SourceType
, String
> map
= sources
.get(index
);
77 map
= new HashMap
<SourceType
, String
>();
78 sources
.put(index
, map
);
83 public List
<Map
<SourceType
, String
>> getSources() {
84 return getOrdered(sources
);
90 // **************************** GETTER / SETTER *********************************/
93 public void setCdmUuid(UUID cdmUuid
) {
94 this.cdmUuid
= cdmUuid
;
98 public UUID
getCdmUuid() {
104 // * @return the author
106 // public String getAuthor() {
112 // * @param author the author to set
114 // public void setAuthor(String author) {
115 // this.author = author;
121 * @return the ecology
123 public String
getEcology() {
129 * @param ecology the ecology to set
131 public void setEcology(String ecology
) {
132 this.ecology
= ecology
;
137 * @return the plantDescription
139 public String
getPlantDescription() {
140 return plantDescription
;
145 * @param plantDescription the plantDescription to set
147 public void setPlantDescription(String plantDescription
) {
148 this.plantDescription
= plantDescription
;
151 public void putIdInSource(int key
, String id
){
152 IdentifiableSource source
= getOrMakeSource(key
);
153 source
.setIdInSource(id
);
155 public void putSourceReference(int key
, Reference
<?
> reference
){
156 IdentifiableSource source
= getOrMakeSource(key
);
157 source
.setCitation(reference
);
160 public List
<IdentifiableSource
> getSources() {
161 return getOrdered(sources
);
169 private IdentifiableSource
getOrMakeSource(int key
) {
170 IdentifiableSource source
= sources
.get(key
);
172 source
= IdentifiableSource
.NewInstance();
173 sources
.put(key
, source
);
179 public void putTypeCategory(int key
, SpecimenTypeDesignationStatus status
){
180 SpecimenTypeDesignation designation
= getOrMakeTypeDesignation(key
);
181 designation
.setTypeStatus(status
);
183 public void putTypifiedName(int key
, TaxonNameBase
<?
,?
> name
){
185 SpecimenTypeDesignation designation
= getOrMakeTypeDesignation(key
);
186 name
.addTypeDesignation(designation
, false);
190 public List
<SpecimenTypeDesignation
> getTypeDesignations() {
191 return getOrdered(types
);
195 private SpecimenTypeDesignation
getOrMakeTypeDesignation(int key
) {
196 SpecimenTypeDesignation designation
= types
.get(key
);
197 if (designation
== null){
198 designation
= SpecimenTypeDesignation
.NewInstance();
199 types
.put(key
, designation
);
204 private<T
extends Object
> List
<T
> getOrdered(TreeMap
<?
, T
> tree
) {
205 List
<T
> result
= new ArrayList
<T
>();
206 for (T value
: tree
.values()){
212 public void addExtension(String levelPostfix
, String value
) {
213 PostfixTerm term
= new PostfixTerm();
215 term
.postfix
= levelPostfix
;
216 this.extensions
.add(term
);
219 public List
<PostfixTerm
> getExtensions(){
223 //***************** FEATURES ***************************************************/
225 public void putFeature(UUID featureUuid
, int index
, String value
) {
226 TreeMap
<Integer
, String
> featureMap
= featureTexts
.get(featureUuid
);
227 if (featureMap
== null){
228 featureMap
= new TreeMap
<Integer
, String
>();
229 featureTexts
.put(featureUuid
, featureMap
);
231 featureMap
.put(index
, value
);
234 public void putFeatureLanguage(UUID featureUuid
, int index
, String value
) {
235 TreeMap
<Integer
, String
> featureLanguageMap
= featureLanguages
.get(featureUuid
);
236 if (featureLanguageMap
== null){
237 featureLanguageMap
= new TreeMap
<Integer
, String
>();
238 featureLanguages
.put(featureUuid
, featureLanguageMap
);
240 featureLanguageMap
.put(index
, value
);
243 public Set
<UUID
> getFeatures() {
244 return featureTexts
.keySet();
247 public List
<String
> getFeatureTexts(UUID featureUuid
) {
248 TreeMap
<Integer
, String
> map
= featureTexts
.get(featureUuid
);
250 return getOrdered(map
);
256 public List
<String
> getFeatureLanguages(UUID featureUuid
) {
257 TreeMap
<Integer
, String
> map
= featureLanguages
.get(featureUuid
);
259 return getOrdered(map
);
266 public void putFeatureSource(UUID featureUuid
, int featureIndex
, SourceType refType
, String value
, int refIndex
) {
268 TreeMap
<Integer
, SourceDataHolder
> featureMap
= textSources
.get(featureUuid
);
269 if (featureMap
== null){
270 featureMap
= new TreeMap
<Integer
, SourceDataHolder
>();
271 textSources
.put(featureUuid
, featureMap
);
274 SourceDataHolder sourceDataHolder
= featureMap
.get(featureIndex
);
275 if (sourceDataHolder
== null){
276 sourceDataHolder
= new SourceDataHolder();
277 featureMap
.put(featureIndex
, sourceDataHolder
);
280 sourceDataHolder
.putSource(refIndex
, refType
, value
);
284 public SourceDataHolder
getFeatureTextReferences(UUID featureUuid
, int index
) {
285 TreeMap
<Integer
, SourceDataHolder
> textMap
= textSources
.get(featureUuid
);
286 if (textMap
== null){
287 return new SourceDataHolder();
289 SourceDataHolder sourceMap
= textMap
.get(index
);