Revision 892efc69
Added by Andreas Kohlbecker almost 14 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonRelationImport.java | ||
---|---|---|
39 | 39 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
40 | 40 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
41 | 41 |
import eu.etaxonomy.cdm.io.common.Source; |
42 |
import eu.etaxonomy.cdm.model.common.AnnotatableEntity; |
|
42 | 43 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
44 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
|
43 | 45 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
44 | 46 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
45 | 47 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship; |
... | ... | |
60 | 62 |
public class BerlinModelTaxonRelationImport extends BerlinModelImportBase { |
61 | 63 |
private static final Logger logger = Logger.getLogger(BerlinModelTaxonRelationImport.class); |
62 | 64 |
|
65 |
public static final String TREE_NAMESPACE = "PTRefFk"; |
|
66 |
|
|
63 | 67 |
private static int modCount = 30000; |
64 | 68 |
private static final String pluralString = "taxon relations"; |
65 | 69 |
private static final String dbTableName = "RelPTaxon"; |
... | ... | |
91 | 95 |
//biblio reference map |
92 | 96 |
nameSpace = BerlinModelReferenceImport.BIBLIO_REFERENCE_NAMESPACE; |
93 | 97 |
cdmClass = ReferenceBase.class; |
94 |
idSet = new HashSet<String>(); |
|
98 |
// idSet = new HashSet<String>();
|
|
95 | 99 |
Map<String, ReferenceBase> biblioRefMap = (Map<String, ReferenceBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
96 | 100 |
|
97 | 101 |
ResultSet rs = source.getResultSet(getTaxonomicTreeQuery()) ; |
... | ... | |
105 | 109 |
Object ptRefFkObj = rs.getObject("PTRefFk"); |
106 | 110 |
String ptRefFk= String.valueOf(ptRefFkObj); |
107 | 111 |
ReferenceBase<?> ref = getReferenceOnlyFromMaps(biblioRefMap, nomRefMap, ptRefFk); |
108 |
|
|
109 |
//FIXME treeName
|
|
112 |
|
|
113 |
rs.getString("RefCache");
|
|
110 | 114 |
String treeName = "TaxonTree - No Name"; |
115 |
String refCache = rs.getString("RefCache"); |
|
116 |
if (CdmUtils.isNotEmpty(refCache)){ |
|
117 |
treeName = refCache; |
|
118 |
} |
|
111 | 119 |
if (ref != null && CdmUtils.isNotEmpty(ref.getTitleCache())){ |
112 | 120 |
treeName = ref.getTitleCache(); |
113 | 121 |
} |
... | ... | |
116 | 124 |
if (i == 1 && state.getConfig().getTaxonomicTreeUuid() != null){ |
117 | 125 |
tree.setUuid(state.getConfig().getTaxonomicTreeUuid()); |
118 | 126 |
} |
127 |
IdentifiableSource identifiableSource = IdentifiableSource.NewInstance(ptRefFk, TREE_NAMESPACE); |
|
128 |
tree.addSource(identifiableSource); |
|
119 | 129 |
|
120 | 130 |
getTaxonTreeService().save(tree); |
121 | 131 |
state.putTaxonomicTreeUuidInt((Integer)ptRefFkObj, tree); |
... | ... | |
142 | 152 |
} |
143 | 153 |
return result; |
144 | 154 |
} |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
/* (non-Javadoc) |
|
149 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getIdQuery() |
|
150 |
*/ |
|
151 |
@Override |
|
152 |
protected String getIdQuery() { |
|
153 |
String result = " " + |
|
154 |
" SELECT RelPTaxon.RelPTaxonId " + |
|
155 |
" FROM RelPTaxon LEFT JOIN Name AS toName ON RelPTaxon.PTNameFk1 = toName.NameId " + |
|
156 |
" ORDER BY toName.RankFk "; |
|
157 |
return result; |
|
158 |
} |
|
159 | 155 |
|
160 | 156 |
/** |
161 | 157 |
* @return |
162 | 158 |
*/ |
163 | 159 |
private String getTaxonomicTreeQuery() { |
164 |
String strQuery = "SELECT PTaxon.PTRefFk " + |
|
160 |
String strQuery = "SELECT PTaxon.PTRefFk, Reference.RefCache " +
|
|
165 | 161 |
" FROM RelPTaxon INNER JOIN " + |
166 |
" PTaxon AS PTaxon ON RelPTaxon.PTNameFk2 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon.PTRefFk " + |
|
162 |
" PTaxon AS PTaxon ON RelPTaxon.PTNameFk2 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon.PTRefFk INNER JOIN " + |
|
163 |
" Reference ON PTaxon.PTRefFk = Reference.RefId " + |
|
167 | 164 |
" WHERE (RelPTaxon.RelQualifierFk = 1) " + |
168 |
" GROUP BY PTaxon.PTRefFk "; |
|
165 |
" GROUP BY PTaxon.PTRefFk, Reference.RefCache ";
|
|
169 | 166 |
return strQuery; |
170 | 167 |
} |
171 | 168 |
|
... | ... | |
198 | 195 |
Map<String, ReferenceBase> nomRefMap = (Map<String, ReferenceBase>) partitioner.getObjectMap(BerlinModelReferenceImport.NOM_REFERENCE_NAMESPACE); |
199 | 196 |
|
200 | 197 |
ResultSet rs = partitioner.getResultSet(); |
201 |
|
|
198 |
|
|
202 | 199 |
try{ |
203 | 200 |
int i = 0; |
204 | 201 |
//for each reference |
... | ... | |
212 | 209 |
Object relRefFkObj = rs.getObject("relRefFk"); |
213 | 210 |
int treeRefFk = rs.getInt("treeRefFk"); |
214 | 211 |
int relQualifierFk = rs.getInt("relQualifierFk"); |
212 |
String notes = rs.getString("notes"); |
|
215 | 213 |
boolean isConceptRelationship = rs.getBoolean("is_concept_relation"); |
216 | 214 |
|
217 | 215 |
TaxonBase taxon1 = taxonMap.get(String.valueOf(taxon1Id)); |
... | ... | |
228 | 226 |
success = false; |
229 | 227 |
continue; |
230 | 228 |
} |
229 |
AnnotatableEntity taxonRelationship = null; |
|
231 | 230 |
Taxon toTaxon = (Taxon)taxon2; |
232 | 231 |
if (isTaxonRelationship(relQualifierFk)){ |
233 | 232 |
if (!(taxon1 instanceof Taxon)){ |
... | ... | |
237 | 236 |
} |
238 | 237 |
Taxon fromTaxon = (Taxon)taxon1; |
239 | 238 |
if (relQualifierFk == TAX_REL_IS_INCLUDED_IN){ |
240 |
makeTaxonomicallyIncluded(state, taxonTreeMap, treeRefFk, fromTaxon, toTaxon, citation, microcitation); |
|
239 |
taxonRelationship = makeTaxonomicallyIncluded(state, taxonTreeMap, treeRefFk, fromTaxon, toTaxon, citation, microcitation);
|
|
241 | 240 |
}else if (relQualifierFk == TAX_REL_IS_MISAPPLIED_NAME_OF){ |
242 |
toTaxon.addMisappliedName(fromTaxon, citation, microcitation); |
|
241 |
taxonRelationship = toTaxon.addMisappliedName(fromTaxon, citation, microcitation);
|
|
243 | 242 |
} |
244 | 243 |
}else if (isSynonymRelationship(relQualifierFk)){ |
245 | 244 |
if (!(taxon1 instanceof Synonym)){ |
... | ... | |
249 | 248 |
} |
250 | 249 |
Synonym synonym = (Synonym)taxon1; |
251 | 250 |
SynonymRelationship synRel = getSynRel(relQualifierFk, toTaxon, synonym, citation, microcitation); |
252 |
|
|
251 |
taxonRelationship = synRel; |
|
252 |
|
|
253 | 253 |
if (relQualifierFk == TAX_REL_IS_SYNONYM_OF || |
254 | 254 |
relQualifierFk == TAX_REL_IS_HOMOTYPIC_SYNONYM_OF || |
255 | 255 |
relQualifierFk == TAX_REL_IS_HETEROTYPIC_SYNONYM_OF){ |
... | ... | |
275 | 275 |
logger.error("TaxonBase (ID = " + taxon1.getId()+ ", RIdentifier = " + taxon1Id + ") can't be casted to Taxon"); |
276 | 276 |
}else{ |
277 | 277 |
Taxon fromTaxon = (Taxon)taxon1; |
278 |
fromTaxon.addTaxonRelation(toTaxon, relType, citation, microcitation); |
|
278 |
taxonRelationship = fromTaxon.addTaxonRelation(toTaxon, relType, citation, microcitation);
|
|
279 | 279 |
} |
280 | 280 |
} catch (UnknownCdmTypeException e) { |
281 | 281 |
//TODO other relationships |
... | ... | |
287 | 287 |
logger.warn("TaxonRelationShipType " + relQualifierFk + " not yet implemented"); |
288 | 288 |
success = false; |
289 | 289 |
} |
290 |
|
|
291 |
doNotes(taxonRelationship, notes); |
|
290 | 292 |
taxaToSave.add(taxon2); |
291 | 293 |
|
292 | 294 |
//TODO |
... | ... | |
305 | 307 |
getTaxonService().save(taxaToSave); |
306 | 308 |
taxonTreeMap = null; |
307 | 309 |
taxaToSave = null; |
308 |
|
|
309 |
return success; |
|
310 |
|
|
311 |
return success;
|
|
310 | 312 |
} |
311 | 313 |
|
312 | 314 |
|
... | ... | |
345 | 347 |
handleForeignKey(rs, taxonIdSet, "taxon2Id"); |
346 | 348 |
// handleForeignKey(rs, taxonTreeIdSet, "treeRefFk"); |
347 | 349 |
handleForeignKey(rs, referenceIdSet, "RelRefFk"); |
348 |
}
|
|
349 |
|
|
350 |
} |
|
351 |
|
|
350 | 352 |
//taxon map |
351 | 353 |
nameSpace = BerlinModelTaxonImport.NAMESPACE; |
352 | 354 |
cdmClass = TaxonBase.class; |
... | ... | |
441 | 443 |
} |
442 | 444 |
} |
443 | 445 |
|
444 |
private boolean makeTaxonomicallyIncluded(BerlinModelImportState state, Map<Integer, TaxonomicTree> taxonTreeMap, int treeRefFk, Taxon child, Taxon parent, ReferenceBase citation, String microCitation){
|
|
446 |
private TaxonNode makeTaxonomicallyIncluded(BerlinModelImportState state, Map<Integer, TaxonomicTree> taxonTreeMap, int treeRefFk, Taxon child, Taxon parent, ReferenceBase citation, String microCitation){
|
|
445 | 447 |
TaxonomicTree tree = taxonTreeMap.get(treeRefFk); |
446 | 448 |
if (tree == null){ |
447 | 449 |
UUID treeUuid = state.getTreeUuidByIntTreeKey(treeRefFk); |
Also available in: Unified diff
merging /branches/cdmlib/SPRINT-Chichorieae1/ to trunk