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
;
30 public class ExtensionTypeExcelImport
extends ExcelImporterBase
<SpecimenCdmExcelImportState
> implements ICdmIO
<SpecimenCdmExcelImportState
> {
31 private static final Logger logger
= Logger
.getLogger(ExtensionTypeExcelImport
.class);
33 private static final String WORKSHEET_NAME
= "ExtensionTypes";
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";
42 public ExtensionTypeExcelImport() {
47 protected void analyzeRecord(HashMap
<String
, String
> record
, SpecimenCdmExcelImportState state
) {
48 Set
<String
> keys
= record
.keySet();
50 NamedAreaLevellRow row
= new NamedAreaLevellRow();
51 state
.setNamedAreaLevelRow(row
);
53 for (String originalKey
: keys
) {
55 String indexedKey
= CdmUtils
.removeDuplicateWhitespace(originalKey
.trim()).toString();
56 String
[] split
= indexedKey
.split("_");
57 String key
= split
[0];
58 if (split
.length
> 1){
59 String indexString
= split
[split
.length
- 1];
61 index
= Integer
.valueOf(indexString
);
62 } catch (NumberFormatException e
) {
63 String message
= "Index must be integer";
64 logger
.error(message
);
69 String value
= (String
) record
.get(indexedKey
);
70 if (! StringUtils
.isBlank(value
)) {
71 if (logger
.isDebugEnabled()) { logger
.debug(key
+ ": " + value
); }
72 value
= CdmUtils
.removeDuplicateWhitespace(value
.trim()).toString();
77 if (key
.equalsIgnoreCase(UUID_COLUMN
)) {
78 row
.setUuid(UUID
.fromString(value
)); //VALIDATE UUID
79 } else if(key
.equalsIgnoreCase(LABEL_COLUMN
)) {
81 } else if(key
.equalsIgnoreCase(ABBREVIATION_COLUMN
)) {
82 row
.setAbbreviation(value
);
83 } else if(key
.equalsIgnoreCase(DESCRIPTION_COLUMN
)) {
84 row
.setDescription(value
);
85 } else if(key
.equalsIgnoreCase(POSTFIX_COLUMN
)) {
86 row
.setPostfix(value
);
88 state
.setUnsuccessfull();
89 logger
.error("Unexpected column header " + key
);
97 protected void firstPass(SpecimenCdmExcelImportState state
) {
98 NamedAreaLevellRow row
= state
.getNamedAreaLevelRow();
101 UUID uuid
= row
.getUuid();
102 String label
= row
.getAbbreviation();
103 String text
= row
.getDescription();
104 String labelAbbrev
= row
.getAbbreviation();
106 ExtensionType term
= getExtensionType(state
, uuid
, label
, text
, labelAbbrev
);
108 if (StringUtils
.isNotBlank(row
.getPostfix())){
109 state
.putPostfixExtensionType(row
.getPostfix(), term
);
113 getTermService().save(term
);
120 protected void secondPass(SpecimenCdmExcelImportState state
) {
121 //no second path defined yet
126 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
129 protected boolean doCheck(SpecimenCdmExcelImportState state
) {
130 logger
.warn("Validation not yet implemented for " + this.getClass().getSimpleName());
134 protected String
getWorksheetName() {
135 return WORKSHEET_NAME
;
139 protected boolean needsNomenclaturalCode() {
145 protected boolean isIgnore(SpecimenCdmExcelImportState state
) {
146 return !state
.getConfig().isDoExtensionTypes();