1
|
/**
|
2
|
* Copyright (C) 2017 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
|
package eu.etaxonomy.cdm.io.greece;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.springframework.stereotype.Component;
|
15
|
|
16
|
import eu.etaxonomy.cdm.io.common.utils.ImportDeduplicationHelper;
|
17
|
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImport;
|
18
|
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
|
19
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
20
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
21
|
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
|
22
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
23
|
|
24
|
/**
|
25
|
* @author a.mueller
|
26
|
* @since 08.12.2017
|
27
|
*
|
28
|
*/
|
29
|
@Component
|
30
|
public class GreeceGenusAuthorImport
|
31
|
extends SimpleExcelTaxonImport<GreeceGenusAuthorImportConfigurator>{
|
32
|
|
33
|
private static final Logger logger = Logger.getLogger(GreeceGenusAuthorImport.class);
|
34
|
|
35
|
private static final long serialVersionUID = 1173327042682886814L;
|
36
|
private ImportDeduplicationHelper<SimpleExcelTaxonImportState> dedupHelper;
|
37
|
private NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
|
38
|
|
39
|
|
40
|
/**
|
41
|
* {@inheritDoc}
|
42
|
*/
|
43
|
@Override
|
44
|
protected void firstPass(SimpleExcelTaxonImportState<GreeceGenusAuthorImportConfigurator> state) {
|
45
|
String genus = state.getOriginalRecord().get("Genus");
|
46
|
String author = state.getOriginalRecord().get("Author");
|
47
|
List<TaxonName> existingNames = getNameService().findNamesByNameCache(genus, MatchMode.EXACT, null);
|
48
|
if (existingNames.size() != 1){
|
49
|
logger.warn("Name '"+genus+"' has not exactly one record, but " + existingNames.size());
|
50
|
}else{
|
51
|
TaxonName name = existingNames.iterator().next();
|
52
|
// TaxonName name = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS()) ;
|
53
|
// name.setGenusOrUninomial("Genus");
|
54
|
try {
|
55
|
parser.parseAuthors(name, author);
|
56
|
getDedupHelper(state).replaceAuthorNamesAndNomRef(state, name);
|
57
|
name.addImportSource(null, null, state.getConfig().getSourceReference(), String.valueOf(state.getCurrentLine()));
|
58
|
} catch (StringNotParsableException e) {
|
59
|
// TODO Auto-generated catch block
|
60
|
e.printStackTrace();
|
61
|
// throw new RuntimeException(e);
|
62
|
}
|
63
|
}
|
64
|
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* @param state
|
69
|
* @return
|
70
|
*/
|
71
|
private ImportDeduplicationHelper<SimpleExcelTaxonImportState> getDedupHelper(SimpleExcelTaxonImportState<GreeceGenusAuthorImportConfigurator> state) {
|
72
|
if (this.dedupHelper == null){
|
73
|
dedupHelper = ImportDeduplicationHelper.NewInstance(this, state);
|
74
|
}
|
75
|
return this.dedupHelper;
|
76
|
}
|
77
|
|
78
|
}
|