jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1490650 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java oak-jcr/pom.xml
Date Fri, 07 Jun 2013 13:56:43 GMT
Author: mduerig
Date: Fri Jun  7 13:56:43 2013
New Revision: 1490650

URL: http://svn.apache.org/r1490650
Log:
OAK-775 Implement backward compatible observation
add support for Event.getIdentifier()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java?rev=1490650&r1=1490649&r2=1490650&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
Fri Jun  7 13:56:43 2013
@@ -33,8 +33,10 @@ import javax.jcr.observation.EventListen
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Iterators;
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.iterator.EventIteratorAdapter;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.observation.ChangeDispatcher.ChangeSet;
@@ -192,22 +194,26 @@ class ChangeProcessor implements Runnabl
         private final ChangeSet changes;
         private final String path;
         private final NodeState associatedParentNode;
+        private final EventGeneratingNodeStateDiff parent;
+        private final String name;
 
         private List<Iterator<Event>> events;
         private int childNodeCount;
 
         EventGeneratingNodeStateDiff(ChangeSet changes, String path, List<Iterator<Event>>
events,
-                NodeState associatedParentNode) {
+                NodeState associatedParentNode, EventGeneratingNodeStateDiff parent, String
name) {
 
             this.changes = changes;
             this.path = path;
             this.events = events;
             this.associatedParentNode = associatedParentNode;
+            this.parent = parent;
+            this.name = name;
         }
 
         public EventGeneratingNodeStateDiff(ChangeSet changes) {
             // FIXME associatedParentNode should be the root node here
-            this(changes, "/", new ArrayList<Iterator<Event>>(PURGE_LIMIT), null);
+            this(changes, "/", new ArrayList<Iterator<Event>>(PURGE_LIMIT), null,
null, "");
         }
 
         public void sendEvents() {
@@ -286,33 +292,46 @@ class ChangeProcessor implements Runnabl
         public RecursingNodeStateDiff createChildDiff(String name, NodeState before, NodeState
after) {
             if (filterRef.get().includeChildren(jcrPath())) {
                 EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(
-                        changes, PathUtils.concat(path, name), events, after);
+                        changes, PathUtils.concat(path, name), events, after, this, name);
                 return VisibleDiff.wrap(diff);
             } else {
                 return new RecursingNodeStateDiff();
             }
         }
 
-        private EventImpl createEvent(int eventType, String jcrPath) {
+        private EventImpl createEvent(int eventType, String jcrPath, String id) {
             // TODO support identifier, info
             return new EventImpl(ChangeProcessor.this, eventType, jcrPath, changes.getUserId(),
-                    null, null, changes.getDate(), userDataRef.get(), changes.isExternal());
+                    id, null, changes.getDate(), userDataRef.get(), changes.isExternal());
+        }
+
+        private String getId(String childName) {
+            if (parent == null) {
+                return '/' + namePathMapper.getJcrName(childName);
+            }
+
+            PropertyState uuid = associatedParentNode.getProperty(JcrConstants.JCR_UUID);
+            if (uuid == null) {
+                return parent.getId(name) + '/' + namePathMapper.getJcrName(childName);
+            }
+
+            return uuid.getValue(Type.STRING);
         }
 
         private Event generatePropertyEvent(int eventType, String parentPath, PropertyState
property) {
             String jcrPath = namePathMapper.getJcrPath(PathUtils.concat(parentPath, property.getName()));
-            return createEvent(eventType, jcrPath);
+            return createEvent(eventType, jcrPath, parent.getId(name));
         }
 
-        private Iterator<Event> generateNodeEvents(int eventType, String parentPath,
String name, NodeState node) {
+        private Iterator<Event> generateNodeEvents(int eventType, String parentPath,
String childName, NodeState node) {
             EventFilter filter = filterRef.get();
-            final String path = PathUtils.concat(parentPath, name);
+            final String path = PathUtils.concat(parentPath, childName);
             String jcrParentPath = namePathMapper.getJcrPath(parentPath);
             String jcrPath = namePathMapper.getJcrPath(path);
 
             Iterator<Event> nodeEvent;
             if (filter.include(eventType, jcrParentPath, associatedParentNode)) {
-                Event event = createEvent(eventType, jcrPath);
+                Event event = createEvent(eventType, jcrPath, getId(childName));
                 nodeEvent = Iterators.singletonIterator(event);
             } else {
                 nodeEvent = Iterators.emptyIterator();

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1490650&r1=1490649&r2=1490650&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Fri Jun  7 13:56:43 2013
@@ -225,12 +225,8 @@
       org.apache.jackrabbit.test.api.observation.NodeMovedTest#testMoveNode
       org.apache.jackrabbit.test.api.observation.NodeMovedTest#testMoveTree
       org.apache.jackrabbit.test.api.observation.NodeMovedTest#testMoveWithRemove
-      org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeAdded
       org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeMoved
-      org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeRemoved
       org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testPropertyAdded
-      org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testPropertyChanged
-      org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testPropertyRemoved
       org.apache.jackrabbit.test.api.observation.LockingTest#testAddLockToNode
       org.apache.jackrabbit.test.api.observation.LockingTest#testRemoveLockFromNode
       <!-- Versioning -->



Mime
View raw message