#5010 : Initial commit to fix duplicate entry issue when creating new key node
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 17 Jul 2015 13:05:35 +0000 (15:05 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 17 Jul 2015 13:05:35 +0000 (15:05 +0200)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/ProxyUtils.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CachedCommonServiceImpl.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyEditorInput.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListContentProvider.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/operation/CreateNodeOperation.java

index 33f1203454b156aedf1294f766124596772c7490..1d1e878eacb09fb222f287fd8eae52cf6cf4b33a 100644 (file)
@@ -28,6 +28,7 @@ import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
 import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor;
 import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
 import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
 import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor;
 import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
 import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
+import eu.etaxonomy.taxeditor.service.ICachedCommonService;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 
 /**
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 
 /**
@@ -208,4 +209,8 @@ public class CdmApplicationRemoteController  extends CdmApplicationController {
     public ITestService getTestService(){
         return (ITestService) getBean("testService");
     }
     public ITestService getTestService(){
         return (ITestService) getBean("testService");
     }
+
+    public ICachedCommonService getCachedCommonService(){
+        return (ICachedCommonService) getBean("cachedCommonService");
+    }
 }
 }
index cf47b3cfce64fce2bf7da00713e2f6b4bbbac9e3..551f5fafeacc229697741a4fc6c8058368b8f89f 100644 (file)
@@ -16,6 +16,7 @@ import java.lang.reflect.Type;
 import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.api.service.ITestService;
 import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.api.service.ITestService;
+import eu.etaxonomy.taxeditor.service.ICachedCommonService;
 
 /**
  * @author cmathew
 
 /**
  * @author cmathew
@@ -135,4 +136,11 @@ public class CdmApplicationState {
 
     }
 
 
     }
 
+    public static ICachedCommonService getCachedCommonService() {
+        ICdmApplicationConfiguration configuration = getCurrentAppConfig();
+
+        return ((CdmApplicationRemoteController)configuration).getCachedCommonService();
+
+    }
+
 }
 }
index c1a951777be518e9fa9e750d1f6fb2dbbb947654..ceca3e97e99c4e900c972ce3b06f1243fbe28574 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.UUID;
 
 import org.hibernate.collection.internal.PersistentBag;
 import org.hibernate.collection.internal.PersistentList;
 
 import org.hibernate.collection.internal.PersistentBag;
 import org.hibernate.collection.internal.PersistentList;
@@ -30,6 +31,8 @@ import org.hibernate.proxy.HibernateProxy;
 import org.hibernate.proxy.LazyInitializer;
 import org.springframework.util.ReflectionUtils;
 
 import org.hibernate.proxy.LazyInitializer;
 import org.springframework.util.ReflectionUtils;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
 import eu.etaxonomy.taxeditor.remoting.CdmRemotingException;
 
 import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
 import eu.etaxonomy.taxeditor.remoting.CdmRemotingException;
 
@@ -168,6 +171,28 @@ public class ProxyUtils {
         return false;
     }
 
         return false;
     }
 
+    public static Object remoteLoadPersistentCollectionIfProxy(Object o, UUID ownerUuid, String fieldName) throws ClassNotFoundException {
+        if(o != null && o instanceof HibernateProxy) {
+            LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
+            if(hli.isUninitialized()) {
+                return CdmApplicationState.getCachedCommonService().find((Class<CdmBase>)Class.forName(hli.getEntityName()),
+                        ((Integer)hli.getIdentifier()).intValue());
+            }
+        }
+
+        if(o != null && o instanceof PersistentCollection) {
+            PersistentCollection pc = ((PersistentCollection)o);
+            if(!pc.wasInitialized()) {
+                return CdmApplicationState.getCachedCommonService().initializeCollection(ownerUuid, fieldName);
+            }
+        }
+
+        return o;
+    }
+
+
+
+
     public static void setRoleValueInOwner(Object owner, String role, Object value) {
         if(role == null || role.isEmpty()) {
             throw new CdmRemotingException("Role cannot be null or an empty string");
     public static void setRoleValueInOwner(Object owner, String role, Object value) {
         if(role == null || role.isEmpty()) {
             throw new CdmRemotingException("Role cannot be null or an empty string");
index 3b302659c707ad45ef973ae6442197a95bd1a35a..e36138e698f7a2f4539b8bdc5b0d9ff872851c84 100644 (file)
@@ -54,15 +54,16 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
      */
     @Override
     public CdmBase find(Class<? extends CdmBase> clazz, int id) {
      */
     @Override
     public CdmBase find(Class<? extends CdmBase> clazz, int id) {
-        if(cacheEnabled) {
-            CdmBase cdmEntity = CdmBase.deproxy(commonService.find(clazz, id, getPropertyPaths(clazz)),clazz);
+//        if(cacheEnabled) {
+            CdmBase cdmEntity = commonService.find(clazz, id, getPropertyPaths(clazz));
             if(cdmEntity == null) {
                 throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id  + " is null.");
             }
             if(cdmEntity == null) {
                 throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id  + " is null.");
             }
-            return cdmEntitySessionManager.load(cdmEntity, false);
-        } else {
-            return CdmBase.deproxy(commonService.find(clazz, id),clazz);
-        }
+            return cdmEntity;
+            //return cdmEntitySessionManager.load(cdmEntity, false);
+//        } else {
+//            return CdmBase.deproxy(commonService.find(clazz, id),clazz);
+//        }
     }
 
 
     }
 
 
index 31eecc36aa100a2a4b38d59315ad267fcc915990..a6555ce7d01e3f5ff8266f33ac90ed98995984f6 100644 (file)
@@ -21,7 +21,7 @@ public class PolytomousKeyEditorInput extends AbstractIdentificationEditorInput<
 
     private final String name;
     private final UUID keyUuid;
 
     private final String name;
     private final UUID keyUuid;
-    private final PolytomousKey key;
+    private PolytomousKey key;
 
 
     protected PolytomousKeyEditorInput(ConversationHolder conversation,
 
 
     protected PolytomousKeyEditorInput(ConversationHolder conversation,
@@ -89,7 +89,7 @@ public class PolytomousKeyEditorInput extends AbstractIdentificationEditorInput<
      */
     @Override
     public void merge() {
      */
     @Override
     public void merge() {
-        CdmStore.getService(IPolytomousKeyService.class).merge(key);
+        key = CdmStore.getService(IPolytomousKeyService.class).merge(key);
     }
 
 }
     }
 
 }
index a17c56a0a503afd56d350188b8ed65d5c4179f51..90ed20b2b7386d3397d1ce2d2de13f45851709ee 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2007 EDIT
 // $Id$
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -16,7 +16,6 @@ import java.util.List;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.Viewer;
 
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.Viewer;
 
-import eu.etaxonomy.cdm.model.description.PolytomousKey;
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
 
 /**
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
 
 /**
@@ -29,7 +28,7 @@ public class PolytomousKeyListContentProvider implements
 
        /*
         * (non-Javadoc)
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see org.eclipse.jface.viewers.IContentProvider#dispose()
         */
        @Override
         * @see org.eclipse.jface.viewers.IContentProvider#dispose()
         */
        @Override
@@ -38,7 +37,7 @@ public class PolytomousKeyListContentProvider implements
 
        /*
         * (non-Javadoc)
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface
         * .viewers.Viewer, java.lang.Object, java.lang.Object)
         * @see
         * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface
         * .viewers.Viewer, java.lang.Object, java.lang.Object)
@@ -49,17 +48,17 @@ public class PolytomousKeyListContentProvider implements
 
        /*
         * (non-Javadoc)
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java
         * .lang.Object)
         */
        @Override
        public Object[] getElements(Object inputElement) {
         * @see
         * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java
         * .lang.Object)
         */
        @Override
        public Object[] getElements(Object inputElement) {
-               if (inputElement instanceof PolytomousKey) {
+               if (inputElement instanceof PolytomousKeyEditorInput) {
                        List<PolytomousKeyNode> result = new ArrayList<PolytomousKeyNode>();
 
                        List<PolytomousKeyNode> result = new ArrayList<PolytomousKeyNode>();
 
-                       PolytomousKeyNode root = ((PolytomousKey) inputElement).getRoot();
+                       PolytomousKeyNode root = ((PolytomousKeyEditorInput) inputElement).getKey().getRoot();
 
                        getChildrenBreadthFirst(result, root);
                        return result.toArray();
 
                        getChildrenBreadthFirst(result, root);
                        return result.toArray();
index ceae45d69d43fd57c6ea825e9928e868b7ac14f8..cbbeb8b8b1894c60b595c624efe6ec86ac6d3c7f 100644 (file)
@@ -250,7 +250,7 @@ public class PolytomousKeyListEditor extends EditorPart implements
 
                setPartName(key.getTitleCache());
 
 
                setPartName(key.getTitleCache());
 
-               viewer.setInput(key);
+               viewer.setInput(getEditorInput());
        }
 
        public int getTableItemCount() {
        }
 
        public int getTableItemCount() {
@@ -320,11 +320,14 @@ public class PolytomousKeyListEditor extends EditorPart implements
                if (element instanceof PolytomousKeyNode) {
                        List<PolytomousKeyNode> children = ((PolytomousKeyNode) element)
                                        .getParent().getChildren();
                if (element instanceof PolytomousKeyNode) {
                        List<PolytomousKeyNode> children = ((PolytomousKeyNode) element)
                                        .getParent().getChildren();
+                       viewer.update(((PolytomousKeyNode) element)
+                    .getParent(), null);
                        for (PolytomousKeyNode child : children) {
                                viewer.update(child, null);
                        }
                }
 
                        for (PolytomousKeyNode child : children) {
                                viewer.update(child, null);
                        }
                }
 
+
        }
 
     /* (non-Javadoc)
        }
 
     /* (non-Javadoc)
index f45ce48b021ba42043a23a5448c5e02835b9c33a..fcf5b9171a2f5aff639ef5fb6743b17a1985dfd1 100644 (file)
@@ -1,5 +1,5 @@
 /**
 /**
- * 
+ *
  */
 package eu.etaxonomy.taxeditor.editor.key.polytomous.operation;
 
  */
 package eu.etaxonomy.taxeditor.editor.key.polytomous.operation;
 
@@ -9,6 +9,7 @@ import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
@@ -21,7 +22,7 @@ public class CreateNodeOperation extends AbstractPostTaxonOperation {
 
        PolytomousKeyNode parentNode;
        private PolytomousKeyNode childNode;
 
        PolytomousKeyNode parentNode;
        private PolytomousKeyNode childNode;
-       
+
        public CreateNodeOperation(String label,
                        IUndoContext undoContext, PolytomousKeyNode parentNode, IPostOperationEnabled postOperationEnabled) {
                super(label, undoContext, postOperationEnabled);
        public CreateNodeOperation(String label,
                        IUndoContext undoContext, PolytomousKeyNode parentNode, IPostOperationEnabled postOperationEnabled) {
                super(label, undoContext, postOperationEnabled);
@@ -36,9 +37,9 @@ public class CreateNodeOperation extends AbstractPostTaxonOperation {
                        throws ExecutionException {
 
                childNode = PolytomousKeyNode.NewInstance();
                        throws ExecutionException {
 
                childNode = PolytomousKeyNode.NewInstance();
-               
-               parentNode.addChild(childNode);
 
 
+               parentNode.addChild(childNode);
+               childNode = CdmApplicationState.getCurrentAppConfig().getPolytomousKeyNodeService().merge(childNode);
                return postExecute(childNode);
        }
 
                return postExecute(childNode);
        }