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
;
30 public class NamedAreaLevelExcelImport
extends ExcelImporterBase
<SpecimenCdmExcelImportState
> implements ICdmIO
<SpecimenCdmExcelImportState
> {
31 private static final Logger logger
= Logger
.getLogger(NamedAreaLevelExcelImport
.class);
33 private static final String WORKSHEET_NAME
= "AreaLevels";
35 private static final String UUID_COLUMN
= "UUID";
36 private static final String LABEL_COLUMN
= "Label";
37 private static final String ABBREVIATION_COLUMN
= "Abbreviation";
38 private static final String DESCRIPTION_COLUMN
= "Description";
39 private static final String POSTFIX_COLUMN
= "Postfix";
40 private static final String GEOSERVER_LABEL_COLUMN
= "GeoserverLabel";
41 private static final String GEOSERVER_ATTRIBUTE_COLUMN
= "GeoserverAttribute";
42 private static final String ORDER_INDEX_COLUMN
= "OrderIndex";
45 public NamedAreaLevelExcelImport() {
50 protected void analyzeRecord(HashMap
<String
, String
> record
, SpecimenCdmExcelImportState state
) {
51 Set
<String
> keys
= record
.keySet();
53 NamedAreaLevellRow row
= new NamedAreaLevellRow();
54 state
.setNamedAreaLevelRow(row
);
56 for (String originalKey
: keys
) {
58 String indexedKey
= CdmUtils
.removeDuplicateWhitespace(originalKey
.trim()).toString();
59 String
[] split
= indexedKey
.split("_");
60 String key
= split
[0];
61 if (split
.length
> 1){
62 String indexString
= split
[split
.length
- 1];
64 index
= Integer
.valueOf(indexString
);
65 } catch (NumberFormatException e
) {
66 String message
= "Index must be integer";
67 logger
.error(message
);
72 String value
= (String
) record
.get(indexedKey
);
73 if (! StringUtils
.isBlank(value
)) {
74 if (logger
.isDebugEnabled()) { logger
.debug(key
+ ": " + value
); }
75 value
= CdmUtils
.removeDuplicateWhitespace(value
.trim()).toString();
80 if (key
.equalsIgnoreCase(UUID_COLUMN
)) {
81 row
.setUuid(UUID
.fromString(value
)); //VALIDATE UUID
82 } else if(key
.equalsIgnoreCase(LABEL_COLUMN
)) {
84 } else if(key
.equalsIgnoreCase(ABBREVIATION_COLUMN
)) {
85 row
.setAbbreviation(value
);
86 } else if(key
.equalsIgnoreCase(DESCRIPTION_COLUMN
)) {
87 row
.setDescription(value
);
88 } else if(key
.equalsIgnoreCase(POSTFIX_COLUMN
)) {
89 row
.setPostfix(value
);
90 } else if(key
.equalsIgnoreCase(GEOSERVER_LABEL_COLUMN
)) {
91 row
.setGeoserverLabel(value
);
92 } else if(key
.equalsIgnoreCase(GEOSERVER_ATTRIBUTE_COLUMN
)) {
93 row
.setGeoServerAttribute(value
);
94 } else if(key
.equalsIgnoreCase(ORDER_INDEX_COLUMN
)) {
95 row
.setOrderIndex(value
);
97 state
.setUnsuccessfull();
98 logger
.error("Unexpected column header " + key
);
106 protected void firstPass(SpecimenCdmExcelImportState state
) {
107 NamedAreaLevellRow row
= state
.getNamedAreaLevelRow();
110 UUID uuid
= row
.getUuid();
111 String label
= row
.getAbbreviation();
112 String text
= row
.getDescription();
113 String labelAbbrev
= row
.getAbbreviation();
115 NamedAreaLevel level
= getNamedAreaLevel(state
, uuid
, label
, text
, labelAbbrev
, null);
119 //TODO geoserverLabel
121 //TODO geoserverAttribute
123 if (StringUtils
.isNotBlank(row
.getPostfix())){
124 state
.putPostfixLevel(row
.getPostfix(), level
);
128 getTermService().save(level
);
135 protected void secondPass(SpecimenCdmExcelImportState state
) {
136 //no second path defined yet
141 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
144 protected boolean doCheck(SpecimenCdmExcelImportState state
) {
145 logger
.warn("Validation not yet implemented for " + this.getClass().getSimpleName());
149 protected String
getWorksheetName() {
150 return WORKSHEET_NAME
;
154 protected boolean needsNomenclaturalCode() {
160 protected boolean isIgnore(SpecimenCdmExcelImportState state
) {
161 return !state
.getConfig().isDoAreaLevels();