fix #5869 use the service method to create new taxonnode to avoid multiple representa...
authorKatja Luther <k.luther@bgbm.org>
Fri, 26 Aug 2016 10:40:18 +0000 (12:40 +0200)
committerKatja Luther <k.luther@bgbm.org>
Fri, 26 Aug 2016 10:40:18 +0000 (12:40 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonNodeWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java

index e8dfc554796b2e2cdc33fdde7584a4a94cecef6c..36da706729679f99cbcb4f4bc78d6e4ea587cb8b 100644 (file)
@@ -21,8 +21,10 @@ import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
 
 /**
@@ -64,42 +66,40 @@ public class NewTaxonNodeWizard extends AbstractNewEntityWizard<ITaxonTreeNode>{
                else{
                    parentNodeUuid = parent.getUuid();
                }
-                UpdateResult result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon, parent.getReference(), parent.getMicroReference());
-
-                //TaxonNode taxonNode = parent.addChildTaxon(taxon, parent.getReference(), parent.getMicroReference());
-
-              /*  if(CdmStore.getCurrentSessionManager().isRemoting()) {
-                    taxonNode = CdmStore.getService(ITaxonNodeService.class).merge(taxonNode);
-                } else {
-                    taxonNode = CdmStore.getService(ITaxonNodeService.class).save(taxonNode);
-                }*/
-                if (result.isOk()){
-                       generatedTaxonNodeUuid = result.getCdmEntity().getUuid();
-                       TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
-                       taxonNode.getTaxon().setSec(sec);
-                       CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
-                    Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
-                    if (result.getUpdatedObjects().iterator().hasNext()){
-                       TaxonNode parentNode = (TaxonNode)result.getUpdatedObjects().iterator().next();
-                       if(parentNode.getParent() == null) {
-                            affectedObjects.add(taxonNode.getClassification());
-                        }
-                       affectedObjects.add(parentNode);
-                    }
-                    if(CdmStore.getCurrentSessionManager().isRemoting()) {
-                        CdmApplicationState.getCurrentDataChangeService()
-                            .fireChangeEvent(new CdmChangeEvent(Action.Create, affectedObjects, NewTaxonNodeWizard.class), true);
-                    }
-                }else{
-                    if (!result.isOk()){
-                        if (!result.getExceptions().isEmpty()){
-                            MessagingUtils.error(getClass(), "Taxon could not be created", result.getExceptions().iterator().next());
-                        }else{
-                            MessagingUtils.warn(getClass(), "Taxon could not be created");
-                        }
-                    }
-                }
-            }catch(IllegalArgumentException e){
+               UpdateResult result;
+               
+               if (taxon.getId() == 0){
+                       result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon, parent.getReference(), parent.getMicroReference());
+               }else{
+                       result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon.getUuid(), parent.getReference(), parent.getMicroReference());
+               }
+               if (result.isOk()){
+                       generatedTaxonNodeUuid = result.getCdmEntity().getUuid();
+                       TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
+                       taxonNode.getTaxon().setSec(sec);
+                       CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
+                        Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
+                        if (result.getUpdatedObjects().iterator().hasNext()){
+                               TaxonNode parentNode = (TaxonNode)result.getUpdatedObjects().iterator().next();
+                               if(parentNode.getParent() == null) {
+                                affectedObjects.add(taxonNode.getClassification());
+                            }
+                               affectedObjects.add(parentNode);
+                        }
+                        if(CdmStore.getCurrentSessionManager().isRemoting()) {
+                            CdmApplicationState.getCurrentDataChangeService()
+                                .fireChangeEvent(new CdmChangeEvent(Action.Create, affectedObjects, NewTaxonNodeWizard.class), true);
+                        }
+                    }else{
+                        if (!result.isOk()){
+                            if (!result.getExceptions().isEmpty()){
+                                MessagingUtils.error(getClass(), "Taxon could not be created", result.getExceptions().iterator().next());
+                            }else{
+                                MessagingUtils.warn(getClass(), "Taxon could not be created");
+                            }
+                        }
+                    }
+          }catch(IllegalArgumentException e){
                 MessagingUtils.warningDialog("Taxon already exists in classfication", getClass(), e.getMessage());
             }
         }
index 7da137dc9f612283ebd870576359dd36b61fafd1..1ecc939342dc3a5d007953ef433d9b14e62521cb 100644 (file)
@@ -185,7 +185,7 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
                        selection_reuseExistingTaxon.setEnabled(enabled);
                        textNewTaxonName.setEnabled(enabled);
 
-                       setTaxon(selection_reuseExistingName.getEntity());
+                       //setTaxon(selection_reuseExistingName.getEntity());
 
                        complete = !textNewTaxonName.getText().isEmpty();
                } else if (eventSource == textNewTaxonName) {
@@ -286,7 +286,7 @@ public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeN
         return textNewTaxonName.getText();
     }
        public Taxon getTaxon() {
-        return selection_reuseExistingTaxon.getEntity();
+        return taxon;
     }
 
        public Reference getReference(){