Revision 3af4f365
Added by Andreas Müller 8 months ago
app-import/src/main/java/eu/etaxonomy/cdm/app/common/CdmDestinations.java | ||
---|---|---|
155 | 155 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
156 | 156 |
} |
157 | 157 |
|
158 |
|
|
159 |
public static ICdmDataSource cdm_local_mysql_fdac(){ |
|
160 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
|
161 |
String cdmServer = "127.0.0.1"; |
|
162 |
String cdmDB = "fdac"; |
|
163 |
String cdmUserName = "edit"; |
|
164 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
|
165 |
} |
|
166 |
|
|
167 | 158 |
public static ICdmDataSource cdm_test_local_mysql_test(){ |
168 | 159 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
169 | 160 |
String cdmServer = "127.0.0.1"; |
... | ... | |
879 | 870 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
880 | 871 |
} |
881 | 872 |
|
882 |
public static ICdmDataSource cdm_local_piB(String database){ |
|
883 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
|
884 |
String cdmServer = "127.0.0.1"; |
|
885 |
String cdmDB = "piB_" + database; |
|
886 |
String cdmUserName = "root"; |
|
887 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
|
888 |
} |
|
889 |
|
|
890 | 873 |
public static ICdmDataSource cdm_local_proibiosphere_chenopodium() { |
891 | 874 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
892 | 875 |
String cdmServer = "localhost"; |
app-import/src/main/java/eu/etaxonomy/cdm/io/wp6/CichorieaeCommonNameExcelImport.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.io.wp6; |
|
11 |
|
|
12 |
import java.util.HashMap; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Map; |
|
15 |
import java.util.Set; |
|
16 |
import java.util.UUID; |
|
17 |
|
|
18 |
import org.apache.commons.lang.StringUtils; |
|
19 |
import org.apache.logging.log4j.LogManager; |
|
20 |
import org.apache.logging.log4j.Logger; |
|
21 |
import org.hibernate.criterion.Criterion; |
|
22 |
import org.springframework.stereotype.Component; |
|
23 |
|
|
24 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
25 |
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException; |
|
26 |
import eu.etaxonomy.cdm.io.excel.common.ExcelImportBase; |
|
27 |
import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase; |
|
28 |
import eu.etaxonomy.cdm.model.common.Language; |
|
29 |
import eu.etaxonomy.cdm.model.description.CommonTaxonName; |
|
30 |
import eu.etaxonomy.cdm.model.description.DescriptionElementSource; |
|
31 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
32 |
import eu.etaxonomy.cdm.model.location.Country; |
|
33 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
34 |
import eu.etaxonomy.cdm.model.reference.OriginalSourceType; |
|
35 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
36 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
37 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
38 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
39 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
40 |
|
|
41 |
/** |
|
42 |
* @author a.babadshanjan |
|
43 |
* @since 08.01.2009 |
|
44 |
*/ |
|
45 |
@Component |
|
46 |
public class CichorieaeCommonNameExcelImport |
|
47 |
extends ExcelImportBase<CichorieaeCommonNameImportState, CommonNameImportConfigurator, ExcelRowBase> { |
|
48 |
|
|
49 |
private static final long serialVersionUID = 747044451715401750L; |
|
50 |
private static final Logger logger = LogManager.getLogger(); |
|
51 |
|
|
52 |
protected static final String SPECIES_COLUMN = "Art"; |
|
53 |
protected static final String COMMON_NAME_COLUMN = "common name"; |
|
54 |
protected static final String REFERENCE_COLUMN = "Literaturnummer"; |
|
55 |
protected static final String DISTIRBUTION_COLUMN = "Verbreitung"; |
|
56 |
protected static final String AREA_COLUMN = "Vorschlag Bezeichnung L�nder/Regionen"; |
|
57 |
|
|
58 |
private Map<String, NamedArea> areaStore = new HashMap<>(); |
|
59 |
private Map<String, Language> languageStore = new HashMap<>(); |
|
60 |
|
|
61 |
|
|
62 |
@Override |
|
63 |
protected boolean isIgnore(CichorieaeCommonNameImportState state) { |
|
64 |
return false; |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
protected boolean doCheck(CichorieaeCommonNameImportState state) { |
|
69 |
logger.warn("DoCheck not yet implemented for CommonNameExcelImport"); |
|
70 |
return true; |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
@Override |
|
75 |
protected void analyzeRecord(Map<String, String> record, CichorieaeCommonNameImportState state) { |
|
76 |
Set<String> keys = record.keySet(); |
|
77 |
|
|
78 |
CommonNameRow row = new CommonNameRow(); |
|
79 |
state.setCommonNameRow(row); |
|
80 |
|
|
81 |
for (String originalKey: keys) { |
|
82 |
String indexedKey = CdmUtils.removeDuplicateWhitespace(originalKey.trim()).toString(); |
|
83 |
String[] split = indexedKey.split("_"); |
|
84 |
String key = split[0]; |
|
85 |
if (split.length > 1){ |
|
86 |
String indexString = split[1]; |
|
87 |
try { |
|
88 |
Integer.valueOf(indexString); |
|
89 |
} catch (NumberFormatException e) { |
|
90 |
String message = "Index must be integer"; |
|
91 |
logger.error(message); |
|
92 |
continue; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
String value = record.get(indexedKey); |
|
97 |
if (! StringUtils.isBlank(value)) { |
|
98 |
if (logger.isDebugEnabled()) { logger.debug(key + ": " + value); } |
|
99 |
value = CdmUtils.removeDuplicateWhitespace(value.trim()).toString(); |
|
100 |
}else{ |
|
101 |
continue; |
|
102 |
} |
|
103 |
|
|
104 |
|
|
105 |
if (key.equalsIgnoreCase(SPECIES_COLUMN)) { |
|
106 |
row.parseSpecies(value); |
|
107 |
|
|
108 |
} else if(key.equalsIgnoreCase(COMMON_NAME_COLUMN)) { |
|
109 |
row.setCommonNames(value); |
|
110 |
|
|
111 |
} else if(key.equalsIgnoreCase(REFERENCE_COLUMN)) { |
|
112 |
row.setReference(value); |
|
113 |
} else if(key.equalsIgnoreCase(DISTIRBUTION_COLUMN)) { |
|
114 |
//do nothing |
|
115 |
|
|
116 |
} else if(key.equalsIgnoreCase(AREA_COLUMN)) { |
|
117 |
row.setArea(value); |
|
118 |
} else { |
|
119 |
state.setUnsuccessfull(); |
|
120 |
logger.error("Unexpected column header " + key); |
|
121 |
} |
|
122 |
} |
|
123 |
return; |
|
124 |
} |
|
125 |
|
|
126 |
|
|
127 |
/** |
|
128 |
* Stores taxa records in DB |
|
129 |
*/ |
|
130 |
@Override |
|
131 |
protected void firstPass(CichorieaeCommonNameImportState state) { |
|
132 |
|
|
133 |
CommonNameRow taxonLight = state.getCommonNameRow(); |
|
134 |
//species name |
|
135 |
String speciesStr = taxonLight.getSpecies(); |
|
136 |
TaxonDescription taxonDesc = getTaxon(state, speciesStr); |
|
137 |
Reference ref = getReference(state, taxonLight); |
|
138 |
|
|
139 |
NamedArea area = getArea(state, taxonLight.getArea()); |
|
140 |
|
|
141 |
makeCommonNames(state, taxonLight.getCommonNames(), taxonDesc, ref, area, taxonLight.getNameUsedInSource()); |
|
142 |
|
|
143 |
// OLD |
|
144 |
// TaxonNameBase nameUsedInSource = getNameUsedInSource(state, taxonLight.getNameUsedInSource()); |
|
145 |
|
|
146 |
getTaxonService().save(taxonDesc.getTaxon()); |
|
147 |
return; |
|
148 |
} |
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
private Map<String, Reference> referenceStore = new HashMap<String, Reference>(); |
|
153 |
private Reference getReference(CichorieaeCommonNameImportState state, CommonNameRow taxonLight) { |
|
154 |
String reference = taxonLight.getReference(); |
|
155 |
Reference result = referenceStore.get(reference); |
|
156 |
if (result == null){ |
|
157 |
result = getCommonService().getSourcedObjectByIdInSource(Reference.class, reference, "import to Berlin Model"); |
|
158 |
if (result == null){ |
|
159 |
logger.warn("Reference not found: " + reference + " for taxon " + taxonLight.getSpecies()); |
|
160 |
// result = ReferenceFactory.newGeneric(); |
|
161 |
// result.setTitleCache(reference); |
|
162 |
}else{ |
|
163 |
referenceStore.put(reference, result); |
|
164 |
} |
|
165 |
} |
|
166 |
return result; |
|
167 |
} |
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
private NamedArea getArea(CichorieaeCommonNameImportState state, String area) { |
|
172 |
NamedArea result; |
|
173 |
List<OrderHint> orderHints = null; |
|
174 |
List<Criterion> criteria = null; |
|
175 |
result = areaStore.get(area); |
|
176 |
|
|
177 |
if (result == null){ |
|
178 |
try { |
|
179 |
result = state.getTransformer().getNamedAreaByKey(area); |
|
180 |
} catch (UndefinedTransformerMethodException e) { |
|
181 |
e.printStackTrace(); |
|
182 |
} |
|
183 |
if (result == null){ |
|
184 |
List<? extends NamedArea> candidates = getTermService().findByTitle(Country.class, area, null, criteria, null, null, orderHints, null).getRecords(); |
|
185 |
if (candidates.size() == 0){ |
|
186 |
candidates = getTermService().findByTitle(NamedArea.class, area, null, criteria, null, null, orderHints, null).getRecords(); |
|
187 |
} |
|
188 |
if (candidates.size()>0){ |
|
189 |
//TODO |
|
190 |
result = candidates.get(0); |
|
191 |
}else{ |
|
192 |
UUID uuidArea; |
|
193 |
try { |
|
194 |
uuidArea = state.getTransformer().getNamedAreaUuid(area); |
|
195 |
if (uuidArea == null){ |
|
196 |
logger.warn("Area not defined: " + area) ; |
|
197 |
} |
|
198 |
result = getNamedArea(state, uuidArea, area, area, null, null, null); |
|
199 |
} catch (UndefinedTransformerMethodException e) { |
|
200 |
e.printStackTrace(); |
|
201 |
} |
|
202 |
if (result == null){ |
|
203 |
logger.warn("Area not defined: " + area) ; |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
207 |
areaStore.put(area, result); |
|
208 |
} |
|
209 |
return result; |
|
210 |
} |
|
211 |
|
|
212 |
|
|
213 |
Map<String, TaxonDescription> taxonStore = new HashMap<String, TaxonDescription>(); |
|
214 |
|
|
215 |
private TaxonDescription getTaxon(CichorieaeCommonNameImportState state, String taxonNameStr) { |
|
216 |
TaxonDescription desc; |
|
217 |
Taxon taxon; |
|
218 |
|
|
219 |
if (taxonStore.get(taxonNameStr) != null){ |
|
220 |
desc = taxonStore.get(taxonNameStr); |
|
221 |
}else{ |
|
222 |
taxon = getTaxonService().findBestMatchingTaxon(taxonNameStr); |
|
223 |
// TaxonNameBase name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
224 |
// name.setTitleCache(taxonNameStr, true); |
|
225 |
// |
|
226 |
// result = Taxon.NewInstance(name, null); |
|
227 |
if (taxon == null){ |
|
228 |
logger.warn("Taxon not found: " + taxonNameStr); |
|
229 |
desc = null; |
|
230 |
}else{ |
|
231 |
desc = getNewDescription(state, taxon); |
|
232 |
taxonStore.put(taxonNameStr, desc); |
|
233 |
} |
|
234 |
} |
|
235 |
return desc; |
|
236 |
} |
|
237 |
|
|
238 |
private TaxonDescription getNewDescription(CichorieaeCommonNameImportState state, Taxon taxon) { |
|
239 |
Reference excelRef = state.getConfig().getSourceReference(); |
|
240 |
TaxonDescription desc = TaxonDescription.NewInstance(taxon, false); |
|
241 |
desc.setTitleCache("Common Names Excel import", true); |
|
242 |
desc.addSource(OriginalSourceType.Import, null, null, excelRef, null); |
|
243 |
return desc; |
|
244 |
} |
|
245 |
|
|
246 |
|
|
247 |
private void makeCommonNames(CichorieaeCommonNameImportState state, Map<String, List<String>> commonNamesMap, TaxonDescription description, Reference ref, NamedArea area, String nameUsedInSource) { |
|
248 |
//Common Names |
|
249 |
// TaxonDescription td = this.getTaxonDescription(mainTaxon, false, true); |
|
250 |
for (String languageKey : commonNamesMap.keySet()){ |
|
251 |
Language language = getLanguage(state, languageKey); |
|
252 |
List<String> commonNamesList = commonNamesMap.get(languageKey); |
|
253 |
for (String strCommonName : commonNamesList){ |
|
254 |
CommonTaxonName commonName = CommonTaxonName.NewInstance(strCommonName, language, area); |
|
255 |
if (ref != null || StringUtils.isNotBlank(nameUsedInSource)){ |
|
256 |
DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(ref, null); |
|
257 |
source.setOriginalInfo(nameUsedInSource); |
|
258 |
commonName.addSource(source); |
|
259 |
}else{ |
|
260 |
logger.debug("No reference defined"); |
|
261 |
} |
|
262 |
description.addElement(commonName); |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
private Language getLanguage(CichorieaeCommonNameImportState state, String languageKey) { |
|
268 |
if (languageKey.equals("*")){ |
|
269 |
return null; |
|
270 |
} |
|
271 |
Language result; |
|
272 |
languageKey = languageKey.replace(", no ISO-Code", ""); |
|
273 |
result = languageStore.get(languageKey); |
|
274 |
if (result == null){ |
|
275 |
try{ |
|
276 |
if (languageKey.length()<4){ |
|
277 |
try { |
|
278 |
result = getTermService().getLanguageByIso(languageKey); |
|
279 |
} catch (Exception e) { |
|
280 |
// TODO Auto-generated catch block |
|
281 |
e.printStackTrace(); |
|
282 |
} |
|
283 |
}else{ |
|
284 |
UUID uuid = state.getTransformer().getLanguageUuid(languageKey); |
|
285 |
result = (Language)getTermService().find(uuid); |
|
286 |
} |
|
287 |
if (result == null){ |
|
288 |
result = state.getTransformer().getLanguageByKey(languageKey); |
|
289 |
if (result == null){ |
|
290 |
UUID uuidLanguage; |
|
291 |
uuidLanguage = state.getTransformer().getLanguageUuid(languageKey); |
|
292 |
if (uuidLanguage == null){ |
|
293 |
logger.warn("Language not defined: " + languageKey) ; |
|
294 |
} |
|
295 |
result = getLanguage(state, uuidLanguage, languageKey, languageKey, null); |
|
296 |
if (result == null){ |
|
297 |
logger.warn("Language not defined: " + languageKey) ; |
|
298 |
} |
|
299 |
}else if (result.getId() == 0){ |
|
300 |
// UUID uuidLanguageVoc = UUID.fromString("45ac7043-7f5e-4f37-92f2-3874aaaef2de"); |
|
301 |
UUID uuidLanguageVoc = UUID.fromString("434cea89-9052-4567-b2db-ff77f42e9084"); |
|
302 |
TermVocabulary<Language> voc = getVocabulary(state, TermType.Language, uuidLanguageVoc, "User Defined Languages", "User Defined Languages", null, null, false, result); |
|
303 |
// TermVocabulary<Language> voc = getVocabularyService().find(uuidLanguageVoc); |
|
304 |
voc.addTerm(result); |
|
305 |
getTermService().saveOrUpdate(result); |
|
306 |
state.putLanguage(result); |
|
307 |
} |
|
308 |
} |
|
309 |
languageStore.put(languageKey, result); |
|
310 |
} catch (UndefinedTransformerMethodException e) { |
|
311 |
e.printStackTrace(); |
|
312 |
} |
|
313 |
|
|
314 |
} |
|
315 |
return result; |
|
316 |
} |
|
317 |
|
|
318 |
|
|
319 |
/** |
|
320 |
* Stores parent-child, synonym and common name relationships |
|
321 |
*/ |
|
322 |
@Override |
|
323 |
protected void secondPass(CichorieaeCommonNameImportState state) { |
|
324 |
//no second pass |
|
325 |
return; |
|
326 |
} |
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
// private TaxonNameBase getNameUsedInSource(CichorieaeCommonNameImportState state, String nameUsedInSource) { |
|
331 |
// if (StringUtils.isBlank(nameUsedInSource)){ |
|
332 |
// return null; |
|
333 |
// }else{ |
|
334 |
// Pager<TaxonNameBase> list = getNameService().findByName(BotanicalName.class, nameUsedInSource, null, null, null, null, null, null); |
|
335 |
// if (list.getCount() > 0){ |
|
336 |
// return list.getRecords().get(0); |
|
337 |
// }else{ |
|
338 |
// return null; |
|
339 |
// } |
|
340 |
// } |
|
341 |
// |
|
342 |
// } |
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/wp6/CommonNameExcelImport.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.io.wp6; |
|
11 |
|
|
12 |
import java.util.HashMap; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Map; |
|
15 |
import java.util.Set; |
|
16 |
import java.util.UUID; |
|
17 |
|
|
18 |
import org.apache.commons.lang.StringUtils; |
|
19 |
import org.apache.logging.log4j.LogManager; |
|
20 |
import org.apache.logging.log4j.Logger; |
|
21 |
import org.hibernate.criterion.Criterion; |
|
22 |
import org.springframework.stereotype.Component; |
|
23 |
|
|
24 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
25 |
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException; |
|
26 |
import eu.etaxonomy.cdm.io.excel.common.ExcelImportBase; |
|
27 |
import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase; |
|
28 |
import eu.etaxonomy.cdm.model.common.Language; |
|
29 |
import eu.etaxonomy.cdm.model.description.CommonTaxonName; |
|
30 |
import eu.etaxonomy.cdm.model.description.DescriptionElementSource; |
|
31 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
32 |
import eu.etaxonomy.cdm.model.location.Country; |
|
33 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
34 |
import eu.etaxonomy.cdm.model.reference.OriginalSourceType; |
|
35 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
36 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
37 |
import eu.etaxonomy.cdm.model.term.TermType; |
|
38 |
import eu.etaxonomy.cdm.model.term.TermVocabulary; |
|
39 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
40 |
|
|
41 |
/** |
|
42 |
* @author a.babadshanjan |
|
43 |
* @since 08.01.2009 |
|
44 |
*/ |
|
45 |
|
|
46 |
@Component |
|
47 |
public class CommonNameExcelImport |
|
48 |
extends ExcelImportBase<CichorieaeCommonNameImportState, CommonNameImportConfigurator, ExcelRowBase> { |
|
49 |
|
|
50 |
private static final long serialVersionUID = 747044451715401750L; |
|
51 |
private static final Logger logger = LogManager.getLogger(); |
|
52 |
|
|
53 |
protected static final String SPECIES_COLUMN = "Art"; |
|
54 |
protected static final String COMMON_NAME_COLUMN = "common name"; |
|
55 |
protected static final String REFERENCE_COLUMN = "Literaturnummer"; |
|
56 |
protected static final String DISTIRBUTION_COLUMN = "Verbreitung"; |
|
57 |
protected static final String AREA_COLUMN = "Vorschlag Bezeichnung L�nder/Regionen"; |
|
58 |
|
|
59 |
private Map<String, NamedArea> areaStore = new HashMap<String, NamedArea>(); |
|
60 |
private Map<String, Language> languageStore = new HashMap<String, Language>(); |
|
61 |
|
|
62 |
|
|
63 |
@Override |
|
64 |
protected boolean isIgnore(CichorieaeCommonNameImportState state) { |
|
65 |
return false; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
protected boolean doCheck(CichorieaeCommonNameImportState state) { |
|
70 |
logger.warn("DoCheck not yet implemented for CommonNameExcelImport"); |
|
71 |
return true; |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
@Override |
|
76 |
protected void analyzeRecord(Map<String, String> record, CichorieaeCommonNameImportState state) { |
|
77 |
Set<String> keys = record.keySet(); |
|
78 |
|
|
79 |
CommonNameRow row = new CommonNameRow(); |
|
80 |
state.setCommonNameRow(row); |
|
81 |
|
|
82 |
for (String originalKey: keys) { |
|
83 |
String indexedKey = CdmUtils.removeDuplicateWhitespace(originalKey.trim()).toString(); |
|
84 |
String[] split = indexedKey.split("_"); |
|
85 |
String key = split[0]; |
|
86 |
if (split.length > 1){ |
|
87 |
String indexString = split[1]; |
|
88 |
try { |
|
89 |
Integer.valueOf(indexString); |
|
90 |
} catch (NumberFormatException e) { |
|
91 |
String message = "Index must be integer"; |
|
92 |
logger.error(message); |
|
93 |
continue; |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
String value = record.get(indexedKey); |
|
98 |
if (! StringUtils.isBlank(value)) { |
|
99 |
if (logger.isDebugEnabled()) { logger.debug(key + ": " + value); } |
|
100 |
value = CdmUtils.removeDuplicateWhitespace(value.trim()).toString(); |
|
101 |
}else{ |
|
102 |
continue; |
|
103 |
} |
|
104 |
|
|
105 |
|
|
106 |
if (key.equalsIgnoreCase(SPECIES_COLUMN)) { |
|
107 |
row.parseSpecies(value); |
|
108 |
|
|
109 |
} else if(key.equalsIgnoreCase(COMMON_NAME_COLUMN)) { |
|
110 |
row.setCommonNames(value); |
|
111 |
|
|
112 |
} else if(key.equalsIgnoreCase(REFERENCE_COLUMN)) { |
|
113 |
row.setReference(value); |
|
114 |
} else if(key.equalsIgnoreCase(DISTIRBUTION_COLUMN)) { |
|
115 |
//do nothing |
|
116 |
|
|
117 |
} else if(key.equalsIgnoreCase(AREA_COLUMN)) { |
|
118 |
row.setArea(value); |
|
119 |
} else { |
|
120 |
state.setUnsuccessfull(); |
|
121 |
logger.error("Unexpected column header " + key); |
|
122 |
} |
|
123 |
} |
|
124 |
return; |
|
125 |
} |
|
126 |
|
|
127 |
|
|
128 |
/** |
|
129 |
* Stores taxa records in DB |
|
130 |
*/ |
|
131 |
@Override |
|
132 |
protected void firstPass(CichorieaeCommonNameImportState state) { |
|
133 |
|
|
134 |
CommonNameRow taxonLight = state.getCommonNameRow(); |
|
135 |
//species name |
|
136 |
String speciesStr = taxonLight.getSpecies(); |
|
137 |
TaxonDescription taxonDesc = getTaxon(state, speciesStr); |
|
138 |
Reference ref = getReference(state, taxonLight); |
|
139 |
|
|
140 |
NamedArea area = getArea(state, taxonLight.getArea()); |
|
141 |
|
|
142 |
makeCommonNames(state, taxonLight.getCommonNames(), taxonDesc, ref, area, taxonLight.getNameUsedInSource()); |
|
143 |
|
|
144 |
// OLD |
|
145 |
// TaxonNameBase nameUsedInSource = getNameUsedInSource(state, taxonLight.getNameUsedInSource()); |
|
146 |
|
|
147 |
getTaxonService().save(taxonDesc.getTaxon()); |
|
148 |
return; |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
private Map<String, Reference> referenceStore = new HashMap<String, Reference>(); |
|
154 |
private Reference getReference(CichorieaeCommonNameImportState state, CommonNameRow taxonLight) { |
|
155 |
String reference = taxonLight.getReference(); |
|
156 |
Reference result = referenceStore.get(reference); |
|
157 |
if (result == null){ |
|
158 |
result = getCommonService().getSourcedObjectByIdInSource(Reference.class, reference, "import to Berlin Model"); |
|
159 |
if (result == null){ |
|
160 |
logger.warn("Reference not found: " + reference + " for taxon " + taxonLight.getSpecies()); |
|
161 |
// result = ReferenceFactory.newGeneric(); |
|
162 |
// result.setTitleCache(reference); |
|
163 |
}else{ |
|
164 |
referenceStore.put(reference, result); |
|
165 |
} |
|
166 |
} |
|
167 |
return result; |
|
168 |
} |
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
private NamedArea getArea(CichorieaeCommonNameImportState state, String area) { |
|
173 |
NamedArea result; |
|
174 |
List<OrderHint> orderHints = null; |
|
175 |
List<Criterion> criteria = null; |
|
176 |
result = areaStore.get(area); |
|
177 |
|
|
178 |
if (result == null){ |
|
179 |
try { |
|
180 |
result = state.getTransformer().getNamedAreaByKey(area); |
|
181 |
} catch (UndefinedTransformerMethodException e) { |
|
182 |
e.printStackTrace(); |
|
183 |
} |
|
184 |
if (result == null){ |
|
185 |
List<? extends NamedArea> candidates = getTermService().findByTitle(Country.class, area, null, criteria, null, null, orderHints, null).getRecords(); |
|
186 |
if (candidates.size() == 0){ |
|
187 |
candidates = getTermService().findByTitle(NamedArea.class, area, null, criteria, null, null, orderHints, null).getRecords(); |
|
188 |
} |
|
189 |
if (candidates.size()>0){ |
|
190 |
//TODO |
|
191 |
result = candidates.get(0); |
|
192 |
}else{ |
|
193 |
UUID uuidArea; |
|
194 |
try { |
|
195 |
uuidArea = state.getTransformer().getNamedAreaUuid(area); |
|
196 |
if (uuidArea == null){ |
|
197 |
logger.warn("Area not defined: " + area) ; |
|
198 |
} |
|
199 |
result = getNamedArea(state, uuidArea, area, area, null, null, null); |
|
200 |
} catch (UndefinedTransformerMethodException e) { |
|
201 |
e.printStackTrace(); |
|
202 |
} |
|
203 |
if (result == null){ |
|
204 |
logger.warn("Area not defined: " + area) ; |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
areaStore.put(area, result); |
|
209 |
} |
|
210 |
return result; |
|
211 |
} |
|
212 |
|
|
213 |
|
|
214 |
Map<String, TaxonDescription> taxonStore = new HashMap<String, TaxonDescription>(); |
|
215 |
|
|
216 |
private TaxonDescription getTaxon(CichorieaeCommonNameImportState state, String taxonNameStr) { |
|
217 |
TaxonDescription desc; |
|
218 |
Taxon taxon; |
|
219 |
|
|
220 |
if (taxonStore.get(taxonNameStr) != null){ |
|
221 |
desc = taxonStore.get(taxonNameStr); |
|
222 |
}else{ |
|
223 |
taxon = getTaxonService().findBestMatchingTaxon(taxonNameStr); |
|
224 |
// TaxonNameBase name = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
225 |
// name.setTitleCache(taxonNameStr, true); |
|
226 |
// |
|
227 |
// result = Taxon.NewInstance(name, null); |
|
228 |
if (taxon == null){ |
|
229 |
logger.warn("Taxon not found: " + taxonNameStr); |
|
230 |
desc = null; |
|
231 |
}else{ |
|
232 |
desc = getNewDescription(state, taxon); |
|
233 |
taxonStore.put(taxonNameStr, desc); |
|
234 |
} |
|
235 |
} |
|
236 |
return desc; |
|
237 |
} |
|
238 |
|
|
239 |
private TaxonDescription getNewDescription(CichorieaeCommonNameImportState state, Taxon taxon) { |
|
240 |
Reference excelRef = state.getConfig().getSourceReference(); |
|
241 |
TaxonDescription desc = TaxonDescription.NewInstance(taxon, false); |
|
242 |
desc.setTitleCache("Common Names Excel import", true); |
|
243 |
desc.addSource(OriginalSourceType.Import, null, null, excelRef, null); |
|
244 |
return desc; |
|
245 |
} |
|
246 |
|
|
247 |
|
|
248 |
private void makeCommonNames(CichorieaeCommonNameImportState state, Map<String, List<String>> commonNamesMap, TaxonDescription description, Reference ref, NamedArea area, String nameUsedInSource) { |
|
249 |
//Common Names |
|
250 |
// TaxonDescription td = this.getTaxonDescription(mainTaxon, false, true); |
|
251 |
for (String languageKey : commonNamesMap.keySet()){ |
|
252 |
Language language = getLanguage(state, languageKey); |
|
253 |
List<String> commonNamesList = commonNamesMap.get(languageKey); |
|
254 |
for (String strCommonName : commonNamesList){ |
|
255 |
CommonTaxonName commonName = CommonTaxonName.NewInstance(strCommonName, language, area); |
|
256 |
if (ref != null || StringUtils.isNotBlank(nameUsedInSource)){ |
|
257 |
DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(ref, null); |
|
258 |
source.setOriginalInfo(nameUsedInSource); |
|
259 |
commonName.addSource(source); |
|
260 |
}else{ |
|
261 |
logger.debug("No reference defined"); |
|
262 |
} |
|
263 |
description.addElement(commonName); |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
private Language getLanguage(CichorieaeCommonNameImportState state, String languageKey) { |
|
269 |
if (languageKey.equals("*")){ |
|
270 |
return null; |
|
271 |
} |
|
272 |
Language result; |
|
273 |
languageKey = languageKey.replace(", no ISO-Code", ""); |
|
274 |
result = languageStore.get(languageKey); |
|
275 |
if (result == null){ |
|
276 |
try{ |
|
277 |
if (languageKey.length()<4){ |
|
278 |
try { |
|
279 |
result = getTermService().getLanguageByIso(languageKey); |
|
280 |
} catch (Exception e) { |
|
281 |
// TODO Auto-generated catch block |
|
282 |
e.printStackTrace(); |
|
283 |
} |
|
284 |
}else{ |
|
285 |
UUID uuid = state.getTransformer().getLanguageUuid(languageKey); |
|
286 |
result = (Language)getTermService().find(uuid); |
|
287 |
} |
|
288 |
if (result == null){ |
|
289 |
result = state.getTransformer().getLanguageByKey(languageKey); |
|
290 |
if (result == null){ |
|
291 |
UUID uuidLanguage; |
|
292 |
uuidLanguage = state.getTransformer().getLanguageUuid(languageKey); |
|
293 |
if (uuidLanguage == null){ |
|
294 |
logger.warn("Language not defined: " + languageKey) ; |
|
295 |
} |
|
296 |
result = getLanguage(state, uuidLanguage, languageKey, languageKey, null); |
|
297 |
if (result == null){ |
|
298 |
logger.warn("Language not defined: " + languageKey) ; |
|
299 |
} |
|
300 |
}else if (result.getId() == 0){ |
|
301 |
// UUID uuidLanguageVoc = UUID.fromString("45ac7043-7f5e-4f37-92f2-3874aaaef2de"); |
|
302 |
UUID uuidLanguageVoc = UUID.fromString("434cea89-9052-4567-b2db-ff77f42e9084"); |
|
303 |
TermVocabulary<Language> voc = getVocabulary(state, TermType.Language, uuidLanguageVoc, "User Defined Languages", "User Defined Languages", null, null, false, result); |
|
304 |
// TermVocabulary<Language> voc = getVocabularyService().find(uuidLanguageVoc); |
|
305 |
voc.addTerm(result); |
|
306 |
getTermService().saveOrUpdate(result); |
|
307 |
state.putLanguage(result); |
|
308 |
} |
|
309 |
} |
|
310 |
languageStore.put(languageKey, result); |
|
311 |
} catch (UndefinedTransformerMethodException e) { |
|
312 |
e.printStackTrace(); |
|
313 |
} |
|
314 |
|
|
315 |
} |
|
316 |
return result; |
|
317 |
} |
|
318 |
|
|
319 |
|
|
320 |
/** |
|
321 |
* Stores parent-child, synonym and common name relationships |
|
322 |
*/ |
|
323 |
@Override |
|
324 |
protected void secondPass(CichorieaeCommonNameImportState state) { |
|
325 |
//no second pass |
|
326 |
return; |
|
327 |
} |
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
// private TaxonNameBase getNameUsedInSource(CichorieaeCommonNameImportState state, String nameUsedInSource) { |
|
332 |
// if (StringUtils.isBlank(nameUsedInSource)){ |
|
333 |
// return null; |
|
334 |
// }else{ |
|
335 |
// Pager<TaxonNameBase> list = getNameService().findByName(BotanicalName.class, nameUsedInSource, null, null, null, null, null, null); |
|
336 |
// if (list.getCount() > 0){ |
|
337 |
// return list.getRecords().get(0); |
|
338 |
// }else{ |
|
339 |
// return null; |
|
340 |
// } |
|
341 |
// } |
|
342 |
// |
|
343 |
// } |
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/wp6/CommonNameImportConfigurator.java | ||
---|---|---|
44 | 44 |
@Override |
45 | 45 |
protected void makeIoClassList(){ |
46 | 46 |
ioClassList = new Class[]{ |
47 |
CommonNameExcelImport.class , |
|
47 |
CichorieaeCommonNameExcelImport.class ,
|
|
48 | 48 |
}; |
49 | 49 |
} |
50 | 50 |
|
... | ... | |
60 | 60 |
setDestination(destination); |
61 | 61 |
} |
62 | 62 |
|
63 |
|
|
64 |
/* (non-Javadoc) |
|
65 |
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource() |
|
66 |
*/ |
|
67 | 63 |
@Override |
68 | 64 |
public URI getSource() { |
69 | 65 |
return super.getSource(); |
Also available in: Unified diff
cleanup