fix delete polytomouskeynode and improve merge in bulk editor
authorKatja Luther <k.luther@bgbm.org>
Thu, 13 Aug 2015 11:20:56 +0000 (13:20 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 13 Aug 2015 11:20:56 +0000 (13:20 +0200)
1  2 
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/MergeGroupHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/DeleteNodeOperation.java

@@@ -22,12 -22,12 +22,17 @@@ import org.eclipse.ui.IEditorPart
  import org.eclipse.ui.handlers.HandlerUtil;
  import org.eclipse.ui.texteditor.IDocumentProvider;
  
++import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
++import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
++import eu.etaxonomy.cdm.model.reference.Reference;
++import eu.etaxonomy.cdm.strategy.merge.MergeException;
  import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityContainer;
  import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
  import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
  import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
  import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
  import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
++import eu.etaxonomy.taxeditor.store.CdmStore;
  
  /**
   * <p>MergeGroupHandler class.</p>
@@@ -71,10 -71,10 +76,41 @@@ public class MergeGroupHandler extends 
                        }                       
                        Object targetEntity = ((IEntityContainer<?>) targetAnnotation).getEntity();
                        
++                      TeamOrPersonBase teamOrPerson = null;
++                      Reference ref = null;
++                      if (targetEntity instanceof TeamOrPersonBase){
++                              teamOrPerson = HibernateProxyHelper.deproxy(targetEntity, TeamOrPersonBase.class);
++                      } else if(targetEntity instanceof Reference){
++                              ref = HibernateProxyHelper.deproxy(targetEntity, Reference.class);
++                      }
                        logger.info("Merging group");
  //                    model.printAnnotations();
                        for (LineAnnotation annotation : candidateAnnotations) {
++                              //first check whether entities are mergeable
++                              
                                
++                      try{
++                              if (ref != null){
++                                      Reference ref2 = HibernateProxyHelper.deproxy(annotation.getEntity(), Reference.class);
++                                      
++                                      if (!CdmStore.getCommonService().isMergeable(ref, ref2, null)){
++                                              MessageDialog.openWarning(HandlerUtil.getActiveShell(event), 
++                                                              "No merge possible", "A merge of " + ref.getTitleCache() + " and " + ref2.getTitleCache() + " is not possible.");
++                                              return null;
++                                      }
++                              }
++                              if (teamOrPerson != null){
++                                      TeamOrPersonBase teamOrPerson2 = HibernateProxyHelper.deproxy(annotation.getEntity(), TeamOrPersonBase.class);
++                                      
++                                      if (!CdmStore.getCommonService().isMergeable(teamOrPerson, teamOrPerson2, null)){
++                                              MessageDialog.openWarning(HandlerUtil.getActiveShell(event), 
++                                                              "No merge possible", "A merge of " + teamOrPerson.getTitleCache() + " and " + teamOrPerson2.getTitleCache() + " is not possible.");
++                                              return null;
++                                      }
++                              }
++                      }catch(MergeException e){
++                                      
++                      }
                                ((BulkEditor) editor).removeAnnotatedLine(annotation);
                                
                                // Mark entity container for merging with target entity
@@@ -83,6 -83,6 +83,7 @@@ public class KeyEditor extends FormEdit
  
        @Override
        public void setFocus() {
++              getConversationHolder().commit(true);
                getConversationHolder().bind();
                super.setFocus();
        }
@@@ -12,9 -12,9 +12,12 @@@ import org.eclipse.jface.dialogs.Messag
  import org.eclipse.ui.handlers.HandlerUtil;
  
  import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
++import eu.etaxonomy.cdm.api.service.DeleteResult;
  import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
  import eu.etaxonomy.cdm.api.service.ITaxonService;
  import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
++import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
++import eu.etaxonomy.taxeditor.model.MessagingUtils;
  import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
  import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
  import eu.etaxonomy.taxeditor.store.CdmStore;
@@@ -52,15 -52,15 +55,27 @@@ public class DeleteNodeOperation extend
                controller = (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration();
                
                IPolytomousKeyNodeService service = controller.getPolytomousKeyNodeService();
--              
++              DeleteResult result;
                if (node.getChildren().size()>0){
                        if(! MessageDialog.openQuestion(null, "Confirm deletion of children", "The selected node has children, do you want to delete them, too?")) {
--                              service.delete(node.getUuid(), false);
++                              result = service.delete(node.getUuid(), false);
                        } else{
--                              service.delete(node.getUuid(), true);
++                              result = service.delete(node.getUuid(), true);
                        }
                } else{
--                      service.delete(node.getUuid(), true);
++                      result = service.delete(node.getUuid(), true);
++              }
++              
++              if (!result.isOk() || result.getExceptions().size() > 0){
++                      Exception t = new Exception();
++                      if (result.getExceptions().size() >1){
++                              for (Exception e:result.getExceptions()){
++                                      t.addSuppressed(e);
++                              }
++                      }else {
++                              t = result.getExceptions().iterator().next();
++                      }
++                      MessagingUtils.errorDialog("Exception occured. Delete not possible", getClass(),null, TaxeditorBulkeditorPlugin.PLUGIN_ID, t, true);
                }
                return postExecute(null);
        }