Revision 0873eb1c
Added by Patrick Plitzner about 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportClassification.java | ||
---|---|---|
78 | 78 |
@Override |
79 | 79 |
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) { |
80 | 80 |
ResultSet rs = partitioner.getResultSet(); |
81 |
Classification classification = getClassificationService().load(state.getConfig().getClassificationUuid()); |
|
81 |
Classification gesamtListeClassification = getClassificationService().load(state.getConfig().getClassificationUuid()); |
|
82 |
Classification checklistClassification = getClassificationService().load(RedListUtil.checkListClassificationUuid); |
|
82 | 83 |
try { |
83 | 84 |
while (rs.next()){ |
84 |
makeSingleTaxonNode(state, rs, classification);
|
|
85 |
makeSingleTaxonNode(state, rs, gesamtListeClassification, checklistClassification);
|
|
85 | 86 |
|
86 | 87 |
} |
87 | 88 |
} catch (SQLException e) { |
... | ... | |
89 | 90 |
} |
90 | 91 |
|
91 | 92 |
logger.info("Update classification (1000 nodes)"); |
92 |
getClassificationService().saveOrUpdate(classification); |
|
93 |
getClassificationService().saveOrUpdate(gesamtListeClassification); |
|
94 |
getClassificationService().saveOrUpdate(checklistClassification); |
|
93 | 95 |
return true; |
94 | 96 |
} |
95 | 97 |
|
96 |
private void makeSingleTaxonNode(RedListGefaesspflanzenImportState state, ResultSet rs, Classification classification)
|
|
98 |
private void makeSingleTaxonNode(RedListGefaesspflanzenImportState state, ResultSet rs, Classification gesamtListeClassification, Classification checklistClassification)
|
|
97 | 99 |
throws SQLException { |
98 | 100 |
long id = rs.getLong(RedListUtil.NAMNR); |
99 | 101 |
String parentId = String.valueOf(rs.getLong(RedListUtil.LOWER)); |
100 | 102 |
String gueltString = rs.getString(RedListUtil.GUELT); |
101 | 103 |
String taxZusatzString = rs.getString(RedListUtil.TAX_ZUSATZ); |
102 | 104 |
|
103 |
TaxonBase taxonBase = state.getRelatedObject(RedListUtil.TAXON_NAMESPACE, String.valueOf(id), TaxonBase.class); |
|
104 |
Taxon parent = (Taxon) state.getRelatedObject(RedListUtil.TAXON_NAMESPACE, parentId, TaxonBase.class); |
|
105 |
//Gesamtliste |
|
106 |
TaxonBase taxonBaseGL = state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, String.valueOf(id), TaxonBase.class); |
|
107 |
Taxon parentGL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class); |
|
108 |
createParentChildNodes(gesamtListeClassification, id, gueltString, taxZusatzString, taxonBaseGL, parentGL); |
|
105 | 109 |
|
110 |
//Checkliste |
|
111 |
TaxonBase taxonBaseCL = state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, String.valueOf(id), TaxonBase.class); |
|
112 |
Taxon parentCL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, parentId, TaxonBase.class); |
|
113 |
if(taxonBaseCL!=null && parentCL!=null){//null check necessary because not all taxa exist in the checklist |
|
114 |
createParentChildNodes(checklistClassification, id, gueltString, taxZusatzString, taxonBaseCL, parentCL); |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
private void createParentChildNodes(Classification classification, long id, String gueltString, |
|
119 |
String taxZusatzString, TaxonBase taxonBase, Taxon parent) { |
|
120 |
if(parent==null){ |
|
121 |
RedListUtil.logMessage(id, "parent taxon of "+taxonBase+" is null." , logger); |
|
122 |
} |
|
123 |
if(taxonBase==null){ |
|
124 |
RedListUtil.logMessage(id, "child taxon/synonym of "+parent+" is null." , logger); |
|
125 |
} |
|
106 | 126 |
//taxon |
107 | 127 |
if(taxonBase.isInstanceOf(Taxon.class)){ |
108 | 128 |
//misapplied name |
... | ... | |
120 | 140 |
} |
121 | 141 |
} |
122 | 142 |
} |
143 |
//synonym |
|
123 | 144 |
else if(taxonBase.isInstanceOf(Synonym.class)){ |
124 | 145 |
//basionym |
125 | 146 |
if(gueltString.equals(RedListUtil.GUELT_BASIONYM)){ |
... | ... | |
128 | 149 |
} |
129 | 150 |
//regular synonym |
130 | 151 |
else{ |
131 |
//TODO: how to correctly add a synonym? |
|
132 | 152 |
SynonymRelationship synonymRelationship = parent.addSynonym((Synonym) taxonBase, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), null, null); |
133 | 153 |
|
134 | 154 |
//TAX_ZUSATZ |
... | ... | |
149 | 169 |
taxonBase.setAppendedPhrase(taxZusatzString); |
150 | 170 |
} |
151 | 171 |
else{ |
152 |
RedListUtil.logMessage(id, "unknown value for column "+RedListUtil.TAX_ZUSATZ, logger); |
|
172 |
RedListUtil.logMessage(id, "unknown value "+taxZusatzString+" for column "+RedListUtil.TAX_ZUSATZ, logger);
|
|
153 | 173 |
} |
154 | 174 |
} |
155 | 175 |
} |
... | ... | |
170 | 190 |
} catch (SQLException e) { |
171 | 191 |
e.printStackTrace(); |
172 | 192 |
} |
173 |
Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.TAXON_NAMESPACE); |
|
174 |
result.put(RedListUtil.TAXON_NAMESPACE, taxonMap); |
|
193 |
Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE);
|
|
194 |
result.put(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, taxonMap);
|
|
175 | 195 |
return result; |
176 | 196 |
} |
177 | 197 |
|
178 | 198 |
private void makeClassification(RedListGefaesspflanzenImportState state) { |
199 |
//Gesamtliste |
|
179 | 200 |
Classification classification = Classification.NewInstance(state.getConfig().getClassificationName()); |
180 | 201 |
classification.setUuid(state.getConfig().getClassificationUuid()); |
181 | 202 |
getClassificationService().save(classification); |
203 |
//checkliste |
|
204 |
Classification checklistClassification = Classification.NewInstance("Checkliste"); |
|
205 |
checklistClassification.setUuid(RedListUtil.checkListClassificationUuid); |
|
206 |
getClassificationService().save(checklistClassification); |
|
182 | 207 |
} |
183 | 208 |
|
184 | 209 |
@Override |
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java | ||
---|---|---|
36 | 36 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
37 | 37 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
38 | 38 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
39 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
|
40 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
|
39 | 41 |
|
40 | 42 |
/** |
41 | 43 |
* |
... | ... | |
249 | 251 |
RedListUtil.logMessage(id, "Taxon for name "+name+" could not be created.", logger); |
250 | 252 |
return; |
251 | 253 |
} |
252 |
|
|
253 | 254 |
taxaToSave.add(taxonBase); |
254 | 255 |
|
256 |
/*check if taxon/synonym is also in checklist |
|
257 |
* 1. create new taxon with the same name (in the checklist classification) |
|
258 |
* 2. create congruent concept relationship between both |
|
259 |
*/ |
|
260 |
String clTaxonString = rs.getString(RedListUtil.CL_TAXON); |
|
261 |
if(CdmUtils.isNotBlank(clTaxonString) && !clTaxonString.trim().equals("-")){ |
|
262 |
TaxonBase clone = (TaxonBase) taxonBase.clone(); |
|
263 |
clone.setName(name); |
|
264 |
if(taxonBase.isInstanceOf(Taxon.class)){ |
|
265 |
TaxonRelationship taxonRelation = ((Taxon) taxonBase).addTaxonRelation((Taxon) clone, TaxonRelationshipType.CONGRUENT_TO(), null, null); |
|
266 |
taxonRelation.setDoubtful(true);//TODO Ist das mit " mit Fragezeichen" gemeint? |
|
267 |
} |
|
268 |
ImportHelper.setOriginalSource(clone, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE); |
|
269 |
state.getTaxonMap().put(id, clone.getUuid()); |
|
270 |
taxaToSave.add(clone); |
|
271 |
} |
|
272 |
|
|
255 | 273 |
//id |
256 |
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_NAMESPACE); |
|
274 |
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE);
|
|
257 | 275 |
state.getTaxonMap().put(id, taxonBase.getUuid()); |
258 | 276 |
} |
259 | 277 |
|
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportState.java | ||
---|---|---|
31 | 31 |
private final Map<String, UUID> authorMap = new HashMap<String, UUID>(); |
32 | 32 |
private final Map<Long, UUID> nameMap = new HashMap<Long, UUID>(); |
33 | 33 |
private final Map<Long, UUID> taxonMap = new HashMap<Long, UUID>(); |
34 |
private UUID checklistClassificationUuid; |
|
34 | 35 |
|
35 | 36 |
protected RedListGefaesspflanzenImportState(RedListGefaesspflanzenImportConfigurator config) { |
36 | 37 |
super(config); |
... | ... | |
48 | 49 |
return taxonMap; |
49 | 50 |
} |
50 | 51 |
|
52 |
public void setChecklistClassificationUuid(UUID checklistClassificationUuid) { |
|
53 |
this.checklistClassificationUuid = checklistClassificationUuid; |
|
54 |
} |
|
55 |
|
|
56 |
public UUID getChecklistClassificationUuid() { |
|
57 |
return checklistClassificationUuid; |
|
58 |
} |
|
59 |
|
|
51 | 60 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.io.redlist.gefaesspflanzen; |
11 | 11 |
|
12 |
import java.util.UUID; |
|
13 |
|
|
12 | 14 |
import org.apache.log4j.Logger; |
13 | 15 |
|
14 | 16 |
/** |
... | ... | |
18 | 20 |
*/ |
19 | 21 |
public class RedListUtil { |
20 | 22 |
|
23 |
public static final UUID checkListClassificationUuid = UUID.fromString("928a4695-c055-465e-99da-07322384b0b7"); |
|
24 |
|
|
21 | 25 |
public static final String NAME_NAMESPACE = "name"; |
22 |
public static final String TAXON_NAMESPACE = "taxon"; |
|
26 |
public static final String TAXON_GESAMTLISTE_NAMESPACE = "taxon_gesamt_liste"; |
|
27 |
public static final String TAXON_CHECKLISTE_NAMESPACE = "taxon_checkliste"; |
|
23 | 28 |
public static final String AUTHOR_NAMESPACE = "author"; |
24 | 29 |
|
25 | 30 |
public static final String AUCT = "auct."; |
... | ... | |
43 | 48 |
public static final String RANG = "RANG"; |
44 | 49 |
public static final String TAXNAME = "TAXNAME"; |
45 | 50 |
public static final String AUTOR = "AUTOR"; |
51 |
public static final String CL_TAXON = "CL_TAXON"; |
|
46 | 52 |
|
47 | 53 |
public static void logMessage(long id, String message, Logger logger){ |
48 | 54 |
logger.error(NAMNR+": "+id+" "+message); |
Also available in: Unified diff
Import taxa separately into checklist classification and GesamtListe
classification