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
.excel
.in
;
12 import java
.util
.HashMap
;
14 import java
.util
.UUID
;
16 import org
.apache
.commons
.lang
.StringUtils
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.springframework
.stereotype
.Component
;
20 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
21 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
22 import eu
.etaxonomy
.cdm
.io
.excel
.common
.ExcelImporterBase
;
23 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
31 public class NamedAreaLevelExcelImport
extends ExcelImporterBase
<SpecimenCdmExcelImportState
> implements ICdmIO
<SpecimenCdmExcelImportState
> {
32 private static final Logger logger
= Logger
.getLogger(NamedAreaLevelExcelImport
.class);
34 private static final String WORKSHEET_NAME
= "AreaLevels";
36 private static final String UUID_COLUMN
= "UUID";
37 private static final String LABEL_COLUMN
= "Label";
38 private static final String ABBREVIATION_COLUMN
= "Abbreviation";
39 private static final String DESCRIPTION_COLUMN
= "Description";
40 private static final String POSTFIX_COLUMN
= "Postfix";
41 private static final String GEOSERVER_LABEL_COLUMN
= "GeoserverLabel";
42 private static final String GEOSERVER_ATTRIBUTE_COLUMN
= "GeoserverAttribute";
43 private static final String ORDER_INDEX_COLUMN
= "OrderIndex";
46 public NamedAreaLevelExcelImport() {
51 protected void analyzeRecord(HashMap
<String
, String
> record
, SpecimenCdmExcelImportState state
) {
52 Set
<String
> keys
= record
.keySet();
54 NamedAreaLevellRow row
= new NamedAreaLevellRow();
55 state
.setNamedAreaLevelRow(row
);
57 for (String originalKey
: keys
) {
59 String indexedKey
= CdmUtils
.removeDuplicateWhitespace(originalKey
.trim()).toString();
60 String
[] split
= indexedKey
.split("_");
61 String key
= split
[0];
62 if (split
.length
> 1){
63 String indexString
= split
[split
.length
- 1];
65 index
= Integer
.valueOf(indexString
);
66 } catch (NumberFormatException e
) {
67 String message
= "Index must be integer";
68 logger
.error(message
);
73 String value
= (String
) record
.get(indexedKey
);
74 if (! StringUtils
.isBlank(value
)) {
75 if (logger
.isDebugEnabled()) { logger
.debug(key
+ ": " + value
); }
76 value
= CdmUtils
.removeDuplicateWhitespace(value
.trim()).toString();
81 if (key
.equalsIgnoreCase(UUID_COLUMN
)) {
82 row
.setUuid(UUID
.fromString(value
)); //VALIDATE UUID
83 } else if(key
.equalsIgnoreCase(LABEL_COLUMN
)) {
85 } else if(key
.equalsIgnoreCase(ABBREVIATION_COLUMN
)) {
86 row
.setAbbreviation(value
);
87 } else if(key
.equalsIgnoreCase(DESCRIPTION_COLUMN
)) {
88 row
.setDescription(value
);
89 } else if(key
.equalsIgnoreCase(POSTFIX_COLUMN
)) {
90 row
.setPostfix(value
);
91 } else if(key
.equalsIgnoreCase(GEOSERVER_LABEL_COLUMN
)) {
92 row
.setGeoserverLabel(value
);
93 } else if(key
.equalsIgnoreCase(GEOSERVER_ATTRIBUTE_COLUMN
)) {
94 row
.setGeoServerAttribute(value
);
95 } else if(key
.equalsIgnoreCase(ORDER_INDEX_COLUMN
)) {
96 row
.setOrderIndex(value
);
98 state
.setUnsuccessfull();
99 logger
.error("Unexpected column header " + key
);
107 protected void firstPass(SpecimenCdmExcelImportState state
) {
108 NamedAreaLevellRow row
= state
.getNamedAreaLevelRow();
111 UUID uuid
= row
.getUuid();
112 String label
= row
.getAbbreviation();
113 String text
= row
.getDescription();
114 String labelAbbrev
= row
.getAbbreviation();
116 NamedAreaLevel level
= getNamedAreaLevel(state
, uuid
, label
, text
, labelAbbrev
, null);
120 //TODO geoserverLabel
122 //TODO geoserverAttribute
124 if (StringUtils
.isNotBlank(row
.getPostfix())){
125 state
.putPostfixLevel(row
.getPostfix(), level
);
129 getTermService().save(level
);
136 protected void secondPass(SpecimenCdmExcelImportState state
) {
137 //no second path defined yet
142 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
145 protected boolean doCheck(SpecimenCdmExcelImportState state
) {
146 logger
.warn("Validation not yet implemented for " + this.getClass().getSimpleName());
150 protected String
getWorksheetName() {
151 return WORKSHEET_NAME
;
155 protected boolean needsNomenclaturalCode() {
161 protected boolean isIgnore(SpecimenCdmExcelImportState state
) {
162 return !state
.getConfig().isDoAreaLevels();