Revision 783428fc
Added by Patrick Plitzner almost 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportClassification.java | ||
---|---|---|
36 | 36 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
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.TaxonRelationshipType; |
|
39 | 40 |
|
40 | 41 |
/** |
41 | 42 |
* |
... | ... | |
131 | 132 |
String gueltString = rs.getString(RedListUtil.GUELT); |
132 | 133 |
String taxZusatzString = rs.getString(RedListUtil.TAX_ZUSATZ); |
133 | 134 |
|
135 |
String relationE = rs.getString(RedListUtil.E); |
|
136 |
String relationW = rs.getString(RedListUtil.W); |
|
137 |
String relationK = rs.getString(RedListUtil.K); |
|
138 |
String relationAW = rs.getString(RedListUtil.AW); |
|
139 |
String relationAO = rs.getString(RedListUtil.AO); |
|
140 |
String relationR = rs.getString(RedListUtil.R); |
|
141 |
String relationO = rs.getString(RedListUtil.O); |
|
142 |
String relationS = rs.getString(RedListUtil.S); |
|
143 |
|
|
134 | 144 |
//Gesamtliste |
135 | 145 |
TaxonBase<?> taxonBaseGL = state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, String.valueOf(id), TaxonBase.class); |
136 | 146 |
TaxonBase<?> parentBaseGL = state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class); |
... | ... | |
160 | 170 |
} |
161 | 171 |
|
162 | 172 |
//add taxa for concept relationships to E, W, K, AW, AO, R, O, S |
163 |
addTaxonToClassification(classificationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, id, state); |
|
164 |
addTaxonToClassification(classificationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, id, state); |
|
165 |
addTaxonToClassification(classificationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, id, state); |
|
166 |
addTaxonToClassification(classificationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, id, state); |
|
167 |
addTaxonToClassification(classificationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, id, state); |
|
168 |
addTaxonToClassification(classificationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, id, state); |
|
169 |
addTaxonToClassification(classificationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, id, state); |
|
170 |
addTaxonToClassification(classificationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, id, state); |
|
173 |
addTaxonToClassification(classificationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, relationE, taxonBaseGL, taxonBaseCL, id, state);
|
|
174 |
addTaxonToClassification(classificationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, relationW, taxonBaseGL, taxonBaseCL, id, state);
|
|
175 |
addTaxonToClassification(classificationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, relationK, taxonBaseGL, taxonBaseCL, id, state);
|
|
176 |
addTaxonToClassification(classificationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, relationAW, taxonBaseGL, taxonBaseCL, id, state);
|
|
177 |
addTaxonToClassification(classificationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, relationAO, taxonBaseGL, taxonBaseCL, id, state);
|
|
178 |
addTaxonToClassification(classificationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, relationR, taxonBaseGL, taxonBaseCL, id, state);
|
|
179 |
addTaxonToClassification(classificationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, relationO, taxonBaseGL, taxonBaseCL, id, state);
|
|
180 |
addTaxonToClassification(classificationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, relationS, taxonBaseGL, taxonBaseCL, id, state);
|
|
171 | 181 |
} |
172 | 182 |
|
173 |
private void addTaxonToClassification(Classification classification, String classificationNamespace, long id, RedListGefaesspflanzenImportState state){ |
|
183 |
private void addTaxonToClassification(Classification classification, String classificationNamespace, String relationString, final TaxonBase<?> gesamtListeTaxon, final TaxonBase<?> checklisteTaxon, long id, RedListGefaesspflanzenImportState state){
|
|
174 | 184 |
Taxon taxon = HibernateProxyHelper.deproxy(state.getRelatedObject(classificationNamespace, String.valueOf(id), TaxonBase.class), Taxon.class); |
185 |
//add concept relation to gesamtliste and checkliste |
|
186 |
if(CdmUtils.isNotBlank(relationString) && !relationString.equals(".")){ |
|
187 |
//if the related concept in gesamtliste/checkliste is a synonym then we |
|
188 |
//create a relation to the accepted taxon |
|
189 |
Taxon acceptedGesamtListeTaxon = getAcceptedTaxon(gesamtListeTaxon); |
|
190 |
Taxon acceptedChecklistTaxon = getAcceptedTaxon(checklisteTaxon); |
|
191 |
String relationSubstring = relationString.substring(relationString.length()-1, relationString.length()); |
|
192 |
TaxonRelationshipType taxonRelationshipTypeByKey = new RedListGefaesspflanzenTransformer().getTaxonRelationshipTypeByKey(relationSubstring); |
|
193 |
if(taxonRelationshipTypeByKey==null){ |
|
194 |
RedListUtil.logMessage(id, "Could not interpret relationship "+relationString+" for taxon "+gesamtListeTaxon.generateTitle(), logger); |
|
195 |
} |
|
196 |
//there is no type "included in" so we have to reverse the direction |
|
197 |
if(relationSubstring.equals("<")){ |
|
198 |
if(acceptedGesamtListeTaxon!=null){ |
|
199 |
acceptedGesamtListeTaxon.addTaxonRelation(taxon, taxonRelationshipTypeByKey, null, null); |
|
200 |
} |
|
201 |
if(acceptedChecklistTaxon!=null) { |
|
202 |
acceptedChecklistTaxon.addTaxonRelation(taxon, taxonRelationshipTypeByKey, null, null); |
|
203 |
} |
|
204 |
} |
|
205 |
else{ |
|
206 |
if(acceptedGesamtListeTaxon!=null){ |
|
207 |
taxon.addTaxonRelation(acceptedGesamtListeTaxon, taxonRelationshipTypeByKey, null, null); |
|
208 |
} |
|
209 |
if(acceptedChecklistTaxon!=null) { |
|
210 |
taxon.addTaxonRelation(acceptedChecklistTaxon, taxonRelationshipTypeByKey, null, null); |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
175 | 215 |
if(taxon!=null){//not all taxa exist in these classifications |
176 | 216 |
taxon.setSec(classification.getReference()); |
177 | 217 |
taxon.setTitleCache(null);//Reset title cache to reflect sec ref in title |
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java | ||
---|---|---|
117 | 117 |
throws SQLException { |
118 | 118 |
long id = rs.getLong(RedListUtil.NAMNR); |
119 | 119 |
String clTaxonString = rs.getString(RedListUtil.CL_TAXON); |
120 |
String relationE = rs.getString(RedListUtil.E); |
|
121 |
String relationW = rs.getString(RedListUtil.W); |
|
122 |
String relationK = rs.getString(RedListUtil.K); |
|
123 |
String relationAW = rs.getString(RedListUtil.AW); |
|
124 |
String relationAO = rs.getString(RedListUtil.AO); |
|
125 |
String relationR = rs.getString(RedListUtil.R); |
|
126 |
String relationO = rs.getString(RedListUtil.O); |
|
127 |
String relationS = rs.getString(RedListUtil.S); |
|
128 | 120 |
|
129 | 121 |
//---NAME--- |
130 | 122 |
NonViralName<?> name = importName(state, rs, namesToSave); |
... | ... | |
154 | 146 |
taxaToSave.add(checklistTaxon); |
155 | 147 |
} |
156 | 148 |
//E, W, K, AW, AO, R, O, S |
157 |
addConceptRelation(relationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
158 |
addConceptRelation(relationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
159 |
addConceptRelation(relationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
160 |
addConceptRelation(relationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
161 |
addConceptRelation(relationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
162 |
addConceptRelation(relationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
163 |
addConceptRelation(relationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
164 |
addConceptRelation(relationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxonBase, checklistTaxon, taxaToSave, id, state);
|
|
149 |
cloneTaxon(taxonBase, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxaToSave, id, state);
|
|
150 |
cloneTaxon(taxonBase, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxaToSave, id, state);
|
|
151 |
cloneTaxon(taxonBase, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxaToSave, id, state);
|
|
152 |
cloneTaxon(taxonBase, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxaToSave, id, state);
|
|
153 |
cloneTaxon(taxonBase, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxaToSave, id, state);
|
|
154 |
cloneTaxon(taxonBase, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxaToSave, id, state);
|
|
155 |
cloneTaxon(taxonBase, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxaToSave, id, state);
|
|
156 |
cloneTaxon(taxonBase, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxaToSave, id, state);
|
|
165 | 157 |
|
166 | 158 |
//NOTE: the source has to be added after cloning or otherwise the clone would also get the source |
167 | 159 |
ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE); |
168 | 160 |
taxaToSave.add(taxonBase); |
169 | 161 |
} |
170 | 162 |
|
171 |
private void addConceptRelation(String relationString, String classificationNamespace, TaxonBase<?> gesamtListeTaxon, TaxonBase<?> checkListenTaxon, Set<TaxonBase> taxaToSave, long id, RedListGefaesspflanzenImportState state){ |
|
172 |
if(CdmUtils.isNotBlank(relationString) && !relationString.equals(".")){ |
|
173 |
String substring = relationString.substring(relationString.length()-1, relationString.length()); |
|
174 |
TaxonRelationshipType taxonRelationshipTypeByKey = new RedListGefaesspflanzenTransformer().getTaxonRelationshipTypeByKey(substring); |
|
175 |
if(taxonRelationshipTypeByKey==null){ |
|
176 |
RedListUtil.logMessage(id, "Could not interpret relationship "+relationString+" for taxon "+gesamtListeTaxon.generateTitle(), logger); |
|
177 |
} |
|
178 |
//there is no type "included in" so we have to reverse the direction |
|
179 |
if(substring.equals("<")){ |
|
180 |
cloneTaxon(gesamtListeTaxon, checkListenTaxon, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, true, false, state); |
|
181 |
} |
|
182 |
else{ |
|
183 |
cloneTaxon(gesamtListeTaxon, checkListenTaxon, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, false, false, state); |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* 1. clone new taxon of gesamtListeTaxon with the same name (in that classification)<br> |
|
190 |
* 2. create concept relationship from clone to gesamtListeTaxon/checklisteTaxon or from its accepted taxon if it is synonym<br> |
|
191 |
*<br> |
|
192 |
* <b>NOTE:</b> the {@link TaxonRelationshipType} passed as parameter is |
|
193 |
* directed <b>from the clone</b> to the taxon.<br> |
|
194 |
* This can be changed with parameter <i>reverseRelation</i> |
|
195 |
* @return cloned taxon |
|
196 |
*/ |
|
197 |
private Taxon cloneTaxon(final TaxonBase<?> gesamtListeTaxon, final TaxonBase<?> checklisteTaxon, TaxonRelationshipType relationFromCloneToTaxon, Set<TaxonBase> taxaToSave, long id, String sourceNameSpace, boolean reverseRelation, boolean doubtful, RedListGefaesspflanzenImportState state){ |
|
198 |
Taxon acceptedGesamtListeTaxon = getAcceptedTaxon(gesamtListeTaxon); |
|
199 |
Taxon acceptedChecklistTaxon = getAcceptedTaxon(checklisteTaxon); |
|
163 |
private Taxon cloneTaxon(final TaxonBase<?> gesamtListeTaxon, String sourceNameSpace, Set<TaxonBase> taxaToSave, long id, RedListGefaesspflanzenImportState state){ |
|
200 | 164 |
Taxon clonedTaxon = null; |
201 | 165 |
|
202 | 166 |
if(gesamtListeTaxon.isInstanceOf(Taxon.class)){ |
... | ... | |
210 | 174 |
return null; |
211 | 175 |
} |
212 | 176 |
|
213 |
if(reverseRelation){ |
|
214 |
if(acceptedGesamtListeTaxon!=null){ |
|
215 |
TaxonRelationship taxonRelation = acceptedGesamtListeTaxon.addTaxonRelation(clonedTaxon, relationFromCloneToTaxon, null, null); |
|
216 |
taxonRelation.setDoubtful(doubtful); |
|
217 |
} |
|
218 |
if(acceptedChecklistTaxon!=null) { |
|
219 |
TaxonRelationship taxonRelation = acceptedChecklistTaxon.addTaxonRelation(clonedTaxon, relationFromCloneToTaxon, null, null); |
|
220 |
taxonRelation.setDoubtful(doubtful); |
|
221 |
} |
|
222 |
} |
|
223 |
else { |
|
224 |
if(acceptedGesamtListeTaxon!=null){ |
|
225 |
TaxonRelationship taxonRelation = clonedTaxon.addTaxonRelation(acceptedGesamtListeTaxon, relationFromCloneToTaxon, null, null); |
|
226 |
taxonRelation.setDoubtful(doubtful); |
|
227 |
} |
|
228 |
if(acceptedChecklistTaxon!=null) { |
|
229 |
TaxonRelationship taxonRelation = clonedTaxon.addTaxonRelation(acceptedChecklistTaxon, relationFromCloneToTaxon, null, null); |
|
230 |
taxonRelation.setDoubtful(doubtful); |
|
231 |
} |
|
232 |
} |
|
233 |
|
|
234 | 177 |
ImportHelper.setOriginalSource(clonedTaxon, state.getTransactionalSourceReference(), id, sourceNameSpace); |
235 | 178 |
taxaToSave.add(clonedTaxon); |
236 | 179 |
return clonedTaxon; |
Also available in: Unified diff
#5448 Move import of concept relationships to classification import
class