import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.io.common.DbImportBase;
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
import eu.etaxonomy.cdm.model.taxon.Classification;
@Override
protected void doInvoke(RedListGefaesspflanzenImportState state) {
- makeClassification(state);
+ makeClassification("Gesamtliste", state.getConfig().getClassificationUuid(), "Gesamtliste_ref", RedListUtil.gesamtListeReferenceUuid, state);
+ makeClassification("Checkliste", RedListUtil.checkListClassificationUuid, "Checkliste_ref", RedListUtil.checkListReferenceUuid, state);
+ makeClassification("E", RedListUtil.uuidClassificationE, "E_ref", RedListUtil.uuidClassificationReferenceE, state);
+ makeClassification("W", RedListUtil.uuidClassificationW, "W_ref", RedListUtil.uuidClassificationReferenceW, state);
+ makeClassification("K", RedListUtil.uuidClassificationK, "K_ref", RedListUtil.uuidClassificationReferenceK, state);
+ makeClassification("AW", RedListUtil.uuidClassificationAW, "AW_ref", RedListUtil.uuidClassificationReferenceAW, state);
+ makeClassification("AO", RedListUtil.uuidClassificationAO, "AO_ref", RedListUtil.uuidClassificationReferenceAO, state);
+ makeClassification("R", RedListUtil.uuidClassificationR, "R_ref", RedListUtil.uuidClassificationReferenceR, state);
+ makeClassification("O", RedListUtil.uuidClassificationO, "O_ref", RedListUtil.uuidClassificationReferenceO, state);
+ makeClassification("S", RedListUtil.uuidClassificationS, "S_ref", RedListUtil.uuidClassificationReferenceS, state);
super.doInvoke(state);
}
ResultSet rs = partitioner.getResultSet();
Classification gesamtListeClassification = getClassificationService().load(state.getConfig().getClassificationUuid());
Classification checklistClassification = getClassificationService().load(RedListUtil.checkListClassificationUuid);
+ Classification classificationE = getClassificationService().load(RedListUtil.uuidClassificationE);
+ Classification classificationW = getClassificationService().load(RedListUtil.uuidClassificationW);
+ Classification classificationK = getClassificationService().load(RedListUtil.uuidClassificationK);
+ Classification classificationAW = getClassificationService().load(RedListUtil.uuidClassificationAW);
+ Classification classificationAO = getClassificationService().load(RedListUtil.uuidClassificationAO);
+ Classification classificationR = getClassificationService().load(RedListUtil.uuidClassificationR);
+ Classification classificationO = getClassificationService().load(RedListUtil.uuidClassificationO);
+ Classification classificationS = getClassificationService().load(RedListUtil.uuidClassificationS);
try {
while (rs.next()){
- makeSingleTaxonNode(state, rs, gesamtListeClassification, checklistClassification);
+ makeSingleTaxonNode(state, rs, gesamtListeClassification, checklistClassification,
+ classificationE, classificationW, classificationK, classificationAW
+ , classificationAO, classificationR, classificationO, classificationS);
}
} catch (SQLException e) {
return true;
}
- private void makeSingleTaxonNode(RedListGefaesspflanzenImportState state, ResultSet rs, Classification gesamtListeClassification, Classification checklistClassification)
+ private void makeSingleTaxonNode(RedListGefaesspflanzenImportState state, ResultSet rs,
+ Classification gesamtListeClassification, Classification checklistClassification,
+ Classification classificationE, Classification classificationW, Classification classificationK,
+ Classification classificationAW, Classification classificationAO, Classification classificationR,
+ Classification classificationO, Classification classificationS)
throws SQLException {
long id = rs.getLong(RedListUtil.NAMNR);
String parentId = String.valueOf(rs.getLong(RedListUtil.LOWER));
//Gesamtliste
TaxonBase taxonBaseGL = state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, String.valueOf(id), TaxonBase.class);
+ TaxonBase parentBaseGL = state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class);
+ if(parentBaseGL!=null && !parentBaseGL.isInstanceOf(Taxon.class)){
+ RedListUtil.logMessage(id, parentBaseGL+" is no taxon but is a parent of "+taxonBaseGL+" (Gesamtliste)", logger);
+ }
Taxon parentGL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class);
createParentChildNodes(gesamtListeClassification, id, gueltString, taxZusatzString, taxonBaseGL, parentGL);
//Checkliste
TaxonBase taxonBaseCL = state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, String.valueOf(id), TaxonBase.class);
+ TaxonBase parentBaseCL = state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, parentId, TaxonBase.class);
+ if(parentBaseCL!=null && !parentBaseCL.isInstanceOf(Taxon.class)){
+ RedListUtil.logMessage(id, parentBaseCL+" is no taxon but is a parent of "+taxonBaseCL+" (Checkliste)", logger);
+ }
Taxon parentCL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, parentId, TaxonBase.class);
if(taxonBaseCL!=null){//null check necessary because not all taxa exist in the checklist
createParentChildNodes(checklistClassification, id, gueltString, taxZusatzString, taxonBaseCL, parentCL);
if(parentGL!=null && parentCL!=null && parentGL.getUuid().equals(parentCL.getUuid())){
RedListUtil.logMessage(id, "Same UUID for "+parentGL+ " (Gesamtliste) and "+parentCL+" (Checkliste)", logger);
}
+
+ //add taxa for concept relationships to E, W, K, AW, AO, R, O, S
+ addTaxonToClassification(classificationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, id, state);
+ addTaxonToClassification(classificationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, id, state);
+ addTaxonToClassification(classificationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, id, state);
+ addTaxonToClassification(classificationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, id, state);
+ addTaxonToClassification(classificationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, id, state);
+ addTaxonToClassification(classificationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, id, state);
+ addTaxonToClassification(classificationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, id, state);
+ addTaxonToClassification(classificationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, id, state);
+ }
+
+ private void addTaxonToClassification(Classification classification, String classificationNamespace, long id, RedListGefaesspflanzenImportState state){
+ Taxon taxon = HibernateProxyHelper.deproxy(state.getRelatedObject(classificationNamespace, String.valueOf(id), TaxonBase.class), Taxon.class);
+ classification.addChildTaxon(taxon, null, null);
}
private void createParentChildNodes(Classification classification, long id, String gueltString,
String taxZusatzString, TaxonBase taxonBase, Taxon parent) {
if(taxonBase==null){
- RedListUtil.logMessage(id, "child taxon/synonym of "+parent+" is null. ("+classification.getTitleCache()+")" , logger);
+ RedListUtil.logMessage(id, "child taxon/synonym of "+parent+" is null. ("+classification.generateTitle()+")" , logger);
return;
}
//taxon
return result;
}
- private void makeClassification(RedListGefaesspflanzenImportState state) {
- //Gesamtliste
- Classification classification = Classification.NewInstance(state.getConfig().getClassificationName());
- classification.setName(LanguageString.NewInstance("Gesamtliste", Language.DEFAULT()));
- classification.setUuid(state.getConfig().getClassificationUuid());
+ private void makeClassification(String classificationName, UUID classificationUuid, String referenceName, UUID referenceUuid, RedListGefaesspflanzenImportState state) {
+ Classification classification = Classification.NewInstance(classificationName, Language.DEFAULT());
+ classification.setUuid(classificationUuid);
Reference gesamtListeReference = ReferenceFactory.newGeneric();
- gesamtListeReference.setUuid(RedListUtil.gesamtListeReferenceUuid);
- gesamtListeReference.setTitle("Gesamtliste");
+ gesamtListeReference.setTitle(referenceName);
+ gesamtListeReference.setUuid(referenceUuid);
classification.setReference(gesamtListeReference);
getClassificationService().save(classification);
- //checkliste
- Classification checklistClassification = Classification.NewInstance("Checkliste");
- checklistClassification.setUuid(RedListUtil.checkListClassificationUuid);
- Reference checklistReference = ReferenceFactory.newGeneric();
- checklistReference.setUuid(RedListUtil.checkListReferenceUuid);
- checklistReference.setTitle("Checkliste");
- checklistClassification.setReference(checklistReference);
- getClassificationService().save(checklistClassification);
}
@Override