From c76a8d3819b17b774ce843dcee0acf544126a41e Mon Sep 17 00:00:00 2001
From: pkupczyk <pkupczyk>
Date: Wed, 21 Nov 2012 08:10:19 +0000
Subject: [PATCH] Bugfix - removing an entity assignment from a metaproject
 should not remove the entity from the Lucene index

SVN: 27728
---
 .../server/business/bo/MetaprojectBO.java     | 48 ++++++-------------
 1 file changed, 14 insertions(+), 34 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MetaprojectBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MetaprojectBO.java
index 8a2c7e941c5..bf3e59cc17d 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MetaprojectBO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/MetaprojectBO.java
@@ -65,9 +65,7 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec
 
     private MetaprojectPE metaproject;
 
-    private Map<Class<?>, List<Long>> addedEntitiesIds;
-
-    private Map<Class<?>, List<Long>> removedEntitiesIds;
+    private Map<Class<?>, List<Long>> changedEntitiesIds;
 
     private boolean dataChanged;
 
@@ -118,7 +116,7 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec
                     "Metaproject with ID '%s' does not exist.", metaprojectId));
         }
 
-        initEntitiesMaps();
+        initChangedEntities();
         dataChanged = false;
     }
 
@@ -133,7 +131,7 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec
                     "Metaproject with ID '%s' does not exist.", metaprojectId));
         }
 
-        initEntitiesMaps();
+        initChangedEntities();
         dataChanged = false;
     }
 
@@ -157,16 +155,10 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec
                 IFullTextIndexUpdateScheduler indexUpdater =
                         getPersistencyResources().getIndexUpdateScheduler();
 
-                for (Map.Entry<Class<?>, List<Long>> addedEntry : addedEntitiesIds.entrySet())
+                for (Map.Entry<Class<?>, List<Long>> changedEntry : changedEntitiesIds.entrySet())
                 {
-                    indexUpdater.scheduleUpdate(IndexUpdateOperation.reindex(addedEntry.getKey(),
-                            addedEntry.getValue()));
-                }
-
-                for (Map.Entry<Class<?>, List<Long>> removedEntry : removedEntitiesIds.entrySet())
-                {
-                    indexUpdater.scheduleUpdate(IndexUpdateOperation.remove(removedEntry.getKey(),
-                            removedEntry.getValue()));
+                    indexUpdater.scheduleUpdate(IndexUpdateOperation.reindex(changedEntry.getKey(),
+                            changedEntry.getValue()));
                 }
 
             } catch (final DataAccessException ex)
@@ -193,7 +185,7 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec
 
         this.metaproject = createMetaproject(metaprojectName, description, ownerId);
 
-        initEntitiesMaps();
+        initChangedEntities();
         dataChanged = true;
     }
 
@@ -304,7 +296,7 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec
                 throw new IllegalArgumentException("Entity for id: " + entityId + " doesn't exist.");
             }
             entityPE.addMetaproject(metaproject);
-            addToAddedEntities(entityPE.getClass(), entityPE.getId());
+            addToChangedEntities(entityPE.getClass(), entityPE.getId());
         }
         dataChanged = true;
     }
@@ -317,7 +309,7 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec
             if (entityPE != null)
             {
                 entityPE.removeMetaproject(metaproject);
-                addToRemovedEntities(entityPE.getClass(), entityPE.getId());
+                addToChangedEntities(entityPE.getClass(), entityPE.getId());
             }
         }
         dataChanged = true;
@@ -343,30 +335,18 @@ public class MetaprojectBO extends AbstractBusinessObject implements IMetaprojec
         }
     }
 
-    private void initEntitiesMaps()
-    {
-        addedEntitiesIds = new HashMap<Class<?>, List<Long>>();
-        removedEntitiesIds = new HashMap<Class<?>, List<Long>>();
-    }
-
-    private void addToAddedEntities(Class<?> entityClass, Long entityId)
-    {
-        addToEntitiesMap(entityClass, entityId, addedEntitiesIds);
-    }
-
-    private void addToRemovedEntities(Class<?> entityClass, Long entityId)
+    private void initChangedEntities()
     {
-        addToEntitiesMap(entityClass, entityId, removedEntitiesIds);
+        changedEntitiesIds = new HashMap<Class<?>, List<Long>>();
     }
 
-    private void addToEntitiesMap(Class<?> entityClass, Long entityId,
-            Map<Class<?>, List<Long>> entitiesMap)
+    private void addToChangedEntities(Class<?> entityClass, Long entityId)
     {
-        List<Long> ids = entitiesMap.get(entityClass);
+        List<Long> ids = changedEntitiesIds.get(entityClass);
         if (ids == null)
         {
             ids = new ArrayList<Long>();
-            entitiesMap.put(entityClass, ids);
+            changedEntitiesIds.put(entityClass, ids);
         }
         ids.add(entityId);
     }
-- 
GitLab