CdmTransientEntityCacher : overriding cache field only in the case of initialised...
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 12 Feb 2015 08:47:26 +0000 (08:47 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 12 Feb 2015 08:47:26 +0000 (08:47 +0000)
CdmEntitySession, ICdmEntitySession, MockCdmEntitySession : added update + delete methods
DeleteSynonymOperation, MoveFactualDataHandler : changed service call to uuid one
ChangeAcceptedTaxonToSynonymOperation, DeleteOperation, MoveTaxonOperation : calling newly added session update , insert delete methods

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmTransientEntityCacher.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/ICdmEntitySession.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySession.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteSynonymOperation.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientTaxonService.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveFactualDataHandler.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/ChangeAcceptedTaxonToSynonymOperation.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java

index ffdc3fbc82ed04f32f45225de67c8493279a2a04..869d3deed150c1998a526a73c35fcb7264e96704 100644 (file)
@@ -386,10 +386,7 @@ public class CdmTransientEntityCacher  {
                     field.set(cdmEntity, o);
                 }
             }
-            // making sure that the field in cached cdm entity is always
-            // up-to-date by setting to the value of the cdm entity being loaded
-            // the only execption to this is found below
-            field.set(cachedCdmEntity, o);
+
             //field.set(cdmEntity, o);
             CdmBase cdmEntityInSubGraph = null;
             if(o != null
@@ -400,6 +397,10 @@ public class CdmTransientEntityCacher  {
                     logger.info("found initialised cdm entity '" + fieldName + "' in object of type " + clazz.getName() + " with id " + cdmEntity.getId());
                     cdmEntityInSubGraph  = (CdmBase)o;
                     CdmBase cachedCdmEntityInSubGraph = getFromCache(cdmEntityInSubGraph);
+                    // making sure that the field in cached cdm entity is always
+                    // up-to-date by setting to the value of the cdm entity being loaded
+                    // the only execption to this is found below
+                    field.set(cachedCdmEntity, o);
                     // the only exception to updating the field to the latest value
                     // is the case where the field has been already initialised, cached and
                     // is not the same as the one in the cache, in which case we set the value
index 2cb27c83c881db7512c887bae47b47079ce1bccb..a8b968e845090daede6909fb9cea3526c64eb731 100644 (file)
@@ -78,16 +78,27 @@ public class CdmEntitySession implements ICdmEntitySession  {
     }
 
     @Override
-    public void update(CdmBase cdmBase, Set<CdmBase> affectedObjects) {
+    public <T extends ICdmBase> void update(T cdmBase, Set<CdmBase> affectedObjects) {
         load(cdmBase);
         addEvent(cdmBase, affectedObjects, EventType.UPDATE);
     }
 
     @Override
-    public void delete(ICdmBase cdmBase, Set<CdmBase> affectedObjects) {
+    public <T extends ICdmBase> void delete(T cdmBase, Set<CdmBase> affectedObjects) {
+        for(CdmBase cb : affectedObjects) {
+            load(cb);
+        }
         addEvent(cdmBase, affectedObjects, EventType.DELETE);
     }
 
+    @Override
+    public <T extends ICdmBase> void delete(Set<T> cdmBases, Set<CdmBase> affectedObjects) {
+        for(CdmBase cb : affectedObjects) {
+            load(cb);
+        }
+        addEvent(cdmBases, affectedObjects, EventType.DELETE);
+    }
+
 
 
     /* (non-Javadoc)
index 17e7f41ffd37cddf150f3dc8ca9d64bd5c407b0a..62ce7df1b58d03036c4f63672a0df652721b0346 100644 (file)
@@ -50,13 +50,19 @@ public interface ICdmEntitySession {
      * @param cdmBase
      * @param affectedObjects
      */
-    public void update(CdmBase cdmBase, Set<CdmBase> affectedObjects);
+    public <T extends ICdmBase> void update(T cdmBase, Set<CdmBase> affectedObjects);
 
     /**
      * @param cdmBase
      * @param affectedObjects
      */
-    public void delete(ICdmBase cdmBase, Set<CdmBase> affectedObjects);
+    public <T extends ICdmBase> void delete(T cdmBase, Set<CdmBase> affectedObjects);
+
+    /**
+     * @param cdmBase
+     * @param affectedObjects
+     */
+    public <T extends ICdmBase> void delete(Set<T> cdmBases, Set<CdmBase> affectedObjects);
 
     /**
      *
index c12a5bc413d9080b7f2d19345cf65b2009270a37..b5e72af4f507252831f2963019c48509c093fcbc 100644 (file)
@@ -171,7 +171,7 @@ public class MockCdmEntitySession implements ICdmEntitySession  {
      * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#update(eu.etaxonomy.cdm.model.common.ICdmBase, java.util.Set)
      */
     @Override
-    public void update(CdmBase cdmBase, Set<CdmBase> affectedObjects) {
+    public <T extends ICdmBase> void update(T cdmBase, Set<CdmBase> affectedObjects) {
         // TODO Auto-generated method stub
 
     }
@@ -180,7 +180,16 @@ public class MockCdmEntitySession implements ICdmEntitySession  {
      * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#delete(eu.etaxonomy.cdm.model.common.ICdmBase, java.util.Set)
      */
     @Override
-    public void delete(ICdmBase cdmBase, Set<CdmBase> affectedObjects) {
+    public <T extends ICdmBase> void delete(T cdmBase, Set<CdmBase> affectedObjects) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#delete(java.util.Set, java.util.Set)
+     */
+    @Override
+    public <T extends ICdmBase> void delete(Set<T> cdmBases, Set<CdmBase> affectedObjects) {
         // TODO Auto-generated method stub
 
     }
index 9cdf90fc566f11606278881c901a4633761de2d6..c7660d5bc5810c2a7c2abbd2147b3b7a1c144f74 100644 (file)
@@ -71,15 +71,15 @@ public class DeleteSynonymOperation extends AbstractPostTaxonOperation {
 
                                ICdmApplicationConfiguration controller;
 
-                               controller = (ICdmApplicationConfiguration) CdmStore.getCurrentApplicationConfiguration();
+                               controller = CdmStore.getCurrentApplicationConfiguration();
 
                                ITaxonService service = controller.getTaxonService();
                                if (synonym.getId() == 0){
                                        element.removeSynonym(synonym);
 
                                } else {
-                                       
-                                       DeleteResult result = service.deleteSynonym(synonym, null);
+
+                                       DeleteResult result = service.deleteSynonym(synonym.getUuid(), element.getUuid(), null);
                                        if (result.isError()){
                                                MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
                                        }
index a507e21147cccd1d773e2ad1142aa78206742ba8..29ddb9aad9c8d1a607c02ecdad5ac9f9b20b9510 100644 (file)
@@ -1418,6 +1418,14 @@ public class TransientTaxonService implements ITaxonService {
            return defaultService.findByIdentifier(clazz, identifier, identifierType, subtreeFilter, matchmode, includeEntity, pageSize, pageNumber, propertyPaths);
        }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.api.service.ITaxonService#deleteSynonym(java.util.UUID, java.util.UUID, eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator)
+     */
+    @Override
+    public DeleteResult deleteSynonym(UUID synonymUuid, UUID taxonUuid, SynonymDeletionConfigurator config) {
+        return defaultService.deleteSynonym(synonymUuid, taxonUuid, config);
+    }
+
 
 
 
index f29211d55beff57be12f0eae7ad9d088c89c384b..c33d9ff125030bf14131eee0d93c5c7bf33a2888 100644 (file)
@@ -76,8 +76,7 @@ public class MoveFactualDataHandler extends AbstractHandler {
                                 "changes in the target taxon. Please save first.");
                         return null;
                     }
-                    CdmStore.getService(IDescriptionService.class).moveTaxonDescriptions(taxon.getUuid(),
-                            targetTaxonNode.getTaxon().getUuid());
+                    CdmStore.getService(IDescriptionService.class).moveTaxonDescriptions(taxon.getUuid(),targetTaxonNode.getTaxon().getUuid());
 
                     navigator.getConversationHolder().bind();
                     navigator.getConversationHolder().commit();
index d1ad8533c8437d0cf44c376c37f2fd7023b5b360..81a4af179e8f15b98267d2ad0f4981a0cb6aa3cb 100644 (file)
@@ -10,6 +10,9 @@
 
 package eu.etaxonomy.taxeditor.navigation.navigator.operation;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;
@@ -20,11 +23,11 @@ import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -81,7 +84,13 @@ public class ChangeAcceptedTaxonToSynonymOperation extends
        Taxon oldTaxon = (Taxon) HibernateProxyHelper.deproxy(((TaxonNode) taxonNode).getTaxon());
 
                synonym = CdmStore.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(taxonNode.getUuid(), newAcceptedTaxonNode.getUuid(), null, null, null);
-               cdmEntitySessionEnabled.getCdmEntitySession().addEvent(taxonNode, EventType.UPDATE);
+               Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
+               for(Taxon taxon : synonym.getAcceptedTaxa()) {
+                   affectedObjects.addAll(taxon.getTaxonNodes());
+               }
+               //FIXME:Remoting add new taxonNode.getParent to affectedObjects
+
+               cdmEntitySessionEnabled.getCdmEntitySession().update(synonym, affectedObjects);
 
                monitor.worked(40);
                return postExecute(oldTaxon);
index 6ae0663e6e3184250aa7e5b93c651c9bab39a0a0..c450209d60d911157bd56ca7ca124317b4e1a7fd 100644 (file)
@@ -31,7 +31,6 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
@@ -103,6 +102,7 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
         monitor.worked(20);
         ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
         ITaxonNodeService service = controller.getTaxonNodeService();
+        Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
 
         if(taxonNode != null && taxonNode instanceof TaxonNode){
             //((TaxonNode) treeNode).delete();
@@ -113,8 +113,10 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
             if (result.isError()){
                 //TODO:Error message!
                 MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
+            } else {
+                affectedObjects.add(((TaxonNode)taxonNode).getParent());
+                cdmEntitySessionEnabled.getCdmEntitySession().delete(taxonNode, affectedObjects);
             }
-            cdmEntitySessionEnabled.getCdmEntitySession().addEvent(taxonNode, EventType.DELETE);
 
         }else if(taxonNode != null && taxonNode instanceof Classification){
             Classification taxonomicTree = (Classification) taxonNode;
@@ -128,16 +130,10 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
             if (result.isError()){
                 //TODO:Error message!
                 MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
+            } else {
+                affectedObjects.add(((TaxonNode)taxonNode).getParent());
+                cdmEntitySessionEnabled.getCdmEntitySession().delete(taxonomicTree, affectedObjects);
             }
-
-            /*}else{
-                                       try{
-                                       CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
-                                       }catch(ReferencedObjectUndeletableException e){
-                                               throw new ExecutionException(e.getMessage());
-                                       }
-                               }*/
-            cdmEntitySessionEnabled.getCdmEntitySession().addEvent(taxonomicTree, EventType.DELETE);
         } else {
             Set<UUID> treeNodeUuids = new HashSet<UUID>();
             for(ITaxonTreeNode treeNode : treeNodes) {
@@ -148,7 +144,11 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
                 //TODO:Error message!
                 MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
             }
-            cdmEntitySessionEnabled.getCdmEntitySession().addEvent(treeNodes, EventType.DELETE);
+
+            for(ITaxonTreeNode treeNode : treeNodes) {
+                affectedObjects.add(((TaxonNode)treeNode).getParent());
+            }
+            cdmEntitySessionEnabled.getCdmEntitySession().delete(treeNodes, affectedObjects);
         }
 
         monitor.worked(40);
index 6a8187a4d94f6ba11ea8247765b5cba59edbc45c..c65b17388fe4282b3aa9c3cc6e9968349f4e22c1 100644 (file)
@@ -10,6 +10,7 @@
 package eu.etaxonomy.taxeditor.navigation.navigator.operation;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -22,10 +23,10 @@ import org.eclipse.core.runtime.Status;
 
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.IllegalAncestryException;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
@@ -52,6 +53,7 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation {
 
        private final Set<TaxonNode> taxonNodes;
 
+       private final ICdmEntitySessionEnabled cdmEntitySessionEnabled;
        /**
         * <p>Constructor for MoveTaxonOperation.</p>
         *
@@ -80,6 +82,8 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation {
                for(TaxonNode taxonNode : taxonNodes){
                        this.oldParentTreeNodes.put(taxonNode, taxonNode.getParent());
                }
+
+               this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
        }
 
        /* (non-Javadoc)
@@ -92,16 +96,19 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation {
                bind();
                monitor.worked(20);
 
+               Set<CdmBase> affectedObjects = new HashSet<CdmBase>();
                try {
                        for (TaxonNode taxonNode : taxonNodes){
-                               TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode,
-                                               newParentTreeNode.getReference(), newParentTreeNode.getMicroReference());
-                               taxonNodes.add(newTaxonNode);
-
+                           TaxonNode newTaxonNode = CdmStore.getService( ITaxonNodeService.class).moveTaxonNode(taxonNode.getUuid(), newParentTreeNode.getUuid());
+                               affectedObjects.add(newTaxonNode.getParent());
+                               //FIXME:Remoting testing until UpdateResult is ready
+                               affectedObjects.add(newTaxonNode.getParent().getParent());
+                               cdmEntitySessionEnabled.getCdmEntitySession().update(newTaxonNode, affectedObjects);
                                monitor.worked(2);
                        }
-                       CdmStore.getService( ITaxonNodeService.class).merge((TaxonNode)newParentTreeNode);
-                       CdmStore.getCurrentSessionManager().getActiveSession().addEvent(newParentTreeNode, EventType.UPDATE);
+
+
+
                } catch(IllegalAncestryException e) {
                        MessagingUtils.warningDialog("Illegal ancestry", this, e.getMessage());
                }