Merge branch 'remoting-4.0' into develop
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / MoveFactualDataHandler.java
index 7249dc198aedd5d54b52b1ffe6179db13219509f..9810418ca26bf8fbf9f4d0346f609b2398665922 100644 (file)
@@ -4,7 +4,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
@@ -21,10 +20,6 @@ import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.common.Annotation;
-import eu.etaxonomy.cdm.model.common.AnnotationType;
-import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
@@ -81,26 +76,10 @@ public class MoveFactualDataHandler extends AbstractHandler {
                                 "changes in the target taxon. Please save first.");
                         return null;
                     }
-                    for(TaxonDescription description : taxon.getDescriptions()){
-                        //reload to avoid session conflicts
-                        description = HibernateProxyHelper.deproxy(CdmStore.getService(IDescriptionService.class).load(description.getUuid()), TaxonDescription.class);
+                    CdmStore.getService(IDescriptionService.class).moveTaxonDescriptions(taxon.getUuid(),targetTaxonNode.getTaxon().getUuid());
 
-                        String moveMessage = String.format("Description moved from %s", taxon);
-                        if(description.isProtectedTitleCache()){
-                            String separator = "";
-                            if(!StringUtils.isBlank(description.getTitleCache())){
-                                separator = " - ";
-                            }
-                            description.setTitleCache(description.getTitleCache() + separator + moveMessage, true);
-                        }
-                        Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage());
-                        annotation.setAnnotationType(AnnotationType.TECHNICAL());
-                        description.addAnnotation(annotation);
-                        targetTaxonNode.getTaxon().addDescription(description);
-                        CdmStore.getService(IDescriptionService.class).saveOrUpdate(description);
-                        navigator.getConversationHolder().bind();
-                        navigator.getConversationHolder().commit();
-                    }
+                    navigator.getConversationHolder().bind();
+                    navigator.getConversationHolder().commit();
 
                     Display.getDefault().asyncExec(new Runnable(){