jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1329195 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: cluster/ClusterNode.java observation/EventState.java observation/EventStateCollection.java
Date Mon, 23 Apr 2012 11:55:41 GMT
Author: mreutegg
Date: Mon Apr 23 11:55:40 2012
New Revision: 1329195

URL: http://svn.apache.org/viewvc?rev=1329195&view=rev
Log:
JCR-3275: Audit log
- add log on external update

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=1329195&r1=1329194&r2=1329195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Mon Apr 23 11:55:40 2012
@@ -892,7 +892,17 @@ public class ClusterNode implements Runn
             }
         }
         try {
-            listener.externalUpdate(record.getChanges(), record.getEvents(),
+            List<EventState> eventStates = record.getEvents();
+
+            String path = getFirstUserId(eventStates)
+                    + "@" + workspace
+                    + ":" + EventState.getCommonPath(eventStates, null);
+
+            updateCount.compareAndSet(Integer.MAX_VALUE, 0);
+            auditLogger.info("[{}] {} {}", new Object[]{updateCount.incrementAndGet(), 
+                    record.getRevision(), path});
+
+            listener.externalUpdate(record.getChanges(), eventStates,
                     record.getTimestamp(), record.getUserData());
         } catch (RepositoryException e) {
             String msg = "Unable to deliver update events: " + e.getMessage();
@@ -1090,4 +1100,11 @@ public class ClusterNode implements Runn
             }
         }
     }
+
+    private String getFirstUserId(List<EventState> eventStates) {
+        if (eventStates == null || eventStates.isEmpty()) {
+            return "";
+        }
+        return eventStates.get(0).getUserId();
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java?rev=1329195&r1=1329194&r2=1329195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
Mon Apr 23 11:55:40 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.observation;
 
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.PropertyId;
@@ -24,15 +25,24 @@ import org.apache.jackrabbit.core.value.
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.CachingPathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
+import org.apache.jackrabbit.spi.commons.conversion.ParsingPathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+
 import javax.jcr.observation.Event;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
+import javax.jcr.NamespaceException;
 import javax.jcr.Session;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.nodetype.NodeType;
 
+import java.util.List;
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -52,6 +62,11 @@ public class EventState {
     private static final Logger log = LoggerFactory.getLogger(EventState.class);
 
     /**
+     * The caching path resolver.
+     */
+    private static CachingPathResolver cachingPathResolver;
+
+    /**
      * The key <code>srcAbsPath</code> in the info map.
      */
     static final String SRC_ABS_PATH = "srcAbsPath";
@@ -865,4 +880,83 @@ public class EventState {
     private static InternalValue createValue(Path path) {
         return InternalValue.create(path);
     }
+
+    /**
+     * Get the longest common path of all event state paths.
+     *
+     * @param events The list of EventState
+     * @param session The associated session; it can be null
+     * @return the longest common path
+     */
+    public static String getCommonPath(List<EventState> events, SessionImpl session)
{
+        String common = null;
+        try {
+            for (int i = 0; i < events.size(); i++) {
+                EventState state = events.get(i);
+                Path parentPath = state.getParentPath();
+                String s;
+                if (session == null) {
+                    s = getJCRPath(parentPath);
+                } else {
+                    s = session.getJCRPath(parentPath);
+                }
+
+                if (common == null) {
+                    common = s;
+                } else if (!common.equals(s)) {
+
+                    // Assign the shorter path to common.
+                    if (s.length() < common.length()) {
+                        String temp = common;
+                        common = s;
+                        s = temp;
+                    }
+
+                    // Find the real common.
+                    while (!s.startsWith(common)) {
+                        int idx = s.lastIndexOf('/');
+                        if (idx < 0) {
+                            break;
+                        }
+                        common = s.substring(0, idx + 1);
+                    }
+                }
+            }
+        } catch (NamespaceException e) {
+            log.debug("Problem in retrieving JCR path", e);
+        }
+        return common;
+    }
+
+    private static String getJCRPath(Path path) {
+ 
+        setupCachingPathResolver();
+
+        String jcrPath;
+        try {
+            jcrPath = cachingPathResolver.getJCRPath(path);
+        } catch (NamespaceException e) {
+            jcrPath = "";
+            log.debug("Problem in retrieving JCR path", e);
+        }
+        return jcrPath;
+    }
+
+    private static void setupCachingPathResolver() {
+        if (cachingPathResolver != null) {
+            return;
+        }
+
+        PathResolver pathResolver = new ParsingPathResolver(PathFactoryImpl.getInstance(),
new NameResolver() {
+            public Name getQName(String name) throws IllegalNameException, NamespaceException
{
+                return null;
+            }
+
+            public String getJCRName(Name name) throws NamespaceException {
+                return name.getLocalName();
+            }
+        });
+
+        cachingPathResolver = new CachingPathResolver(pathResolver);
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java?rev=1329195&r1=1329194&r2=1329195&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
Mon Apr 23 11:55:40 2012
@@ -794,35 +794,6 @@ public final class EventStateCollection 
      * @return the longest common path
      */
     public String getCommonPath() {
-        String common = null;
-        try {
-            for (int i = 0; i < events.size(); i++) {
-                EventState state = events.get(i);
-                String s = session.getJCRPath(state.getParentPath());
-                if (common == null) {
-                    common = s;
-                } else if (!common.equals(s)) {
-
-                    // Assign the shorter path to common.
-                    if (s.length() < common.length()) {
-                        String temp = common;
-                        common = s;
-                        s = temp;
-                    }
-
-                    // Find the real common.
-                    while (!s.startsWith(common)) {
-                        int idx = s.lastIndexOf('/');
-                        if (idx < 0) {
-                            break;
-                        }
-                        common = s.substring(0, idx + 1);
-                    }
-                }
-            }
-        } catch (NamespaceException e) {
-            // ignore
-        }
-        return common;
+        return EventState.getCommonPath(events, session);
     }
 }



Mime
View raw message