1 |
b463135c
|
Patrick Plitzner
|
/**
|
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.redlist.gefaesspflanzen;
|
11 |
|
|
|
12 |
|
|
import java.sql.ResultSet;
|
13 |
|
|
import java.sql.SQLException;
|
14 |
|
|
import java.util.HashMap;
|
15 |
|
|
import java.util.HashSet;
|
16 |
|
|
import java.util.Map;
|
17 |
|
|
import java.util.Set;
|
18 |
|
|
|
19 |
|
|
import org.apache.log4j.Logger;
|
20 |
|
|
import org.springframework.stereotype.Component;
|
21 |
|
|
|
22 |
c1641f79
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
23 |
74525264
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
24 |
b463135c
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.io.common.DbImportBase;
|
25 |
|
|
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
|
26 |
|
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
27 |
|
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
28 |
|
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
29 |
94adeb1d
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
30 |
7319c528
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
31 |
b463135c
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32 |
fac4774f
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.common.Language;
|
33 |
|
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
34 |
|
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
35 |
b463135c
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
36 |
ac9742df
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
37 |
|
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
38 |
74525264
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
39 |
b463135c
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.name.Rank;
|
40 |
|
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
41 |
76dce350
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
42 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
43 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
44 |
0873eb1c
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
45 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
46 |
74525264
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
47 |
b463135c
|
Patrick Plitzner
|
|
48 |
|
|
/**
|
49 |
c5216774
|
Patrick Plitzner
|
*
|
50 |
|
|
* @author pplitzner
|
51 |
|
|
* @date Mar 1, 2016
|
52 |
|
|
*
|
53 |
b463135c
|
Patrick Plitzner
|
*/
|
54 |
|
|
|
55 |
|
|
@Component
|
56 |
|
|
@SuppressWarnings("serial")
|
57 |
|
|
public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
|
58 |
32be2fc4
|
Patrick Plitzner
|
|
59 |
b463135c
|
Patrick Plitzner
|
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportNames.class);
|
60 |
|
|
|
61 |
|
|
private static final String tableName = "Rote Liste Gefäßpflanzen";
|
62 |
|
|
|
63 |
|
|
private static final String pluralString = "names";
|
64 |
|
|
|
65 |
|
|
public RedListGefaesspflanzenImportNames() {
|
66 |
|
|
super(tableName, pluralString);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
@Override
|
70 |
|
|
protected String getIdQuery(RedListGefaesspflanzenImportState state) {
|
71 |
|
|
return "SELECT NAMNR "
|
72 |
|
|
+ "FROM V_TAXATLAS_D20_EXPORT t "
|
73 |
|
|
+ " ORDER BY NAMNR";
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
@Override
|
77 |
|
|
protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
|
78 |
|
|
String result = " SELECT * "
|
79 |
|
|
+ " FROM V_TAXATLAS_D20_EXPORT t "
|
80 |
|
|
+ " WHERE t.NAMNR IN (@IDSET)";
|
81 |
|
|
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
|
82 |
|
|
return result;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
@Override
|
86 |
|
|
protected void doInvoke(RedListGefaesspflanzenImportState state) {
|
87 |
|
|
super.doInvoke(state);
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
@Override
|
92 |
|
|
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
|
93 |
|
|
ResultSet rs = partitioner.getResultSet();
|
94 |
b3b2515e
|
Patrick Plitzner
|
Set<TaxonNameBase<?,?>> namesToSave = new HashSet<TaxonNameBase<?,?>>();
|
95 |
|
|
Set<TaxonBase<?>> taxaToSave = new HashSet<TaxonBase<?>>();
|
96 |
b463135c
|
Patrick Plitzner
|
try {
|
97 |
|
|
while (rs.next()){
|
98 |
76dce350
|
Patrick Plitzner
|
makeSingleNameAndTaxon(state, rs, namesToSave, taxaToSave);
|
99 |
b463135c
|
Patrick Plitzner
|
|
100 |
|
|
}
|
101 |
|
|
} catch (SQLException e) {
|
102 |
|
|
e.printStackTrace();
|
103 |
|
|
}
|
104 |
|
|
|
105 |
b3b2515e
|
Patrick Plitzner
|
getNameService().saveOrUpdate((TaxonNameBase) namesToSave);
|
106 |
|
|
getTaxonService().saveOrUpdate((TaxonBase) taxaToSave);
|
107 |
b463135c
|
Patrick Plitzner
|
return true;
|
108 |
|
|
}
|
109 |
|
|
|
110 |
b3b2515e
|
Patrick Plitzner
|
private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase<?,?>> namesToSave, Set<TaxonBase<?>> taxaToSave)
|
111 |
b463135c
|
Patrick Plitzner
|
throws SQLException {
|
112 |
4fe9a46d
|
Patrick Plitzner
|
long id = rs.getLong(RedListUtil.NAMNR);
|
113 |
bac828e0
|
Patrick Plitzner
|
String clTaxonString = rs.getString(RedListUtil.CL_TAXON);
|
114 |
|
|
String relationE = rs.getString(RedListUtil.E);
|
115 |
|
|
String relationW = rs.getString(RedListUtil.W);
|
116 |
|
|
String relationK = rs.getString(RedListUtil.K);
|
117 |
|
|
String relationAW = rs.getString(RedListUtil.AW);
|
118 |
|
|
String relationAO = rs.getString(RedListUtil.AO);
|
119 |
|
|
String relationR = rs.getString(RedListUtil.R);
|
120 |
|
|
String relationO = rs.getString(RedListUtil.O);
|
121 |
|
|
String relationS = rs.getString(RedListUtil.S);
|
122 |
b463135c
|
Patrick Plitzner
|
|
123 |
ac9742df
|
Patrick Plitzner
|
//---NAME---
|
124 |
b3b2515e
|
Patrick Plitzner
|
NonViralName<?> name = importName(state, rs, namesToSave);
|
125 |
c1641f79
|
Patrick Plitzner
|
|
126 |
b463135c
|
Patrick Plitzner
|
|
127 |
f3f4d328
|
Patrick Plitzner
|
//--- AUTHORS ---
|
128 |
b3b2515e
|
Patrick Plitzner
|
importAuthors(state, rs, name);
|
129 |
f3f4d328
|
Patrick Plitzner
|
|
130 |
|
|
//---TAXON---
|
131 |
b3b2515e
|
Patrick Plitzner
|
TaxonBase<?> taxonBase = importTaxon(rs, name);
|
132 |
f3f4d328
|
Patrick Plitzner
|
if(taxonBase==null){
|
133 |
|
|
RedListUtil.logMessage(id, "Taxon for name "+name+" could not be created.", logger);
|
134 |
|
|
return;
|
135 |
a47deff3
|
Patrick Plitzner
|
}
|
136 |
64879c3f
|
Patrick Plitzner
|
taxonBase.setSec(state.getConfig().getSourceReference());
|
137 |
f3f4d328
|
Patrick Plitzner
|
|
138 |
bac828e0
|
Patrick Plitzner
|
//---CONCEPT RELATIONSHIPS---
|
139 |
|
|
/*check if taxon/synonym also exists in other classification
|
140 |
|
|
* 1. create new taxon with the same name (in that classification)
|
141 |
|
|
* 2. create concept relationship between both
|
142 |
f3f4d328
|
Patrick Plitzner
|
*/
|
143 |
bac828e0
|
Patrick Plitzner
|
//checklist
|
144 |
f3f4d328
|
Patrick Plitzner
|
if(CdmUtils.isNotBlank(clTaxonString) && !clTaxonString.trim().equals("-")){
|
145 |
4ae09d10
|
Patrick Plitzner
|
cloneTaxon(taxonBase, name, TaxonRelationshipType.CONGRUENT_TO(), taxaToSave, id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE, false, true, state);
|
146 |
a47deff3
|
Patrick Plitzner
|
}
|
147 |
bac828e0
|
Patrick Plitzner
|
//E, W, K, AW, AO, R, O, S
|
148 |
|
|
addConceptRelation(relationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxonBase, name, taxaToSave, id, state);
|
149 |
|
|
addConceptRelation(relationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxonBase, name, taxaToSave, id, state);
|
150 |
|
|
addConceptRelation(relationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxonBase, name, taxaToSave, id, state);
|
151 |
|
|
addConceptRelation(relationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxonBase, name, taxaToSave, id, state);
|
152 |
|
|
addConceptRelation(relationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxonBase, name, taxaToSave, id, state);
|
153 |
|
|
addConceptRelation(relationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxonBase, name, taxaToSave, id, state);
|
154 |
|
|
addConceptRelation(relationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxonBase, name, taxaToSave, id, state);
|
155 |
|
|
addConceptRelation(relationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxonBase, name, taxaToSave, id, state);
|
156 |
f3f4d328
|
Patrick Plitzner
|
|
157 |
|
|
//NOTE: the source has to be added after cloning or otherwise the clone would also get the source
|
158 |
|
|
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE);
|
159 |
|
|
taxaToSave.add(taxonBase);
|
160 |
|
|
}
|
161 |
|
|
|
162 |
b3b2515e
|
Patrick Plitzner
|
private void addConceptRelation(String relationString, String classificationNamespace, TaxonBase<?> taxonBase, TaxonNameBase<?,?> name, Set<TaxonBase<?>> taxaToSave, long id, RedListGefaesspflanzenImportState state){
|
163 |
bac828e0
|
Patrick Plitzner
|
if(CdmUtils.isNotBlank(relationString) && !relationString.equals(".")){
|
164 |
4ae09d10
|
Patrick Plitzner
|
String substring = relationString.substring(relationString.length()-1, relationString.length());
|
165 |
|
|
TaxonRelationshipType taxonRelationshipTypeByKey = new RedListGefaesspflanzenTransformer().getTaxonRelationshipTypeByKey(substring);
|
166 |
bac828e0
|
Patrick Plitzner
|
if(taxonRelationshipTypeByKey==null){
|
167 |
4ae09d10
|
Patrick Plitzner
|
RedListUtil.logMessage(id, "Could not interpret relationship "+relationString+" for taxon "+taxonBase.generateTitle(), logger);
|
168 |
|
|
}
|
169 |
|
|
//there is no type "included in" so we have to reverse the direction
|
170 |
|
|
if(substring.equals("<")){
|
171 |
|
|
cloneTaxon(taxonBase, name, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, true, false, state);
|
172 |
|
|
}
|
173 |
|
|
else{
|
174 |
|
|
cloneTaxon(taxonBase, name, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, false, false, state);
|
175 |
bac828e0
|
Patrick Plitzner
|
}
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
|
179 |
a9cb0bc8
|
Patrick Plitzner
|
/**
|
180 |
|
|
* <b>NOTE:</b> the {@link TaxonRelationshipType} passed as parameter is
|
181 |
4ae09d10
|
Patrick Plitzner
|
* directed <b>from the clone</b> to the taxon.<br>
|
182 |
|
|
* This can be changed with parameter <i>reverseRelation</i>
|
183 |
a9cb0bc8
|
Patrick Plitzner
|
*/
|
184 |
b3b2515e
|
Patrick Plitzner
|
private void cloneTaxon(TaxonBase<?> taxonBase, TaxonNameBase<?, ?> name, TaxonRelationshipType relationFromCloneToTaxon, Set<TaxonBase<?>> taxaToSave, long id, String sourceNameSpace, boolean reverseRelation, boolean doubtful, RedListGefaesspflanzenImportState state){
|
185 |
|
|
TaxonBase<?> clone = (TaxonBase<?>) taxonBase.clone();
|
186 |
4ae09d10
|
Patrick Plitzner
|
clone.setName(name);
|
187 |
|
|
if(taxonBase.isInstanceOf(Taxon.class)){
|
188 |
|
|
TaxonRelationship taxonRelation;
|
189 |
|
|
if(reverseRelation){
|
190 |
|
|
taxonRelation = ((Taxon) taxonBase).addTaxonRelation((Taxon) clone, relationFromCloneToTaxon, null, null);
|
191 |
a47deff3
|
Patrick Plitzner
|
}
|
192 |
4ae09d10
|
Patrick Plitzner
|
else {
|
193 |
|
|
taxonRelation = ((Taxon) clone).addTaxonRelation((Taxon) taxonBase, relationFromCloneToTaxon, null, null);
|
194 |
|
|
}
|
195 |
|
|
taxonRelation.setDoubtful(doubtful);
|
196 |
|
|
}
|
197 |
|
|
ImportHelper.setOriginalSource(clone, state.getTransactionalSourceReference(), id, sourceNameSpace);
|
198 |
|
|
taxaToSave.add(clone);
|
199 |
f3f4d328
|
Patrick Plitzner
|
}
|
200 |
|
|
|
201 |
b3b2515e
|
Patrick Plitzner
|
private TaxonBase<?> importTaxon(ResultSet rs, NonViralName<?> name) throws SQLException {
|
202 |
|
|
|
203 |
|
|
long id = rs.getLong(RedListUtil.NAMNR);
|
204 |
|
|
String taxNameString = rs.getString(RedListUtil.TAXNAME);
|
205 |
|
|
String gueltString = rs.getString(RedListUtil.GUELT);
|
206 |
|
|
String trivialString = rs.getString(RedListUtil.TRIVIAL);
|
207 |
|
|
String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
|
208 |
|
|
String hybString = rs.getString(RedListUtil.HYB);
|
209 |
|
|
|
210 |
|
|
TaxonBase<?> taxonBase = null;
|
211 |
f3f4d328
|
Patrick Plitzner
|
if(authorBasiString.trim().contains(RedListUtil.AUCT)){
|
212 |
|
|
taxonBase = Taxon.NewInstance(name, null);
|
213 |
|
|
taxonBase.setAppendedPhrase(RedListUtil.AUCT);
|
214 |
c1641f79
|
Patrick Plitzner
|
}
|
215 |
f3f4d328
|
Patrick Plitzner
|
else if(gueltString.equals(RedListUtil.GUELT_ACCEPTED_TAXON)){
|
216 |
|
|
taxonBase = Taxon.NewInstance(name, null);
|
217 |
ac9742df
|
Patrick Plitzner
|
}
|
218 |
f3f4d328
|
Patrick Plitzner
|
else if(gueltString.equals(RedListUtil.GUELT_SYNONYM) || gueltString.equals(RedListUtil.GUELT_BASIONYM)){
|
219 |
|
|
taxonBase = Synonym.NewInstance(name, null);
|
220 |
8f6337ac
|
Patrick Plitzner
|
}
|
221 |
f3f4d328
|
Patrick Plitzner
|
else{
|
222 |
|
|
return null;
|
223 |
8f6337ac
|
Patrick Plitzner
|
}
|
224 |
ac9742df
|
Patrick Plitzner
|
|
225 |
fac4774f
|
Patrick Plitzner
|
//common name
|
226 |
|
|
if(taxonBase.isInstanceOf(Taxon.class) && trivialString!=null){
|
227 |
|
|
Taxon taxon = HibernateProxyHelper.deproxy(taxonBase, Taxon.class);
|
228 |
|
|
TaxonDescription description = TaxonDescription.NewInstance(taxon);
|
229 |
|
|
description.addElement(CommonTaxonName.NewInstance(trivialString, Language.getDefaultLanguage()));
|
230 |
|
|
}
|
231 |
|
|
|
232 |
f3f4d328
|
Patrick Plitzner
|
//check taxon name consistency
|
233 |
|
|
checkTaxonNameConsistency(id, taxNameString, hybString, taxonBase);
|
234 |
|
|
return taxonBase;
|
235 |
|
|
}
|
236 |
b463135c
|
Patrick Plitzner
|
|
237 |
b3b2515e
|
Patrick Plitzner
|
private void importAuthors(RedListGefaesspflanzenImportState state, ResultSet rs, NonViralName<?> name) throws SQLException {
|
238 |
|
|
|
239 |
|
|
long id = rs.getLong(RedListUtil.NAMNR);
|
240 |
|
|
String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
|
241 |
|
|
String taxZusatzString = rs.getString(RedListUtil.TAX_ZUSATZ);
|
242 |
|
|
String zusatzString = rs.getString(RedListUtil.ZUSATZ);
|
243 |
|
|
String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
|
244 |
|
|
String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
|
245 |
|
|
|
246 |
b4b7ae12
|
Patrick Plitzner
|
//combination author
|
247 |
4fe9a46d
|
Patrick Plitzner
|
if(authorKombString.contains(RedListUtil.EX)){
|
248 |
b4b7ae12
|
Patrick Plitzner
|
//TODO: what happens with multiple ex authors??
|
249 |
4fe9a46d
|
Patrick Plitzner
|
String[] kombSplit = authorKombString.split(RedListUtil.EX);
|
250 |
32be2fc4
|
Patrick Plitzner
|
if(kombSplit.length!=2){
|
251 |
f7d29c7f
|
Patrick Plitzner
|
RedListUtil.logMessage(id, "Multiple ex combination authors found", logger);
|
252 |
32be2fc4
|
Patrick Plitzner
|
}
|
253 |
b4b7ae12
|
Patrick Plitzner
|
for (int i = 0; i < kombSplit.length; i++) {
|
254 |
|
|
if(i==0){
|
255 |
|
|
//first author is ex author
|
256 |
b3b2515e
|
Patrick Plitzner
|
TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
|
257 |
b4b7ae12
|
Patrick Plitzner
|
name.setExCombinationAuthorship(authorKomb);
|
258 |
|
|
}
|
259 |
|
|
else{
|
260 |
b3b2515e
|
Patrick Plitzner
|
TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
|
261 |
b4b7ae12
|
Patrick Plitzner
|
name.setCombinationAuthorship(authorKomb);
|
262 |
|
|
}
|
263 |
|
|
}
|
264 |
|
|
}
|
265 |
7ab729a4
|
Patrick Plitzner
|
else if(authorKombString.trim().contains(RedListUtil.AUCT)){
|
266 |
4fe9a46d
|
Patrick Plitzner
|
RedListUtil.logMessage(id, "AUCT information in "+RedListUtil.AUTOR_KOMB+" column", logger);
|
267 |
94adeb1d
|
Patrick Plitzner
|
}
|
268 |
27d23ab7
|
Patrick Plitzner
|
else if(CdmUtils.isNotBlank(authorKombString)){
|
269 |
b3b2515e
|
Patrick Plitzner
|
TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorKombString);
|
270 |
b4b7ae12
|
Patrick Plitzner
|
name.setCombinationAuthorship(authorKomb);
|
271 |
|
|
}
|
272 |
|
|
//basionym author
|
273 |
4fe9a46d
|
Patrick Plitzner
|
if(authorBasiString.contains(RedListUtil.EX)){
|
274 |
|
|
String[] basiSplit = authorBasiString.split(RedListUtil.EX);
|
275 |
b4b7ae12
|
Patrick Plitzner
|
for (int i = 0; i < basiSplit.length; i++) {
|
276 |
32be2fc4
|
Patrick Plitzner
|
if(basiSplit.length!=2){
|
277 |
f7d29c7f
|
Patrick Plitzner
|
RedListUtil.logMessage(id, "Multiple ex basionymn authors found", logger);
|
278 |
32be2fc4
|
Patrick Plitzner
|
}
|
279 |
b4b7ae12
|
Patrick Plitzner
|
if(i==0){
|
280 |
b3b2515e
|
Patrick Plitzner
|
TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
|
281 |
89603ae0
|
Patrick Plitzner
|
if(CdmUtils.isBlank(authorKombString)){
|
282 |
|
|
name.setExCombinationAuthorship(authorBasi);
|
283 |
|
|
}
|
284 |
|
|
else{
|
285 |
|
|
name.setExBasionymAuthorship(authorBasi);
|
286 |
|
|
}
|
287 |
b4b7ae12
|
Patrick Plitzner
|
}
|
288 |
|
|
else{
|
289 |
b3b2515e
|
Patrick Plitzner
|
TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
|
290 |
89603ae0
|
Patrick Plitzner
|
if(CdmUtils.isBlank(authorKombString)){
|
291 |
|
|
name.setCombinationAuthorship(authorBasi);
|
292 |
|
|
}
|
293 |
|
|
else{
|
294 |
|
|
name.setBasionymAuthorship(authorBasi);
|
295 |
|
|
}
|
296 |
b4b7ae12
|
Patrick Plitzner
|
}
|
297 |
|
|
}
|
298 |
|
|
}
|
299 |
27d23ab7
|
Patrick Plitzner
|
else if(CdmUtils.isNotBlank(authorBasiString)){
|
300 |
32be2fc4
|
Patrick Plitzner
|
//this seems to be a convention in the source database: When there is only a single author then only the "AUTOR_BASI" column is used
|
301 |
b3b2515e
|
Patrick Plitzner
|
TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorBasiString);
|
302 |
32be2fc4
|
Patrick Plitzner
|
if(CdmUtils.isBlank(authorKombString)){
|
303 |
|
|
name.setCombinationAuthorship(authorBasi);
|
304 |
|
|
}
|
305 |
|
|
else{
|
306 |
|
|
name.setBasionymAuthorship(authorBasi);
|
307 |
|
|
}
|
308 |
b4b7ae12
|
Patrick Plitzner
|
}
|
309 |
9d0d3e98
|
Patrick Plitzner
|
|
310 |
|
|
//check authorship consistency
|
311 |
4fe9a46d
|
Patrick Plitzner
|
String authorString = rs.getString(RedListUtil.AUTOR);
|
312 |
b4b7ae12
|
Patrick Plitzner
|
String authorshipCache = name.getAuthorshipCache();
|
313 |
f3f4d328
|
Patrick Plitzner
|
checkAuthorShipConsistency(id, nomZusatzString, taxZusatzString, zusatzString, authorString, authorshipCache);
|
314 |
|
|
}
|
315 |
|
|
|
316 |
b3b2515e
|
Patrick Plitzner
|
private NonViralName<?> importName(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase<?,?>> namesToSave) throws SQLException {
|
317 |
|
|
|
318 |
|
|
long id = rs.getLong(RedListUtil.NAMNR);
|
319 |
|
|
String taxNameString = rs.getString(RedListUtil.TAXNAME);
|
320 |
|
|
String rangString = rs.getString(RedListUtil.RANG);
|
321 |
|
|
String ep1String = rs.getString(RedListUtil.EPI1);
|
322 |
|
|
String ep2String = rs.getString(RedListUtil.EPI2);
|
323 |
|
|
String ep3String = rs.getString(RedListUtil.EPI3);
|
324 |
|
|
String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
|
325 |
|
|
String hybString = rs.getString(RedListUtil.HYB);
|
326 |
|
|
|
327 |
f3f4d328
|
Patrick Plitzner
|
if(CdmUtils.isBlank(taxNameString) && CdmUtils.isBlank(ep1String)){
|
328 |
|
|
RedListUtil.logMessage(id, "No name found!", logger);
|
329 |
|
|
}
|
330 |
|
|
|
331 |
|
|
Rank rank = makeRank(id, state, rangString);
|
332 |
b3b2515e
|
Patrick Plitzner
|
NonViralName<?> name = BotanicalName.NewInstance(rank);
|
333 |
f3f4d328
|
Patrick Plitzner
|
|
334 |
|
|
//ep1 should always be present
|
335 |
|
|
if(CdmUtils.isBlank(ep1String)){
|
336 |
|
|
RedListUtil.logMessage(id, RedListUtil.EPI1+" is empty!", logger);
|
337 |
|
|
}
|
338 |
|
|
name.setGenusOrUninomial(ep1String);
|
339 |
|
|
if(CdmUtils.isNotBlank(ep2String)){
|
340 |
|
|
name.setSpecificEpithet(ep2String);
|
341 |
|
|
}
|
342 |
|
|
if(CdmUtils.isNotBlank(ep3String)){
|
343 |
74525264
|
Patrick Plitzner
|
name.setInfraSpecificEpithet(ep3String);
|
344 |
f3f4d328
|
Patrick Plitzner
|
}
|
345 |
|
|
//nomenclatural status
|
346 |
|
|
if(CdmUtils.isNotBlank(nomZusatzString)){
|
347 |
|
|
NomenclaturalStatusType status = makeNomenclaturalStatus(id, state, nomZusatzString);
|
348 |
|
|
if(status!=null){
|
349 |
|
|
name.addStatus(NomenclaturalStatus.NewInstance(status));
|
350 |
|
|
}
|
351 |
|
|
}
|
352 |
|
|
//hybrid
|
353 |
74525264
|
Patrick Plitzner
|
if(CdmUtils.isNotBlank(hybString)){
|
354 |
|
|
if(hybString.equals(RedListUtil.HYB_X)){
|
355 |
|
|
name.setBinomHybrid(true);
|
356 |
|
|
}
|
357 |
7f40ba60
|
Patrick Plitzner
|
else if(hybString.equals(RedListUtil.HYB_G)){
|
358 |
|
|
name.setMonomHybrid(true);
|
359 |
|
|
}
|
360 |
74525264
|
Patrick Plitzner
|
else if(hybString.equals(RedListUtil.HYB_XF)){
|
361 |
|
|
name.setHybridFormula(true);
|
362 |
|
|
if(ep1String.contains(RedListUtil.HYB_SIGN)){
|
363 |
|
|
RedListUtil.logMessage(id, "EPI1 has hybrid signs but with flag: "+RedListUtil.HYB_XF, logger);
|
364 |
|
|
}
|
365 |
|
|
else if(ep2String.contains(RedListUtil.HYB_SIGN)){
|
366 |
|
|
String[] split = ep2String.split(RedListUtil.HYB_SIGN);
|
367 |
|
|
if(split.length!=2){
|
368 |
|
|
RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep2String, logger);
|
369 |
|
|
}
|
370 |
|
|
String hybridFormula1 = ep1String+" "+split[0].trim();
|
371 |
|
|
String hybridFormula2 = ep1String+" "+split[1].trim();
|
372 |
|
|
if(CdmUtils.isNotBlank(ep3String)){
|
373 |
|
|
hybridFormula1 += " "+ep3String;
|
374 |
|
|
hybridFormula2 += " "+ep3String;
|
375 |
|
|
}
|
376 |
|
|
String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
|
377 |
|
|
name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
|
378 |
|
|
}
|
379 |
|
|
else if(ep3String.contains(RedListUtil.HYB_SIGN)){
|
380 |
|
|
String[] split = ep3String.split(RedListUtil.HYB_SIGN);
|
381 |
|
|
if(split.length!=2){
|
382 |
|
|
RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep3String, logger);
|
383 |
|
|
}
|
384 |
|
|
String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
|
385 |
|
|
String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
|
386 |
|
|
String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
|
387 |
|
|
name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
|
388 |
|
|
}
|
389 |
|
|
}
|
390 |
7f40ba60
|
Patrick Plitzner
|
else if(hybString.equals(RedListUtil.HYB_N)){
|
391 |
|
|
name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String+" "+ep2String+" nothosubsp. "+ep3String);
|
392 |
|
|
}
|
393 |
|
|
else if(hybString.equals(RedListUtil.HYB_GF)){
|
394 |
|
|
if(ep1String.contains(RedListUtil.HYB_SIGN)){
|
395 |
|
|
name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String);
|
396 |
|
|
}
|
397 |
|
|
else{
|
398 |
|
|
RedListUtil.logMessage(id, "HYB is "+hybString+" but "+RedListUtil.HYB+" does not contain "+RedListUtil.HYB_SIGN, logger);
|
399 |
|
|
}
|
400 |
|
|
}
|
401 |
|
|
else{
|
402 |
|
|
logger.error("HYB value "+hybString+" not yet handled");
|
403 |
|
|
}
|
404 |
f3f4d328
|
Patrick Plitzner
|
}
|
405 |
|
|
//add source
|
406 |
|
|
ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
|
407 |
b4b7ae12
|
Patrick Plitzner
|
|
408 |
f3f4d328
|
Patrick Plitzner
|
namesToSave.add(name);
|
409 |
|
|
return name;
|
410 |
|
|
}
|
411 |
|
|
|
412 |
|
|
private void checkAuthorShipConsistency(long id, String nomZusatzString, String taxZusatzString,
|
413 |
|
|
String zusatzString, String authorString, String authorshipCache) {
|
414 |
27d23ab7
|
Patrick Plitzner
|
if(CdmUtils.isNotBlank(zusatzString)){
|
415 |
b4b7ae12
|
Patrick Plitzner
|
authorString = authorString.replace(", "+zusatzString, "");
|
416 |
|
|
}
|
417 |
3c5880e8
|
Patrick Plitzner
|
if(CdmUtils.isNotBlank(nomZusatzString)){
|
418 |
|
|
authorString = authorString.replace(", "+nomZusatzString, "");
|
419 |
|
|
}
|
420 |
|
|
if(CdmUtils.isNotBlank(taxZusatzString)){
|
421 |
|
|
authorString = authorString.replace(", "+taxZusatzString, "");
|
422 |
|
|
}
|
423 |
b37b6a0f
|
Patrick Plitzner
|
if(authorString.equals(RedListUtil.AUCT)){
|
424 |
89603ae0
|
Patrick Plitzner
|
authorString = "";
|
425 |
|
|
}
|
426 |
b4b7ae12
|
Patrick Plitzner
|
if(!authorString.equals(authorshipCache)){
|
427 |
4fe9a46d
|
Patrick Plitzner
|
RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
|
428 |
9d0d3e98
|
Patrick Plitzner
|
}
|
429 |
f3f4d328
|
Patrick Plitzner
|
}
|
430 |
c5216774
|
Patrick Plitzner
|
|
431 |
b3b2515e
|
Patrick Plitzner
|
private void checkTaxonNameConsistency(long id, String taxNameString, String hybString, TaxonBase<?> taxonBase) {
|
432 |
74525264
|
Patrick Plitzner
|
if(hybString.equals(RedListUtil.HYB_XF)){
|
433 |
|
|
if(HibernateProxyHelper.deproxy(taxonBase.getName(),NonViralName.class).getHybridChildRelations().isEmpty()){
|
434 |
|
|
RedListUtil.logMessage(id, "Hybrid name but no hybrid child relations", logger);
|
435 |
|
|
return;
|
436 |
|
|
}
|
437 |
|
|
return;
|
438 |
|
|
}
|
439 |
|
|
|
440 |
|
|
|
441 |
|
|
String nameCache = HibernateProxyHelper.deproxy(taxonBase.getName(), NonViralName.class).getNameCache().trim();
|
442 |
48cd39f3
|
Patrick Plitzner
|
|
443 |
d5a18c75
|
Patrick Plitzner
|
if(taxNameString.endsWith("agg.")){
|
444 |
|
|
taxNameString = taxNameString.replace("agg.", "aggr.");
|
445 |
|
|
}
|
446 |
74525264
|
Patrick Plitzner
|
if(hybString.equals(RedListUtil.HYB_X)){
|
447 |
cefdede1
|
Patrick Plitzner
|
taxNameString = taxNameString.replace(RedListUtil.HYB_SIGN+" ", RedListUtil.HYB_SIGN);//hybrid sign has no space after it in titleCache for binomial hybrids
|
448 |
c9ec6fc8
|
Patrick Plitzner
|
}
|
449 |
cefdede1
|
Patrick Plitzner
|
if(taxNameString.endsWith("- Gruppe")){
|
450 |
|
|
taxNameString.replaceAll("- Gruppe", "species group");
|
451 |
|
|
}
|
452 |
|
|
if(taxNameString.endsWith("- group")){
|
453 |
|
|
taxNameString.replaceAll("- group", "species group");
|
454 |
48cd39f3
|
Patrick Plitzner
|
}
|
455 |
d5a18c75
|
Patrick Plitzner
|
if(!taxNameString.trim().equals(nameCache)){
|
456 |
|
|
RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
|
457 |
|
|
}
|
458 |
b463135c
|
Patrick Plitzner
|
}
|
459 |
|
|
|
460 |
ac9742df
|
Patrick Plitzner
|
private Rank makeRank(long id, RedListGefaesspflanzenImportState state, String rankStr) {
|
461 |
b463135c
|
Patrick Plitzner
|
Rank rank = null;
|
462 |
|
|
try {
|
463 |
|
|
rank = state.getTransformer().getRankByKey(rankStr);
|
464 |
|
|
} catch (UndefinedTransformerMethodException e) {
|
465 |
|
|
e.printStackTrace();
|
466 |
|
|
}
|
467 |
c5216774
|
Patrick Plitzner
|
if(rank==null){
|
468 |
ac9742df
|
Patrick Plitzner
|
RedListUtil.logMessage(id, rankStr+" could not be associated to a known rank.", logger);
|
469 |
c5216774
|
Patrick Plitzner
|
}
|
470 |
b463135c
|
Patrick Plitzner
|
return rank;
|
471 |
|
|
}
|
472 |
|
|
|
473 |
ac9742df
|
Patrick Plitzner
|
private NomenclaturalStatusType makeNomenclaturalStatus(long id, RedListGefaesspflanzenImportState state, String nomZusatzString) {
|
474 |
|
|
NomenclaturalStatusType status = null;
|
475 |
|
|
try {
|
476 |
|
|
status = state.getTransformer().getNomenclaturalStatusByKey(nomZusatzString);
|
477 |
|
|
} catch (UndefinedTransformerMethodException e) {
|
478 |
|
|
e.printStackTrace();
|
479 |
|
|
}
|
480 |
|
|
if(status==null){
|
481 |
|
|
RedListUtil.logMessage(id, nomZusatzString+" could not be associated to a known nomenclatural status.", logger);
|
482 |
|
|
}
|
483 |
|
|
return status;
|
484 |
|
|
}
|
485 |
|
|
|
486 |
b463135c
|
Patrick Plitzner
|
|
487 |
|
|
|
488 |
|
|
@Override
|
489 |
|
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
|
490 |
|
|
RedListGefaesspflanzenImportState state) {
|
491 |
|
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
492 |
94adeb1d
|
Patrick Plitzner
|
Map<String, AgentBase<?>> authorMap = new HashMap<String, AgentBase<?>>();
|
493 |
|
|
|
494 |
|
|
try {
|
495 |
|
|
while (rs.next()){
|
496 |
4fe9a46d
|
Patrick Plitzner
|
String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
|
497 |
94adeb1d
|
Patrick Plitzner
|
|
498 |
4fe9a46d
|
Patrick Plitzner
|
if(authorKombString.contains(RedListUtil.EX)){
|
499 |
|
|
String[] kombSplit = authorKombString.split(RedListUtil.EX);
|
500 |
94adeb1d
|
Patrick Plitzner
|
for (int i = 0; i < kombSplit.length; i++) {
|
501 |
|
|
if(!authorMap.containsKey(kombSplit[i])){
|
502 |
|
|
authorMap.put(kombSplit[i], getAgentService().load(state.getAuthorMap().get(kombSplit[i])));
|
503 |
|
|
}
|
504 |
|
|
}
|
505 |
|
|
}
|
506 |
27d23ab7
|
Patrick Plitzner
|
else if(CdmUtils.isNotBlank(authorKombString) && !authorMap.containsKey(authorKombString)){
|
507 |
94adeb1d
|
Patrick Plitzner
|
authorMap.put(authorKombString, getAgentService().load(state.getAuthorMap().get(authorKombString)));
|
508 |
|
|
}
|
509 |
|
|
|
510 |
4fe9a46d
|
Patrick Plitzner
|
String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
|
511 |
94adeb1d
|
Patrick Plitzner
|
//basionym author
|
512 |
4fe9a46d
|
Patrick Plitzner
|
if(authorBasiString.contains(RedListUtil.EX)){
|
513 |
|
|
String[] basiSplit = authorBasiString.split(RedListUtil.EX);
|
514 |
94adeb1d
|
Patrick Plitzner
|
for (int i = 0; i < basiSplit.length; i++) {
|
515 |
|
|
if(!authorMap.containsKey(basiSplit[i])){
|
516 |
|
|
authorMap.put(basiSplit[i], getAgentService().load(state.getAuthorMap().get(basiSplit[i])));
|
517 |
|
|
}
|
518 |
|
|
}
|
519 |
|
|
}
|
520 |
27d23ab7
|
Patrick Plitzner
|
else if(CdmUtils.isNotBlank(authorBasiString) && !authorMap.containsKey(authorBasiString)){
|
521 |
94adeb1d
|
Patrick Plitzner
|
authorMap.put(authorBasiString, getAgentService().load(state.getAuthorMap().get(authorBasiString)));
|
522 |
|
|
}
|
523 |
|
|
}
|
524 |
|
|
} catch (SQLException e) {
|
525 |
|
|
e.printStackTrace();
|
526 |
|
|
}
|
527 |
b37b6a0f
|
Patrick Plitzner
|
result.put(RedListUtil.AUTHOR_NAMESPACE, authorMap);
|
528 |
b463135c
|
Patrick Plitzner
|
|
529 |
|
|
return result;
|
530 |
|
|
}
|
531 |
|
|
|
532 |
|
|
@Override
|
533 |
|
|
protected boolean doCheck(RedListGefaesspflanzenImportState state) {
|
534 |
|
|
return false;
|
535 |
|
|
}
|
536 |
|
|
|
537 |
|
|
@Override
|
538 |
|
|
protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
|
539 |
|
|
return false;
|
540 |
|
|
}
|
541 |
|
|
|
542 |
|
|
}
|