*/
package eu.etaxonomy.taxeditor.newWizard;
-import java.util.HashSet;
-import java.util.Set;
import java.util.UUID;
import javax.inject.Inject;
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.UpdateResult;
-import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
import eu.etaxonomy.cdm.model.reference.Reference;
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.cdm.persistence.dto.TaxonNodeDto;
import eu.etaxonomy.taxeditor.l10n.Messages;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
/**
}else{
getConversationHolder().bind();
ITaxonTreeNode parent = getParentTreeNode();
- Reference sec = taxon.getSec();
- taxon.setSec(null);
try{
UUID parentNodeUuid;
if(parent instanceof Classification){
else{
parentNodeUuid = parent.getUuid();
}
-
-
UpdateResult result;
-
-
- if (taxon.getId() == 0){
- //getEntity().setTaxon(taxon);
- result = CdmStore.getService(ITaxonNodeService.class).saveNewTaxonNode(getEntity());
-
- }else{
- result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon.getUuid(), parent.getReference(), parent.getMicroReference());
- }
+ result = CdmStore.getService(ITaxonNodeService.class).saveNewTaxonNode(getEntity());
if (result.isOk()){
- generatedTaxonNodeUuid = result.getCdmEntity().getUuid();
- TaxonNode taxonNode = CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
- taxonNode.getTaxon().setSec(sec);
- taxonNode.setExcluded(((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isExcluded());
- taxonNode.setUnplaced(((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isUnplaced());
-
-
- MergeResult resultMerge = 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 (resultMerge.getMergedEntity() instanceof TaxonNode){
- TaxonNode node = (TaxonNode)resultMerge.getMergedEntity();
- affectedObjects.remove(node);
-
- affectedObjects.add(node);
- }
- CdmApplicationState.getCurrentDataChangeService()
- .fireChangeEvent(new CdmChangeEvent(Action.Create, affectedObjects, NewTaxonNodeWizard.class), true);
+ CdmApplicationState.getCurrentDataChangeService()
+ .fireChangeEvent(new CdmChangeEvent(Action.Create, result.getUpdatedObjects(), NewTaxonNodeWizard.class), true);
}else{
if (!result.isOk()){
Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
TaxonNode child = node.addChildTaxon(newTaxon, null, null);
-// if(node.getTaxon()!=null){
-// //FIXME this taxon is not used. Do we need this call?
-// Taxon taxon = (Taxon) CdmStore.getService(ITaxonService.class).load(node.getTaxon().getUuid());
-// }
-// else if(node.getClassification()!=null){
-// return CdmStore.getService(IClassificationService.class).load(node.getClassification().getUuid());
-// }
+
return child;
}