90 |
90 |
//reference map
|
91 |
91 |
String nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
|
92 |
92 |
Class<?> cdmClass = Reference.class;
|
93 |
|
Map<String, Reference> refMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
93 |
@SuppressWarnings("unchecked")
|
|
94 |
Map<String, Reference> refMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
94 |
95 |
|
95 |
|
String treeName = "Classification - No Name";
|
|
96 |
String classificationName = "Classification - No Name";
|
96 |
97 |
|
97 |
98 |
ResultSet rs = state.getConfig().getSource().getResultSet(getClassificationQuery(state)) ;
|
98 |
99 |
int i = 0;
|
99 |
100 |
//for each reference
|
100 |
101 |
try {
|
101 |
102 |
//TODO handle case useSingleClassification = true && sourceSecId = null, which returns no record
|
102 |
|
while (rs.next()){
|
|
103 |
boolean isFirst = true;
|
|
104 |
while (rs.next()){
|
103 |
105 |
|
104 |
106 |
try {
|
105 |
107 |
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("RelPTaxa handled: " + (i-1));}
|
... | ... | |
109 |
111 |
Reference ref = refMap.get(ptRefFk);
|
110 |
112 |
|
111 |
113 |
String refCache = rs.getString("RefCache");
|
112 |
|
if (StringUtils.isNotBlank(refCache)){
|
113 |
|
treeName = refCache;
|
|
114 |
if (isNotBlank(refCache)){
|
|
115 |
classificationName = refCache;
|
114 |
116 |
}
|
115 |
117 |
if (ref != null && StringUtils.isNotBlank(ref.getTitleCache())){
|
116 |
|
treeName = ref.getTitleCache();
|
|
118 |
classificationName = ref.getTitleCache();
|
|
119 |
}
|
|
120 |
if (isFirst && isNotBlank(state.getConfig().getClassificationName())){
|
|
121 |
classificationName = state.getConfig().getClassificationName();
|
117 |
122 |
}
|
118 |
|
Classification tree = Classification.NewInstance(treeName);
|
|
123 |
Classification tree = Classification.NewInstance(classificationName);
|
119 |
124 |
tree.setReference(ref);
|
120 |
125 |
if (i == 1 && state.getConfig().getClassificationUuid() != null){
|
121 |
126 |
tree.setUuid(state.getConfig().getClassificationUuid());
|
... | ... | |
125 |
130 |
|
126 |
131 |
getClassificationService().save(tree);
|
127 |
132 |
state.putClassificationUuidInt(ptRefFkInt, tree);
|
|
133 |
isFirst = false;
|
128 |
134 |
} catch (Exception e) {
|
129 |
135 |
logger.error("Error in BerlinModleTaxonRelationImport.makeClassifications: " + e.getMessage());
|
130 |
136 |
e.printStackTrace();
|
... | ... | |
220 |
226 |
@Override
|
221 |
227 |
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
222 |
228 |
String strQuery =
|
223 |
|
" SELECT RelPTaxon.*, FromTaxon.RIdentifier as taxon1Id, ToTaxon.RIdentifier as taxon2Id, ToTaxon.PTRefFk as treeRefFk, FromTaxon.PTRefFk as fromRefFk, q.is_concept_relation " +
|
224 |
|
" FROM PTaxon as FromTaxon " +
|
225 |
|
" INNER JOIN RelPTaxon ON FromTaxon.PTNameFk = RelPTaxon.PTNameFk1 AND FromTaxon.PTRefFk = RelPTaxon.PTRefFk1 " +
|
226 |
|
" INNER JOIN PTaxon AS ToTaxon ON RelPTaxon.PTNameFk2 = ToTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = ToTaxon.PTRefFk " +
|
|
229 |
" SELECT RelPTaxon.*, fromTaxon.RIdentifier as taxon1Id, toTaxon.RIdentifier as taxon2Id, toTaxon.PTRefFk as treeRefFk, fromTaxon.PTRefFk as fromRefFk, q.is_concept_relation " +
|
|
230 |
" FROM PTaxon as fromTaxon " +
|
|
231 |
" INNER JOIN RelPTaxon ON fromTaxon.PTNameFk = relPTaxon.PTNameFk1 AND fromTaxon.PTRefFk = relPTaxon.PTRefFk1 " +
|
|
232 |
" INNER JOIN PTaxon AS toTaxon ON RelPTaxon.PTNameFk2 = ToTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = ToTaxon.PTRefFk " +
|
227 |
233 |
" INNER JOIN RelPTQualifier q ON q.RelPTQualifierId = RelPTaxon.RelQualifierFk " +
|
228 |
|
" WHERE RelPTaxon.RelPTaxonId IN ("+ID_LIST_TOKEN+") ORDER BY RelPTaxon.RelPTaxonId ";
|
|
234 |
" WHERE RelPTaxon.RelPTaxonId IN ("+ID_LIST_TOKEN+") " +
|
|
235 |
" ORDER BY RelPTaxon.RelPTaxonId ";
|
229 |
236 |
return strQuery;
|
230 |
237 |
}
|
231 |
238 |
|
232 |
239 |
@Override
|
233 |
240 |
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
234 |
241 |
boolean success = true ;
|
235 |
|
BerlinModelImportConfigurator config = state.getConfig();
|
236 |
242 |
Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();
|
237 |
243 |
Map<String, TaxonBase> taxonMap = partitioner.getObjectMap(BerlinModelTaxonImport.NAMESPACE);
|
238 |
244 |
Map<Integer, Classification> classificationMap = new HashMap<Integer, Classification>();
|
... | ... | |
250 |
256 |
int relPTaxonId = rs.getInt("RelPTaxonId");
|
251 |
257 |
Integer taxon1Id = nullSafeInt(rs, "taxon1Id");
|
252 |
258 |
Integer taxon2Id = nullSafeInt(rs, "taxon2Id");
|
253 |
|
int relQualifierFk = 0;
|
|
259 |
int relQualifierFk = -1;
|
254 |
260 |
try {
|
255 |
261 |
Integer relRefFk = nullSafeInt(rs,"relRefFk");
|
256 |
262 |
int treeRefFk = rs.getInt("treeRefFk");
|
... | ... | |
301 |
307 |
handleAllRelatedTaxa(state, toTaxon, classificationMap, treeRefFk);
|
302 |
308 |
Synonym synonym = (Synonym)taxon1;
|
303 |
309 |
if (synonym.getAcceptedTaxon()!= null){
|
304 |
|
logger.warn("Synonym already has an accepted taxon. Create clone.");
|
|
310 |
logger.warn("RelID: " + relPTaxonId + ". Synonym ("+taxon1Id +") already has an accepted taxon. Create clone.");
|
305 |
311 |
synonym = (Synonym)synonym.clone();
|
306 |
312 |
}
|
307 |
313 |
makeSynRel(relQualifierFk, toTaxon, synonym, citation, microcitation);
|
308 |
|
if (isNotBlank(notes)){
|
309 |
|
logger.warn("Notes for synonym relationship or unknown taxon relationship not handled");
|
310 |
|
}
|
311 |
314 |
|
312 |
315 |
if (relQualifierFk == TAX_REL_IS_SYNONYM_OF ||
|
313 |
316 |
relQualifierFk == TAX_REL_IS_HOMOTYPIC_SYNONYM_OF ||
|
... | ... | |
323 |
326 |
synonym.setPartial(true);
|
324 |
327 |
}else{
|
325 |
328 |
success = false;
|
326 |
|
logger.warn("Proparte/Partial not yet implemented for TaxonRelationShipType " + relQualifierFk);
|
|
329 |
logger.warn("Synonym relationship type not yet implemented: " + relQualifierFk);
|
327 |
330 |
}
|
328 |
331 |
}else if (isConceptRelationship){
|
329 |
332 |
ResultWrapper<Boolean> isInverse = ResultWrapper.NewInstance(false);
|
... | ... | |
360 |
363 |
if (taxonRelationship != null){
|
361 |
364 |
doNotes(taxonRelationship, notes);
|
362 |
365 |
}else if (isNotBlank(notes)){
|
363 |
|
logger.warn("Notes for synonym relationship or unknown taxon relationship not handled");
|
|
366 |
logger.warn("Notes for synonym relationship or unknown taxon relationship not handled. RelID: " + relPTaxonId + ". Note: " + notes);
|
364 |
367 |
}
|
365 |
368 |
taxaToSave.add(taxon2);
|
366 |
369 |
|
cleanup BM import