Project

General

Profile

Revision d3b9767b

IDd3b9767bbf64115a686087af680e831aa1693329
Parent 8d5594ee
Child 81b53960

Added by Katja Luther about 5 years ago

fix #5869 use the service method to create new taxonnode to avoid multiple representation exception when reuse taxon

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonNodeWizard.java
21 21
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
22 22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23 23
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
24
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
24 25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25 26
import eu.etaxonomy.taxeditor.store.CdmStore;
27
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
26 28
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
27 29

  
28 30
/**
......
64 66
            	else{
65 67
            	    parentNodeUuid = parent.getUuid();
66 68
            	}
67
                UpdateResult result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon, parent.getReference(), parent.getMicroReference());
68

  
69
                //TaxonNode taxonNode = parent.addChildTaxon(taxon, parent.getReference(), parent.getMicroReference());
70

  
71
              /*  if(CdmStore.getCurrentSessionManager().isRemoting()) {
72
                    taxonNode = CdmStore.getService(ITaxonNodeService.class).merge(taxonNode);
73
                } else {
74
                    taxonNode = CdmStore.getService(ITaxonNodeService.class).save(taxonNode);
75
                }*/
76
                if (result.isOk()){
77
                	generatedTaxonNodeUuid = result.getCdmEntity().getUuid();
78
                	TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
79
                	taxonNode.getTaxon().setSec(sec);
80
                	CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
81
                    Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
82
                    if (result.getUpdatedObjects().iterator().hasNext()){
83
                    	TaxonNode parentNode = (TaxonNode)result.getUpdatedObjects().iterator().next();
84
                    	if(parentNode.getParent() == null) {
85
                            affectedObjects.add(taxonNode.getClassification());
86
                        }
87
                    	affectedObjects.add(parentNode);
88
                    }
89
                    if(CdmStore.getCurrentSessionManager().isRemoting()) {
90
                        CdmApplicationState.getCurrentDataChangeService()
91
                            .fireChangeEvent(new CdmChangeEvent(Action.Create, affectedObjects, NewTaxonNodeWizard.class), true);
92
                    }
93
                }else{
94
                    if (!result.isOk()){
95
                        if (!result.getExceptions().isEmpty()){
96
                            MessagingUtils.error(getClass(), "Taxon could not be created", result.getExceptions().iterator().next());
97
                        }else{
98
                            MessagingUtils.warn(getClass(), "Taxon could not be created");
99
                        }
100
                    }
101
                }
102
            }catch(IllegalArgumentException e){
69
            	UpdateResult result;
70
            	
71
            	if (taxon.getId() == 0){
72
            		result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon, parent.getReference(), parent.getMicroReference());
73
            	}else{
74
            		result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon.getUuid(), parent.getReference(), parent.getMicroReference());
75
            	}
76
            	if (result.isOk()){
77
	             	generatedTaxonNodeUuid = result.getCdmEntity().getUuid();
78
	             	TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
79
	             	taxonNode.getTaxon().setSec(sec);
80
	             	CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
81
	                 Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
82
	                 if (result.getUpdatedObjects().iterator().hasNext()){
83
	                 	TaxonNode parentNode = (TaxonNode)result.getUpdatedObjects().iterator().next();
84
	                 	if(parentNode.getParent() == null) {
85
	                         affectedObjects.add(taxonNode.getClassification());
86
	                     }
87
	                 	affectedObjects.add(parentNode);
88
	                 }
89
	                 if(CdmStore.getCurrentSessionManager().isRemoting()) {
90
	                     CdmApplicationState.getCurrentDataChangeService()
91
	                         .fireChangeEvent(new CdmChangeEvent(Action.Create, affectedObjects, NewTaxonNodeWizard.class), true);
92
	                 }
93
	             }else{
94
	                 if (!result.isOk()){
95
	                     if (!result.getExceptions().isEmpty()){
96
	                         MessagingUtils.error(getClass(), "Taxon could not be created", result.getExceptions().iterator().next());
97
	                     }else{
98
	                         MessagingUtils.warn(getClass(), "Taxon could not be created");
99
	                     }
100
	                 }
101
	             }
102
          }catch(IllegalArgumentException e){
103 103
                MessagingUtils.warningDialog("Taxon already exists in classfication", getClass(), e.getMessage());
104 104
            }
105 105
        }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java
185 185
			selection_reuseExistingTaxon.setEnabled(enabled);
186 186
			textNewTaxonName.setEnabled(enabled);
187 187

  
188
			setTaxon(selection_reuseExistingName.getEntity());
188
			//setTaxon(selection_reuseExistingName.getEntity());
189 189

  
190 190
			complete = !textNewTaxonName.getText().isEmpty();
191 191
		} else if (eventSource == textNewTaxonName) {
......
286 286
        return textNewTaxonName.getText();
287 287
    }
288 288
	public Taxon getTaxon() {
289
        return selection_reuseExistingTaxon.getEntity();
289
        return taxon;
290 290
    }
291 291

  
292 292
	public Reference getReference(){

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)