[exo-jcr-commits] exo-jcr SVN: r539 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 10 04:03:50 EST 2009


Author: nzamosenchuk
Date: 2009-11-10 04:03:50 -0500 (Tue, 10 Nov 2009)
New Revision: 539

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
Log:
EXOJCR-204: Updated test and cache loader

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java	2009-11-10 09:00:50 UTC (rev 538)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java	2009-11-10 09:03:50 UTC (rev 539)
@@ -31,6 +31,7 @@
 import org.exoplatform.services.log.Log;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Modification;
+import org.jboss.cache.Modification.ModificationType;
 import org.jboss.cache.factories.annotations.Inject;
 
 import java.util.List;
@@ -53,8 +54,10 @@
 
    private final Fqn nodeFqn = Fqn.fromString(JBossCacheStorage.NODES);
 
-   private final Fqn propFqn = Fqn.fromString(JBossCacheStorage.PROPS);
+   private final Fqn propertyFqn = Fqn.fromString(JBossCacheStorage.PROPS);
 
+   private final Fqn sessionFqn = Fqn.fromString(JBossCacheStorage.SESSION);
+
    private ObservationManagerRegistry observationManagerRegistry = null;
 
    /**
@@ -78,12 +81,9 @@
    {
 
       // get SessionID from list
-      // TODO: get real user ID
-      String userId = "admin-dummy-id";
-
+      String userId = "";
       // get UserID from list
-      // TODO: get real session ID
-      String sessionId = "user-session-dummy-id";
+      String sessionId = "";
 
       // extract real list from list of modification
       // real - means list with out fake modifications containing UserID & etc
@@ -105,35 +105,47 @@
             for (Modification m : modifications)
             {
 
-               if (m.getFqn().isDirectChildOf(nodeFqn) || m.getFqn().isDirectChildOf(propFqn))
+               if (isItemSubtree(m))
                {
                   ItemData item = getItemData(m);
                   // TODO: remove hardcode
-                  if (item == null)
+                  if (item != null)
                   {
-                     break;
+                     int eventType = eventType(m);
+                     boolean result = true;
+                     // check event type
+                     result &= isTypeMatch(criteria, eventType);
+                     // check Path
+                     result &= isPathMatch(criteria, item);
+                     // check UUID
+                     result &= isIdentifierMatch(criteria, item);
+                     // check NodeType
+                     // TODO: FIX nodetype checks
+                     //result &= isNodeTypeMatch(criteria, item, changesLog);
+                     // check session
+                     result &= isSessionMatch(criteria, sessionId);
+                     if (result)
+                     {
+                        String path =
+                           observationManagerRegistry.getLocationFactory().createJCRPath(item.getQPath()).getAsString(
+                              false);
+                        events.add(new EventImpl(eventType, path, userId));
+                     }
                   } // it wasn't able to retrive item's data
-                  int eventType = eventType(m);
-                  boolean result = true;
-                  // check event type
-                  result &= isTypeMatch(criteria, eventType);
-                  // check Path
-                  result &= isPathMatch(criteria, item);
-                  // check UUID
-                  result &= isIdentifierMatch(criteria, item);
-                  // check NodeType
-                  // TODO: FIX nodetype checks
-                  //result &= isNodeTypeMatch(criteria, item, changesLog);
-                  // check session
-                  result &= isSessionMatch(criteria, sessionId);
-                  if (result)
-                  {
-                     String path =
-                        observationManagerRegistry.getLocationFactory().createJCRPath(item.getQPath()).getAsString(
-                           false);
-                     events.add(new EventImpl(eventType, path, userId));
-                  }
                }
+               // if this is session
+               else if (isSessionSubtree(m))
+               {
+                  if (m.getType() == ModificationType.PUT_KEY_VALUE){
+                     if (m.getKey().equals(JBossCacheStorage.SESSION_ID))
+                        sessionId = (String)m.getValue();
+                     else if (m.getKey().equals(JBossCacheStorage.USER_ID))
+                        userId = (String)m.getValue();}
+                     else if (m.getType() == ModificationType.REMOVE_NODE){
+                        sessionId = "";
+                        userId = "";
+                     }
+               }
             }
 
             if (events.size() > 0)
@@ -159,7 +171,7 @@
                   // node added
                   return Event.NODE_ADDED;
                }
-               else if (modification.getFqn().isDirectChildOf(propFqn))
+               else if (modification.getFqn().isDirectChildOf(propertyFqn))
                {
                   // property added or changed
                   if (modification.getOldValue() != null)
@@ -182,7 +194,7 @@
                // node removed
                return Event.NODE_REMOVED;
             }
-            else if (modification.getFqn().isDirectChildOf(propFqn))
+            else if (modification.getFqn().isDirectChildOf(propertyFqn))
             {
                // property removed
                return Event.PROPERTY_REMOVED;
@@ -206,7 +218,6 @@
 
    private boolean isIdentifierMatch(ListenerCriteria criteria, ItemData item)
    {
-
       if (criteria.getIdentifier() == null)
          return true;
       // for each uuid in list
@@ -217,19 +228,24 @@
             return true;
       }
       return false;
-
    }
 
+   /**
+    * Check associated parent node path.
+    * 
+    * @param criteria
+    * @param item
+    * @return
+    */
    private boolean isPathMatch(ListenerCriteria criteria, ItemData item)
    {
       if (criteria.getAbsPath() == null)
          return true;
-      // 8.3.3 Only events whose associated parent node is at absPath (or
-      // within its subtree, if isDeep is true) will be received.
       QPath itemPath = item.getQPath();
       return itemPath.isDescendantOf(criteria.getAbsPath(), !criteria.isDeep());
    }
 
+   // shoud be changed in order to obtain parent's data elsewhere. Cache is not accessible from cacheloader.put(List)
    @Deprecated
    private boolean isNodeTypeMatch(ListenerCriteria criteria, ItemData item, List<Modification> modifications)
       throws RepositoryException
@@ -282,9 +298,23 @@
       return false;
    }
 
+   protected boolean isItemSubtree(Modification modification)
+   {
+      return modification.getFqn().isDirectChildOf(nodeFqn) || modification.getFqn().isDirectChildOf(propertyFqn);
+   }
+
+   protected boolean isSessionSubtree(Modification modification)
+   {
+      return modification.getFqn().isDirectChildOf(sessionFqn) || modification.getFqn().isChildOrEquals(sessionFqn);
+   }
+
    protected ItemData getItemData(Modification m)
    {
-      return (ItemData)m.getValue();
+      if (m.getValue() instanceof ItemData)
+      {
+         return (ItemData)m.getValue();
+      }
+      return null;
    }
 
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java	2009-11-10 09:00:50 UTC (rev 538)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java	2009-11-10 09:03:50 UTC (rev 539)
@@ -103,15 +103,17 @@
             Constants.ROOT_UUID, new AccessControlList());
       DummyListener listener = new DummyListener();
       registry.addEventListener(listener, new ListenerCriteria(Event.NODE_ADDED, null, true,
-         new String[]{Constants.ROOT_UUID}, null, false, "asd"));
+         new String[]{Constants.ROOT_UUID}, null, false, "session1"));
 
-      List<Modification> modifications = new ArrayList<Modification>();
+      List<Modification> modifications = new ArrayList<Modification>(setSession("session1", "admin"));
       modifications.addAll(addNode(newNode));
+      modifications.addAll(removeSession());
       loader.put(modifications);
       assertEquals(1, listener.eventList.size());
       Event event = listener.eventList.get(0);
       assertEquals(Event.NODE_ADDED, event.getType());
       assertEquals(lf.createJCRPath(node1path).getAsString(false), event.getPath());
+      assertEquals("admin", event.getUserID());
    }
 
    public void testAddNode() throws Exception
@@ -122,15 +124,14 @@
             Constants.ROOT_UUID, new AccessControlList());
       DummyListener listener = new DummyListener();
       registry.addEventListener(listener, new ListenerCriteria(Event.NODE_ADDED,
-         lf.parseAbsPath("/").getInternalPath(), true, null, null, false, "asd"));
+         lf.parseAbsPath("/").getInternalPath(), true, null, null, false, "session1"));
 
-      List<Modification> modifications = new ArrayList<Modification>();
+      List<Modification> modifications = new ArrayList<Modification>(setSession("session1", "admin"));
       modifications.addAll(addNode(newNode));
+      modifications.addAll(removeSession());
       loader.put(modifications);
-      assertEquals(1, listener.eventList.size());
-      Event event = listener.eventList.get(0);
-      assertEquals(Event.NODE_ADDED, event.getType());
-      assertEquals(lf.createJCRPath(node1path).getAsString(false), event.getPath());
+
+      assertEvent(Event.NODE_ADDED, node1path, listener, "admin");
    }
 
    public void testRemoveNode() throws Exception
@@ -141,15 +142,14 @@
             Constants.ROOT_UUID, new AccessControlList());
       DummyListener listener = new DummyListener();
       registry.addEventListener(listener, new ListenerCriteria(Event.NODE_REMOVED, lf.parseAbsPath("/")
-         .getInternalPath(), true, null, null, false, "asd"));
+         .getInternalPath(), true, null, null, false, "session1"));
 
-      List<Modification> modifications = new ArrayList<Modification>();
+      List<Modification> modifications = new ArrayList<Modification>(setSession("session1", "admin"));
       modifications.addAll(removeNode(newNode));
+      modifications.addAll(removeSession());
       loader.put(modifications);
-      assertEquals(1, listener.eventList.size());
-      Event event = listener.eventList.get(0);
-      assertEquals(Event.NODE_REMOVED, event.getType());
-      assertEquals(lf.createJCRPath(node1path).getAsString(false), event.getPath());
+
+      assertEvent(Event.NODE_REMOVED, node1path, listener, "admin");
    }
 
    public void testAddProperty() throws Exception
@@ -160,15 +160,14 @@
 
       DummyListener listener = new DummyListener();
       registry.addEventListener(listener, new ListenerCriteria(Event.PROPERTY_ADDED, lf.parseAbsPath("/")
-         .getInternalPath(), true, null, null, false, "asd"));
+         .getInternalPath(), true, null, null, false, "session1"));
 
-      List<Modification> modifications = new ArrayList<Modification>();
+      List<Modification> modifications = new ArrayList<Modification>(setSession("session1", "admin"));
       modifications.addAll(addProperty(newProperty));
+      modifications.addAll(removeSession());
       loader.put(modifications);
-      assertEquals(1, listener.eventList.size());
-      Event event = listener.eventList.get(0);
-      assertEquals(Event.PROPERTY_ADDED, event.getType());
-      assertEquals(lf.createJCRPath(prop1path).getAsString(false), event.getPath());
+
+      assertEvent(Event.PROPERTY_ADDED, prop1path, listener, "admin");
    }
 
    public void testUpdateProperty() throws Exception
@@ -179,15 +178,14 @@
 
       DummyListener listener = new DummyListener();
       registry.addEventListener(listener, new ListenerCriteria(Event.PROPERTY_CHANGED, lf.parseAbsPath("/")
-         .getInternalPath(), true, null, null, false, "asd"));
+         .getInternalPath(), true, null, null, false, "session1"));
 
-      List<Modification> modifications = new ArrayList<Modification>();
+      List<Modification> modifications = new ArrayList<Modification>(setSession("session1", "admin"));
       modifications.addAll(updateProperty(newProperty));
+      modifications.addAll(removeSession());
       loader.put(modifications);
-      assertEquals(1, listener.eventList.size());
-      Event event = listener.eventList.get(0);
-      assertEquals(Event.PROPERTY_CHANGED, event.getType());
-      assertEquals(lf.createJCRPath(prop1path).getAsString(false), event.getPath());
+
+      assertEvent(Event.PROPERTY_CHANGED, prop1path, listener, "admin");
    }
 
    public void testRemoveProperty() throws Exception
@@ -198,15 +196,24 @@
 
       DummyListener listener = new DummyListener();
       registry.addEventListener(listener, new ListenerCriteria(Event.PROPERTY_REMOVED, lf.parseAbsPath("/")
-         .getInternalPath(), true, null, null, false, "asd"));
+         .getInternalPath(), true, null, null, false, "session1"));
 
-      List<Modification> modifications = new ArrayList<Modification>();
+      List<Modification> modifications = new ArrayList<Modification>(setSession("session1", "admin"));
       modifications.addAll(removeProperty(newProperty));
+      modifications.addAll(removeSession());
       loader.put(modifications);
+
+      assertEvent(Event.PROPERTY_REMOVED, prop1path, listener, "admin");
+   }
+
+   protected void assertEvent(int eventType, QPath prop1path, DummyListener listener, String userId)
+      throws RepositoryException
+   {
       assertEquals(1, listener.eventList.size());
       Event event = listener.eventList.get(0);
-      assertEquals(Event.PROPERTY_REMOVED, event.getType());
+      assertEquals(eventType, event.getType());
       assertEquals(lf.createJCRPath(prop1path).getAsString(false), event.getPath());
+      assertEquals(userId, event.getUserID());
    }
 
    @Override
@@ -222,17 +229,14 @@
          super(null, null, null);
       }
 
-      // TODO: remove hardcode
       public LocationFactory getLocationFactory()
       {
          return lf;
       }
-
    }
 
    class DummyListener implements EventListener
    {
-
       public List<Event> eventList = new ArrayList<Event>();
 
       public void onEvent(EventIterator events)



More information about the exo-jcr-commits mailing list