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 boolean analyzeRecord(HashMap
<String
, String
> record
, SpecimenCdmExcelImportState state
) {
49 boolean success
= true;
50 Set
<String
> keys
= record
.keySet();
52 NamedAreaLevellRow row
= new NamedAreaLevellRow();
53 state
.setNamedAreaLabelRow(row
);
55 for (String originalKey
: keys
) {
57 String indexedKey
= CdmUtils
.removeDuplicateWhitespace(originalKey
.trim()).toString();
58 String
[] split
= indexedKey
.split("_");
59 String key
= split
[0];
60 if (split
.length
> 1){
61 String indexString
= split
[split
.length
- 1];
63 index
= Integer
.valueOf(indexString
);
64 } catch (NumberFormatException e
) {
65 String message
= "Index must be integer";
66 logger
.error(message
);
71 String value
= (String
) record
.get(indexedKey
);
72 if (! StringUtils
.isBlank(value
)) {
73 if (logger
.isDebugEnabled()) { logger
.debug(key
+ ": " + value
); }
74 value
= CdmUtils
.removeDuplicateWhitespace(value
.trim()).toString();
79 if (key
.equalsIgnoreCase(UUID_COLUMN
)) {
80 row
.setUuid(UUID
.fromString(value
)); //VALIDATE UUID
81 } else if(key
.equalsIgnoreCase(LABEL_COLUMN
)) {
83 } else if(key
.equalsIgnoreCase(ABBREVIATION_COLUMN
)) {
84 row
.setAbbreviation(value
);
85 } else if(key
.equalsIgnoreCase(DESCRIPTION_COLUMN
)) {
86 row
.setDescription(value
);
87 } else if(key
.equalsIgnoreCase(POSTFIX_COLUMN
)) {
88 row
.setPostfix(value
);
91 logger
.error("Unexpected column header " + key
);
99 protected boolean firstPass(SpecimenCdmExcelImportState state
) {
100 NamedAreaLevellRow row
= state
.getNamedAreaLabelRow();
103 UUID uuid
= row
.getUuid();
104 String label
= row
.getAbbreviation();
105 String text
= row
.getDescription();
106 String labelAbbrev
= row
.getAbbreviation();
108 ExtensionType term
= getExtensionType(state
, uuid
, label
, text
, labelAbbrev
);
110 if (StringUtils
.isNotBlank(row
.getPostfix())){
111 state
.putPostfixExtensionType(row
.getPostfix(), term
);
115 getTermService().save(term
);
122 protected boolean secondPass(SpecimenCdmExcelImportState state
) {
123 //no second path defined yet
128 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
131 protected boolean doCheck(SpecimenCdmExcelImportState state
) {
132 logger
.warn("Validation not yet implemented for " + this.getClass().getSimpleName());
136 protected String
getWorksheetName() {
137 return WORKSHEET_NAME
;
141 protected boolean needsNomenclaturalCode() {
147 protected boolean isIgnore(SpecimenCdmExcelImportState state
) {
148 return !state
.getConfig().isDoExtensionTypes();