1
|
/**
|
2
|
* Copyright (C) 2020 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.caryo;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Map;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.apache.logging.log4j.LogManager;
|
16
|
import org.apache.logging.log4j.Logger;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
|
19
|
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
|
20
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
21
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
23
|
import eu.etaxonomy.cdm.model.taxon.SynonymType;
|
24
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
25
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
26
|
|
27
|
/**
|
28
|
* @author a.mueller
|
29
|
* @since 02.02.2023
|
30
|
*/
|
31
|
@Component
|
32
|
public class CaryoSileneaeSynonymImport extends CaryoSileneaeImportBase {
|
33
|
|
34
|
private static final long serialVersionUID = 7967768097472488888L;
|
35
|
private static final Logger logger = LogManager.getLogger();
|
36
|
|
37
|
private static final String NOMTAX_ID = "NomTax_ID";
|
38
|
private static final String NOMEN_LINK = "Nomen_link";
|
39
|
private static final String TAXON_LINK = "Taxon_link";
|
40
|
|
41
|
private Set<String> neglectedRecords = new HashSet<>();
|
42
|
|
43
|
private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
|
44
|
|
45
|
@Override
|
46
|
protected void firstPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
|
47
|
int line = state.getCurrentLine();
|
48
|
if ((line % 500) == 0){
|
49
|
newTransaction(state);
|
50
|
System.out.println(line);
|
51
|
}
|
52
|
|
53
|
this.state = state;
|
54
|
Map<String, String> record = state.getOriginalRecord();
|
55
|
|
56
|
Integer nomTaxId = Integer.valueOf(getValue(record, NOMTAX_ID));
|
57
|
Integer nameLinkID = Integer.valueOf(getValue(record, NOMEN_LINK));
|
58
|
Integer taxonLinkId = Integer.valueOf(getValue(record, TAXON_LINK));
|
59
|
|
60
|
|
61
|
String row = String.valueOf(line) + "("+nomTaxId+"): ";
|
62
|
|
63
|
TaxonName name = getName(state, nameLinkID);
|
64
|
|
65
|
if (name == null) {
|
66
|
logger.warn(row + "Name does not exist");
|
67
|
return;
|
68
|
}
|
69
|
|
70
|
Synonym synonym = Synonym.NewInstance(name, getSecRef(state));
|
71
|
|
72
|
Taxon taxon = getTaxon(state, taxonLinkId);
|
73
|
if (taxon == null) {
|
74
|
logger.warn(row + "Taxon does not exist");
|
75
|
return;
|
76
|
}
|
77
|
//TODO type (compute homotypics)
|
78
|
taxon.addSynonym(synonym, SynonymType.SYNONYM_OF);
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
protected void secondPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
|
83
|
}
|
84
|
|
85
|
private boolean hasSameAcceptedTaxon(TaxonBase<?> taxonBase, TaxonBase<?> basionymTaxon) {
|
86
|
if (taxonBase.isInstanceOf(Synonym.class)){
|
87
|
taxonBase = CdmBase.deproxy(taxonBase, Synonym.class).getAcceptedTaxon();
|
88
|
}
|
89
|
if (basionymTaxon.isInstanceOf(Synonym.class)){
|
90
|
basionymTaxon = CdmBase.deproxy(basionymTaxon, Synonym.class).getAcceptedTaxon();
|
91
|
}
|
92
|
return taxonBase != null && basionymTaxon != null && taxonBase.equals(basionymTaxon);
|
93
|
}
|
94
|
}
|