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
.common
.ExtensionType
;
31 public class ExtensionTypeExcelImport
extends ExcelImporterBase
<SpecimenCdmExcelImportState
> implements ICdmIO
<SpecimenCdmExcelImportState
> {
32 private static final Logger logger
= Logger
.getLogger(ExtensionTypeExcelImport
.class);
34 private static final String WORKSHEET_NAME
= "ExtensionTypes";
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";
43 public ExtensionTypeExcelImport() {
48 protected void analyzeRecord(HashMap
<String
, String
> record
, SpecimenCdmExcelImportState state
) {
49 Set
<String
> keys
= record
.keySet();
51 NamedAreaLevellRow row
= new NamedAreaLevellRow();
52 state
.setNamedAreaLevelRow(row
);
54 for (String originalKey
: keys
) {
56 String indexedKey
= CdmUtils
.removeDuplicateWhitespace(originalKey
.trim()).toString();
57 String
[] split
= indexedKey
.split("_");
58 String key
= split
[0];
59 if (split
.length
> 1){
60 String indexString
= split
[split
.length
- 1];
62 index
= Integer
.valueOf(indexString
);
63 } catch (NumberFormatException e
) {
64 String message
= "Index must be integer";
65 logger
.error(message
);
70 String value
= (String
) record
.get(indexedKey
);
71 if (! StringUtils
.isBlank(value
)) {
72 if (logger
.isDebugEnabled()) { logger
.debug(key
+ ": " + value
); }
73 value
= CdmUtils
.removeDuplicateWhitespace(value
.trim()).toString();
78 if (key
.equalsIgnoreCase(UUID_COLUMN
)) {
79 row
.setUuid(UUID
.fromString(value
)); //VALIDATE UUID
80 } else if(key
.equalsIgnoreCase(LABEL_COLUMN
)) {
82 } else if(key
.equalsIgnoreCase(ABBREVIATION_COLUMN
)) {
83 row
.setAbbreviation(value
);
84 } else if(key
.equalsIgnoreCase(DESCRIPTION_COLUMN
)) {
85 row
.setDescription(value
);
86 } else if(key
.equalsIgnoreCase(POSTFIX_COLUMN
)) {
87 row
.setPostfix(value
);
89 state
.setUnsuccessfull();
90 logger
.error("Unexpected column header " + key
);
98 protected void firstPass(SpecimenCdmExcelImportState state
) {
99 NamedAreaLevellRow row
= state
.getNamedAreaLevelRow();
102 UUID uuid
= row
.getUuid();
103 String label
= row
.getAbbreviation();
104 String text
= row
.getDescription();
105 String labelAbbrev
= row
.getAbbreviation();
107 ExtensionType term
= getExtensionType(state
, uuid
, label
, text
, labelAbbrev
);
109 if (StringUtils
.isNotBlank(row
.getPostfix())){
110 state
.putPostfixExtensionType(row
.getPostfix(), term
);
114 getTermService().save(term
);
121 protected void secondPass(SpecimenCdmExcelImportState state
) {
122 //no second path defined yet
127 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
130 protected boolean doCheck(SpecimenCdmExcelImportState state
) {
131 logger
.warn("Validation not yet implemented for " + this.getClass().getSimpleName());
135 protected String
getWorksheetName() {
136 return WORKSHEET_NAME
;
140 protected boolean needsNomenclaturalCode() {
146 protected boolean isIgnore(SpecimenCdmExcelImportState state
) {
147 return !state
.getConfig().isDoExtensionTypes();