Revision aea90ab7
Added by Andreas Müller almost 7 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/FloraHellenicaExcludedTaxonImport.java | ||
---|---|---|
15 | 15 |
|
16 | 16 |
import org.apache.log4j.Logger; |
17 | 17 |
import org.springframework.stereotype.Component; |
18 |
import org.springframework.transaction.TransactionStatus; |
|
19 | 18 |
|
20 | 19 |
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState; |
21 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
|
20 |
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
|
22 | 21 |
import eu.etaxonomy.cdm.model.name.INonViralName; |
23 | 22 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
24 | 23 |
import eu.etaxonomy.cdm.model.name.Rank; |
... | ... | |
61 | 60 |
return "excluded taxa"; |
62 | 61 |
} |
63 | 62 |
|
64 |
private boolean isFirst = true; |
|
65 |
private TransactionStatus tx = null; |
|
66 | 63 |
/** |
67 | 64 |
* {@inheritDoc} |
68 | 65 |
*/ |
69 | 66 |
@Override |
70 | 67 |
protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) { |
71 |
if (isFirst){ |
|
72 |
tx = this.startTransaction(); |
|
73 |
isFirst = false; |
|
74 |
} |
|
75 | 68 |
|
76 | 69 |
String line = state.getCurrentLine() + ": "; |
77 | 70 |
HashMap<String, String> record = state.getOriginalRecord(); |
... | ... | |
90 | 83 |
} |
91 | 84 |
} |
92 | 85 |
|
93 |
@Override |
|
94 |
protected void secondPass(SimpleExcelTaxonImportState<CONFIG> state) { |
|
95 |
if (tx != null){ |
|
96 |
this.commitTransaction(tx); |
|
97 |
tx = null; |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 | 86 |
|
102 | 87 |
/** |
103 | 88 |
* @param state |
... | ... | |
110 | 95 |
HashMap<String, String> record, |
111 | 96 |
String noStr) { |
112 | 97 |
|
113 |
TaxonNode familyTaxon = getFamilyTaxon(record, state); |
|
114 |
if (familyTaxon == null){ |
|
98 |
TaxonNode familyTaxonNode = getFamilyTaxon(record, state); |
|
99 |
familyTaxonNode = getTaxonNodeService().find(familyTaxonNode.getUuid()); |
|
100 |
if (familyTaxonNode == null){ |
|
115 | 101 |
logger.warn(line + "Family not created, can't add excluded taxon: " + record.get(FAMILY)); |
116 | 102 |
return null; |
117 | 103 |
} |
118 | 104 |
|
119 | 105 |
String taxonStr = getValue(record, TAXON); |
120 | 106 |
INonViralName name = parser.parseFullName(taxonStr, NomenclaturalCode.ICNAFP, null); |
107 |
name = replaceNameAuthorsAndReferences(state, name); |
|
121 | 108 |
if (name.isProtectedTitleCache()){ |
122 | 109 |
logger.warn(line + "Name could not be parsed: " + taxonStr); |
123 | 110 |
} |
124 | 111 |
|
125 | 112 |
Taxon taxon = Taxon.NewInstance(name, getSecReference(state)); |
126 | 113 |
taxon.addImportSource(noStr, getWorksheetName(), getSourceCitation(state), null); |
127 |
TaxonNode excludedNode = familyTaxon.addChildTaxon(taxon, getSecReference(state), null); |
|
114 |
TaxonNode excludedNode = familyTaxonNode.addChildTaxon(taxon, getSecReference(state), null);
|
|
128 | 115 |
excludedNode.setExcluded(true); |
129 | 116 |
getTaxonNodeService().saveOrUpdate(excludedNode); |
130 | 117 |
return excludedNode; |
131 | 118 |
} |
132 | 119 |
|
133 | 120 |
|
121 |
|
|
134 | 122 |
/** |
135 | 123 |
* @param record |
136 | 124 |
* @param state |
... | ... | |
145 | 133 |
} |
146 | 134 |
familyStr = familyStr.trim(); |
147 | 135 |
|
148 |
Taxon family = state.getHigherTaxon(familyStr); |
|
136 |
// Taxon family = state.getHigherTaxon(familyStr); |
|
137 |
Taxon family = this.getHigherTaxon(record, state, FAMILY); |
|
149 | 138 |
TaxonNode familyNode; |
150 | 139 |
if (family != null){ |
151 | 140 |
familyNode = family.getTaxonNodes().iterator().next(); |
152 | 141 |
}else{ |
153 |
BotanicalName name = makeFamilyName(state, familyStr); |
|
142 |
IBotanicalName name = makeFamilyName(state, familyStr); |
|
143 |
name = replaceNameAuthorsAndReferences(state, name); |
|
144 |
|
|
154 | 145 |
Reference sec = getSecReference(state); |
155 | 146 |
family = Taxon.NewInstance(name, sec); |
156 | 147 |
|
Also available in: Unified diff
ref #6286 updates for Flora Hellenica import (including new image import)