Revision aea90ab7
Added by Andreas Müller almost 7 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/FloraHellenicaImportBase.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.io.greece; |
10 | 10 |
|
11 | 11 |
import java.util.HashMap; |
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
import java.util.UUID; |
|
12 | 15 |
|
13 | 16 |
import org.apache.log4j.Logger; |
14 | 17 |
|
18 |
import eu.etaxonomy.cdm.io.common.utils.ImportDeduplicationHelper; |
|
15 | 19 |
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImport; |
16 | 20 |
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState; |
21 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
|
17 | 22 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
18 | 23 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
24 |
import eu.etaxonomy.cdm.model.name.INonViralName; |
|
19 | 25 |
import eu.etaxonomy.cdm.model.name.Rank; |
20 | 26 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory; |
21 | 27 |
import eu.etaxonomy.cdm.model.reference.Reference; |
... | ... | |
32 | 38 |
private static final long serialVersionUID = 2593130403213346396L; |
33 | 39 |
private static final Logger logger = Logger.getLogger(FloraHellenicaImportBase.class); |
34 | 40 |
|
41 |
private Map<UUID, Taxon> acceptedTaxonMap = new HashMap<>(); |
|
42 |
private Reference sourceReference; |
|
43 |
private Reference secReference; |
|
44 |
private Reference secReference2; |
|
45 |
|
|
46 |
@SuppressWarnings("unchecked") |
|
47 |
private ImportDeduplicationHelper<SimpleExcelTaxonImportState<?>> deduplicationHelper = (ImportDeduplicationHelper<SimpleExcelTaxonImportState<?>>)ImportDeduplicationHelper.NewInstance(this); |
|
48 |
|
|
49 |
|
|
35 | 50 |
|
36 | 51 |
/** |
37 | 52 |
* @param taxon |
... | ... | |
53 | 68 |
* @return |
54 | 69 |
*/ |
55 | 70 |
protected Reference getSourceCitation(SimpleExcelTaxonImportState<CONFIG> state) { |
56 |
return state.getConfig().getSourceReference(); |
|
71 |
if (this.sourceReference == null){ |
|
72 |
this.sourceReference = getPersistentReference(state.getConfig().getSourceReference()); |
|
73 |
} |
|
74 |
return this.sourceReference; |
|
57 | 75 |
} |
58 | 76 |
|
59 | 77 |
|
60 | 78 |
protected Reference getSecReference(SimpleExcelTaxonImportState<CONFIG> state) { |
61 |
// TODO Auto-generated method stub |
|
62 |
return null; |
|
79 |
if (this.secReference == null){ |
|
80 |
this.secReference = getPersistentReference(state.getConfig().getSecReference()); |
|
81 |
} |
|
82 |
return this.secReference; |
|
83 |
} |
|
84 |
|
|
85 |
protected Reference getSecReference2(SimpleExcelTaxonImportState<CONFIG> state) { |
|
86 |
if (this.secReference2 == null){ |
|
87 |
this.secReference2 = getPersistentReference(state.getConfig().getSecReference2()); |
|
88 |
} |
|
89 |
return this.secReference2; |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* @param reference |
|
94 |
* @return |
|
95 |
*/ |
|
96 |
private Reference getPersistentReference(Reference reference) { |
|
97 |
Reference result = getReferenceService().find(reference.getUuid()); |
|
98 |
if (result == null){ |
|
99 |
result = reference; |
|
100 |
} |
|
101 |
return result; |
|
63 | 102 |
} |
64 | 103 |
|
65 | 104 |
|
... | ... | |
70 | 109 |
*/ |
71 | 110 |
protected Taxon getAcceptedTaxon(HashMap<String, String> record, |
72 | 111 |
SimpleExcelTaxonImportState<CONFIG> state, String key) { |
112 |
|
|
73 | 113 |
String accStr = getValue(record, key); |
74 | 114 |
if (accStr == null){ |
75 | 115 |
return null; |
... | ... | |
82 | 122 |
logger.warn(message); |
83 | 123 |
return null; |
84 | 124 |
}else{ |
85 |
accTaxon = (Taxon)getTaxonService().find(accTaxon.getUuid()); |
|
125 |
initAcceptedTaxonMap(); |
|
126 |
// accTaxon = (Taxon)getTaxonService().find(accTaxon.getUuid()); |
|
127 |
accTaxon = acceptedTaxonMap.get(accTaxon.getUuid()); |
|
86 | 128 |
} |
87 | 129 |
return accTaxon; |
88 | 130 |
} |
89 | 131 |
|
132 |
private void initAcceptedTaxonMap() { |
|
133 |
if (acceptedTaxonMap.isEmpty()){ |
|
134 |
List<Taxon> list = getTaxonService().list(Taxon.class, null, null, null, null); |
|
135 |
for (Taxon taxon : list){ |
|
136 |
acceptedTaxonMap.put(taxon.getUuid(), taxon); |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
90 | 140 |
|
141 |
/** |
|
142 |
* @param record |
|
143 |
* @param state |
|
144 |
* @return |
|
145 |
*/ |
|
146 |
protected Taxon getHigherTaxon(HashMap<String, String> record, |
|
147 |
SimpleExcelTaxonImportState<CONFIG> state, String key) { |
|
91 | 148 |
|
92 |
protected BotanicalName makeFamilyName(SimpleExcelTaxonImportState<CONFIG> state, String famStr) { |
|
149 |
String accStr = getValue(record, key); |
|
150 |
if (accStr == null){ |
|
151 |
return null; |
|
152 |
} |
|
153 |
accStr = accStr.trim(); |
|
154 |
|
|
155 |
Taxon accTaxon = state.getHigherTaxon(accStr); |
|
156 |
if (accTaxon == null){ |
|
157 |
String message = state.getCurrentLine()+ ": Higher taxon could not be found: " + accStr; |
|
158 |
logger.info(message); //not critical |
|
159 |
return null; |
|
160 |
}else{ |
|
161 |
initAcceptedTaxonMap(); |
|
162 |
// accTaxon = (Taxon)getTaxonService().find(accTaxon.getUuid()); |
|
163 |
accTaxon = acceptedTaxonMap.get(accTaxon.getUuid()); |
|
164 |
} |
|
165 |
return accTaxon; |
|
166 |
} |
|
167 |
|
|
168 |
|
|
169 |
protected BotanicalName makeFamilyName(SimpleExcelTaxonImportState<CONFIG> state, |
|
170 |
String famStr) { |
|
93 | 171 |
BotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY()); |
172 |
famStr = famStr.substring(0,1).toUpperCase() + famStr.substring(1).toLowerCase(); |
|
94 | 173 |
name.setGenusOrUninomial(famStr); |
95 | 174 |
name.addSource(makeOriginalSource(state)); |
96 | 175 |
return name; |
97 | 176 |
} |
98 | 177 |
|
178 |
|
|
179 |
/** |
|
180 |
* @param state |
|
181 |
* @param name |
|
182 |
* @return |
|
183 |
*/ |
|
184 |
protected <NAME extends INonViralName> NAME replaceNameAuthorsAndReferences(SimpleExcelTaxonImportState<CONFIG> state, NAME name) { |
|
185 |
NAME result = deduplicationHelper.getExistingName(state, name); |
|
186 |
deduplicationHelper.replaceAuthorNamesAndNomRef(state, result); |
|
187 |
return result; |
|
188 |
} |
|
189 |
|
|
190 |
|
|
191 |
/** |
|
192 |
* @param state |
|
193 |
* @return |
|
194 |
*/ |
|
195 |
@Override |
|
196 |
protected IdentifiableSource makeOriginalSource(SimpleExcelTaxonImportState<CONFIG> state) { |
|
197 |
return IdentifiableSource.NewDataImportInstance("line: " + state.getCurrentLine(), null, getSourceCitation(state)); |
|
198 |
} |
|
199 |
|
|
99 | 200 |
} |
Also available in: Unified diff
ref #6286 updates for Flora Hellenica import (including new image import)