Add load capability for MergeResult objects
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 8 Oct 2015 10:44:55 +0000 (12:44 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 8 Oct 2015 10:48:10 +0000 (12:48 +0200)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CacheLoader.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmTransientEntityCacher.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CdmServiceRequestExecutor.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySession.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySession.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/NullSession.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySession.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java

index 526e990e46779b5b09ec00a261e668b6225acc69..62fc5c20ae36ae79eed8f3ddcc89e9f6643ea702 100644 (file)
@@ -25,6 +25,7 @@ import org.springframework.util.ReflectionUtils;
 import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.model.ICdmCacher;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 
 /**
  * @author cmathew
@@ -72,6 +73,8 @@ public class CacheLoader {
         } else if(obj instanceof Pager) {
              load(((Pager)obj).getRecords(), recursive, update);
              return obj;
+        } else if(obj instanceof MergeResult) {
+            return (T) load((MergeResult<CdmBase>)obj, recursive, update);
         }
 
         return obj;
@@ -199,6 +202,13 @@ public class CacheLoader {
     }
 
 
+    public MergeResult<CdmBase> load(MergeResult<CdmBase> mergeResult, boolean recursive, boolean update) {
+        CdmBase cdmBase = load(mergeResult.getMergedEntity(), recursive, update);
+        load(mergeResult.getNewEntities(), recursive, update);
+        return mergeResult;
+    }
+
+
     /**
      * Puts the (Key,Value) pair of ({@link java.util.UUID}, {@link eu.etaxonomy.cdm.model.common.CdmBase}),
      * in the cache corresponding to the given cache id
index 7e67ecd227ce679d42b066cfede1ec5e66f9c27b..7047b190d5d681558aca023a467b3621cdb5d00a 100644 (file)
@@ -34,6 +34,7 @@ import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.api.service.dto.CdmEntityIdentifier;
 import eu.etaxonomy.cdm.model.ICdmCacher;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 
 /**
@@ -184,6 +185,10 @@ public class CdmTransientEntityCacher implements ICdmCacher {
         return result;
     }
 
+    public MergeResult<CdmBase> load(MergeResult<CdmBase> mergeResult, boolean update) {
+        return cacheLoader.load(mergeResult, true, update);
+    }
+
     public CdmModelFieldPropertyFromClass getFromCdmlibModelCache(String className) {
         return cacheLoader.getFromCdmlibModelCache(className);
     }
index fa0a4f14ff3d112e6206ed1b48daf0456a1d76db..065a7f24de067ac0002060dabca232ece0c68cb2 100644 (file)
@@ -12,7 +12,6 @@ import org.springframework.stereotype.Component;
 import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
-import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 
 @Component
@@ -54,13 +53,7 @@ public class CdmServiceRequestExecutor extends CdmAuthenticatedHttpInvokerReques
                 if("merge".equals(currentRemoteInvocation.getMethodName()) ||
                         "save".equals(currentRemoteInvocation.getMethodName()) ||
                         "findWithUpdate".equals(currentRemoteInvocation.getMethodName())) {
-                    if(rir.getValue() instanceof MergeResult) {
-                        MergeResult result = (MergeResult) rir.getValue();
-                        cdmEntitySessionManager.load(result.getMergedEntity(), true);
-                        cdmEntitySessionManager.load(result.getNewEntities(), true);
-                    } else {
-                        rir = new RemoteInvocationResult(cdmEntitySessionManager.load(rir.getValue(), true));
-                    }
+                            rir = new RemoteInvocationResult(cdmEntitySessionManager.load(rir.getValue(), true));
                 } else if(rir.getValue() instanceof UpdateResult){
                     UpdateResult result = (UpdateResult)rir.getValue();
                     if(result.isOk()){
index 5fdfafa9d7b5eb46b3a89a4b42259238f42e1919..150d7d20e2d53756ba3f49130e59eda67e78c0c9 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.log4j.Logger;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
 import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
 
@@ -92,6 +93,14 @@ public class CdmEntitySession implements ICdmEntitySession  {
         return cdmTransientEntityCacher.load(updateResult, update);
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(eu.etaxonomy.cdm.persistence.dto.MergeResult, boolean)
+     */
+    @Override
+    public  <T extends CdmBase> MergeResult<T> load(MergeResult<T> mergeResult, boolean update) {
+        return  cdmTransientEntityCacher.load(mergeResult, update);
+    }
+
     @Override
     public <T extends CdmBase> void  update() {
         Collection<T> rootEntities = getRootEntities();
index 1e5d7d889b77c3f3584158c840f53ed8fd395218..80bc0caba5cd87406ef1ea017d416c63eaf8142a 100644 (file)
@@ -22,6 +22,7 @@ import org.springframework.stereotype.Component;
 
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 
 /**
  * @author cmathew
@@ -161,6 +162,18 @@ public class CdmEntitySessionManager implements ICdmEntitySessionManager {
     }
 
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(eu.etaxonomy.cdm.persistence.dto.MergeResult, boolean)
+     */
+    @Override
+    public MergeResult load(MergeResult mergeResult, boolean update) {
+        if(activeSession == null) {
+            return mergeResult;
+        }
+        return activeSession.load(mergeResult, update);
+    }
+
+
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(java.util.Collection)
      */
@@ -244,7 +257,5 @@ public class CdmEntitySessionManager implements ICdmEntitySessionManager {
         return true;
     }
 
-
-
 }
 
index 22388ed7e5b87827be47628f9c26375c4af6b586..bbd744f77ca2069678df7ab456944461a69e7a79 100644 (file)
@@ -8,6 +8,7 @@ import net.sf.ehcache.statistics.LiveCacheStatistics;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
 
 public interface ICdmEntitySession {
@@ -22,6 +23,8 @@ public interface ICdmEntitySession {
 
        public  UpdateResult load(UpdateResult updateResult, boolean update);
 
+       public  <T extends CdmBase> MergeResult<T> load(MergeResult<T> mergeResult, boolean update);
+
        public <T extends CdmBase> EntityCacherDebugResult debug(T cdmBase);
 
        public <T extends CdmBase> EntityCacherDebugResult debug(Collection<T> cdmBase);
index ea2c7867b79a2b111101adf08654b173e3e996de..f6418aecbcbb10c9bb89b09c5896ad919a92e931 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Collection;
 
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 
 public interface ICdmEntitySessionManager {
 
@@ -27,6 +28,8 @@ public interface ICdmEntitySessionManager {
 
        public abstract UpdateResult load(UpdateResult updateResult, boolean update);
 
+       public abstract MergeResult load(MergeResult mergeResult, boolean update);
+
 
        public abstract <T extends CdmBase> Collection<T> load(Collection<T> cdmBaseList, boolean update);
 
index 615f32a467b18299cf29b7c66e54511650116332..9efd8ec423c075402ad20772a9fdf5accd24c930 100644 (file)
@@ -18,6 +18,7 @@ import net.sf.ehcache.statistics.LiveCacheStatistics;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
 
 /**
@@ -218,4 +219,12 @@ public class NullSession implements ICdmEntitySession {
 
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(eu.etaxonomy.cdm.persistence.dto.MergeResult, boolean)
+     */
+    @Override
+    public <T extends CdmBase> MergeResult<T> load(MergeResult<T> mergeResult, boolean update) {
+        return mergeResult;
+    }
+
 }
index ef72bfa021c366c021aeb87b850aba79d5122646..efe8b7e9301f4cf4f4d7cb4452e3f92256c2f483 100644 (file)
@@ -17,6 +17,7 @@ import net.sf.ehcache.statistics.LiveCacheStatistics;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
@@ -207,5 +208,13 @@ public class MockCdmEntitySession implements ICdmEntitySession  {
 
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(eu.etaxonomy.cdm.persistence.dto.MergeResult, boolean)
+     */
+    @Override
+    public <T extends CdmBase> MergeResult<T> load(MergeResult<T> mergeResult, boolean update) {
+        return mergeResult;
+    }
+
 
 }
index 32467f377a8c2fd8cc59056a683e893eae137f4f..263efab59865ae3c8af3fad4e98797a7b5d60014 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Collection;
 
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.dto.MergeResult;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
@@ -134,4 +135,12 @@ public class MockCdmEntitySessionManager implements ICdmEntitySessionManager {
         return new MockCdmEntitySession();
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#load(eu.etaxonomy.cdm.persistence.dto.MergeResult, boolean)
+     */
+    @Override
+    public MergeResult load(MergeResult mergeResult, boolean update) {
+        return mergeResult;
+    }
+
 }