Revision 766713c7
Added by Patrick Plitzner over 7 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java | ||
---|---|---|
135 | 135 |
} |
136 | 136 |
|
137 | 137 |
//---CONCEPT RELATIONSHIPS--- |
138 |
/*check if taxon/synonym also exists in other classification |
|
139 |
* 1. create new taxon with the same name (in that classification) |
|
140 |
* 2. create concept relationship between both |
|
141 |
*/ |
|
142 | 138 |
//checklist |
139 |
TaxonBase<?> checklistTaxon = null; |
|
143 | 140 |
if(CdmUtils.isNotBlank(clTaxonString) && !clTaxonString.trim().equals("-")){ |
144 |
cloneTaxon(taxonBase, name, TaxonRelationshipType.CONGRUENT_TO(), taxaToSave, id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE, false, true, state); |
|
141 |
checklistTaxon = (TaxonBase<?>) taxonBase.clone(); |
|
142 |
//TODO what to do with synonyms? |
|
143 |
if(checklistTaxon.isInstanceOf(Taxon.class)){ |
|
144 |
TaxonRelationship relation = HibernateProxyHelper.deproxy(checklistTaxon, Taxon.class).addTaxonRelation(HibernateProxyHelper.deproxy(taxonBase, Taxon.class), TaxonRelationshipType.CONGRUENT_TO(), null, null); |
|
145 |
relation.setDoubtful(true); |
|
146 |
} |
|
147 |
|
|
148 |
ImportHelper.setOriginalSource(checklistTaxon, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE); |
|
149 |
taxaToSave.add(checklistTaxon); |
|
145 | 150 |
} |
146 | 151 |
//E, W, K, AW, AO, R, O, S |
147 |
addConceptRelation(relationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxonBase, name, taxaToSave, id, state);
|
|
148 |
addConceptRelation(relationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxonBase, name, taxaToSave, id, state);
|
|
149 |
addConceptRelation(relationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxonBase, name, taxaToSave, id, state);
|
|
150 |
addConceptRelation(relationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxonBase, name, taxaToSave, id, state);
|
|
151 |
addConceptRelation(relationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxonBase, name, taxaToSave, id, state);
|
|
152 |
addConceptRelation(relationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxonBase, name, taxaToSave, id, state);
|
|
153 |
addConceptRelation(relationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxonBase, name, taxaToSave, id, state);
|
|
154 |
addConceptRelation(relationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxonBase, name, taxaToSave, id, state);
|
|
152 |
addConceptRelation(relationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
153 |
addConceptRelation(relationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
154 |
addConceptRelation(relationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
155 |
addConceptRelation(relationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
156 |
addConceptRelation(relationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
157 |
addConceptRelation(relationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
158 |
addConceptRelation(relationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
159 |
addConceptRelation(relationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
155 | 160 |
|
156 | 161 |
//NOTE: the source has to be added after cloning or otherwise the clone would also get the source |
157 | 162 |
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE); |
158 | 163 |
taxaToSave.add(taxonBase); |
159 | 164 |
} |
160 | 165 |
|
161 |
private void addConceptRelation(String relationString, String classificationNamespace, TaxonBase<?> taxonBase, TaxonNameBase<?,?> name, Set<TaxonBase<?>> taxaToSave, long id, RedListGefaesspflanzenImportState state){
|
|
166 |
private void addConceptRelation(String relationString, String classificationNamespace, TaxonBase<?> gesamtListeTaxon, TaxonBase<?> checkListenTaxon, Set<TaxonBase<?>> taxaToSave, long id, RedListGefaesspflanzenImportState state){
|
|
162 | 167 |
if(CdmUtils.isNotBlank(relationString) && !relationString.equals(".")){ |
163 | 168 |
String substring = relationString.substring(relationString.length()-1, relationString.length()); |
164 | 169 |
TaxonRelationshipType taxonRelationshipTypeByKey = new RedListGefaesspflanzenTransformer().getTaxonRelationshipTypeByKey(substring); |
165 | 170 |
if(taxonRelationshipTypeByKey==null){ |
166 |
RedListUtil.logMessage(id, "Could not interpret relationship "+relationString+" for taxon "+taxonBase.generateTitle(), logger);
|
|
171 |
RedListUtil.logMessage(id, "Could not interpret relationship "+relationString+" for taxon "+gesamtListeTaxon.generateTitle(), logger);
|
|
167 | 172 |
} |
168 | 173 |
//there is no type "included in" so we have to reverse the direction |
169 | 174 |
if(substring.equals("<")){ |
170 |
cloneTaxon(taxonBase, name, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, true, false, state);
|
|
175 |
cloneTaxon(gesamtListeTaxon, checkListenTaxon, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, true, false, state);
|
|
171 | 176 |
} |
172 | 177 |
else{ |
173 |
cloneTaxon(taxonBase, name, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, false, false, state);
|
|
178 |
cloneTaxon(gesamtListeTaxon, checkListenTaxon, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, false, false, state);
|
|
174 | 179 |
} |
175 | 180 |
} |
176 | 181 |
} |
177 | 182 |
|
178 | 183 |
/** |
184 |
* 1. clone new taxon of gesamtListeTaxon with the same name (in that classification)<br> |
|
185 |
* 2. create concept relationship from clone to gesamtListeTaxon/checklisteTaxon or from its accepted taxon if it is synonym<br> |
|
186 |
*<br> |
|
179 | 187 |
* <b>NOTE:</b> the {@link TaxonRelationshipType} passed as parameter is |
180 | 188 |
* directed <b>from the clone</b> to the taxon.<br> |
181 | 189 |
* This can be changed with parameter <i>reverseRelation</i> |
190 |
* @return cloned taxon |
|
182 | 191 |
*/ |
183 |
private void cloneTaxon(TaxonBase<?> taxonBase, TaxonNameBase<?, ?> name, TaxonRelationshipType relationFromCloneToTaxon, Set<TaxonBase<?>> taxaToSave, long id, String sourceNameSpace, boolean reverseRelation, boolean doubtful, RedListGefaesspflanzenImportState state){ |
|
184 |
TaxonBase<?> clone = (TaxonBase<?>) taxonBase.clone(); |
|
185 |
if(taxonBase.isInstanceOf(Taxon.class)){ |
|
186 |
TaxonRelationship taxonRelation; |
|
187 |
if(reverseRelation){ |
|
188 |
taxonRelation = ((Taxon) taxonBase).addTaxonRelation((Taxon) clone, relationFromCloneToTaxon, null, null); |
|
192 |
private Taxon cloneTaxon(final TaxonBase<?> gesamtListeTaxon, final TaxonBase<?> checklisteTaxon, TaxonRelationshipType relationFromCloneToTaxon, Set<TaxonBase<?>> taxaToSave, long id, String sourceNameSpace, boolean reverseRelation, boolean doubtful, RedListGefaesspflanzenImportState state){ |
|
193 |
Taxon acceptedGesamtListeTaxon = getAcceptedTaxon(gesamtListeTaxon); |
|
194 |
Taxon acceptedChecklistTaxon = getAcceptedTaxon(checklisteTaxon); |
|
195 |
Taxon clonedTaxon = null; |
|
196 |
|
|
197 |
if(gesamtListeTaxon.isInstanceOf(Taxon.class)){ |
|
198 |
clonedTaxon = HibernateProxyHelper.deproxy(gesamtListeTaxon.clone(), Taxon.class); |
|
199 |
} |
|
200 |
else if(gesamtListeTaxon.isInstanceOf(Synonym.class)){ |
|
201 |
clonedTaxon = Taxon.NewInstance(gesamtListeTaxon.getName(), gesamtListeTaxon.getSec()); |
|
202 |
} |
|
203 |
else{ |
|
204 |
RedListUtil.logMessage(id, "Taxon base "+gesamtListeTaxon+" is neither taxon nor synonym! Taxon could not be cloned", logger); |
|
205 |
return null; |
|
206 |
} |
|
207 |
|
|
208 |
if(reverseRelation){ |
|
209 |
if(acceptedGesamtListeTaxon!=null){ |
|
210 |
TaxonRelationship taxonRelation = acceptedGesamtListeTaxon.addTaxonRelation(clonedTaxon, relationFromCloneToTaxon, null, null); |
|
211 |
taxonRelation.setDoubtful(doubtful); |
|
212 |
} |
|
213 |
if(acceptedChecklistTaxon!=null) { |
|
214 |
TaxonRelationship taxonRelation = acceptedChecklistTaxon.addTaxonRelation(clonedTaxon, relationFromCloneToTaxon, null, null); |
|
215 |
taxonRelation.setDoubtful(doubtful); |
|
189 | 216 |
} |
190 |
else { |
|
191 |
taxonRelation = ((Taxon) clone).addTaxonRelation((Taxon) taxonBase, relationFromCloneToTaxon, null, null); |
|
217 |
} |
|
218 |
else { |
|
219 |
if(acceptedGesamtListeTaxon!=null){ |
|
220 |
TaxonRelationship taxonRelation = clonedTaxon.addTaxonRelation(acceptedGesamtListeTaxon, relationFromCloneToTaxon, null, null); |
|
221 |
taxonRelation.setDoubtful(doubtful); |
|
222 |
} |
|
223 |
if(acceptedChecklistTaxon!=null) { |
|
224 |
TaxonRelationship taxonRelation = clonedTaxon.addTaxonRelation(acceptedChecklistTaxon, relationFromCloneToTaxon, null, null); |
|
225 |
taxonRelation.setDoubtful(doubtful); |
|
192 | 226 |
} |
193 |
taxonRelation.setDoubtful(doubtful); |
|
194 | 227 |
} |
195 |
ImportHelper.setOriginalSource(clone, state.getTransactionalSourceReference(), id, sourceNameSpace); |
|
196 |
taxaToSave.add(clone); |
|
228 |
|
|
229 |
ImportHelper.setOriginalSource(clonedTaxon, state.getTransactionalSourceReference(), id, sourceNameSpace); |
|
230 |
taxaToSave.add(clonedTaxon); |
|
231 |
return clonedTaxon; |
|
197 | 232 |
} |
198 | 233 |
|
199 | 234 |
private TaxonBase<?> importTaxon(ResultSet rs, NonViralName<?> name) throws SQLException { |
Also available in: Unified diff
Import synonyms of other classifications #5448