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 |
}
|
fix #5869 use the service method to create new taxonnode to avoid multiple representation exception when reuse taxon