sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1636530 - in /sling/trunk/contrib/extensions/replication: core/src/main/java/org/apache/sling/replication/component/impl/ core/src/main/java/org/apache/sling/replication/trigger/impl/ core/src/test/java/org/apache/sling/replication/trigger...
Date Tue, 04 Nov 2014 09:48:59 GMT
Author: tommaso
Date: Tue Nov  4 09:48:59 2014
New Revision: 1636530

URL: http://svn.apache.org/r1636530
Log:
SLING-4128 - fixed nuggets path initialization

Modified:
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/component/impl/SettingsUtils.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java
    sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java
    sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTriggerTest.java
    sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.component.impl.GenericReplicationComponentFactory-trigger-test-persisting-event.json

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/component/impl/SettingsUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/component/impl/SettingsUtils.java?rev=1636530&r1=1636529&r2=1636530&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/component/impl/SettingsUtils.java
(original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/component/impl/SettingsUtils.java
Tue Nov  4 09:48:59 2014
@@ -37,7 +37,8 @@ public class SettingsUtils {
 
         if (value instanceof String[]) {
             return compactMap(SettingsUtils.toMap((String[]) value));
-
+        } else if (value instanceof String) {
+            return compactMap(SettingsUtils.toMap(((String) value).split(",")));
         }
         return null;
     }

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java?rev=1636530&r1=1636529&r2=1636530&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java
(original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/AbstractJcrEventTrigger.java
Tue Nov  4 09:48:59 2014
@@ -99,6 +99,7 @@ public abstract class AbstractJcrEventTr
         }
 
         public void onEvent(EventIterator eventIterator) {
+            log.info("handling event {}");
             while (eventIterator.hasNext()) {
                 Event event = eventIterator.nextEvent();
                 try {

Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java?rev=1636530&r1=1636529&r2=1636530&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java
(original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTrigger.java
Tue Nov  4 09:48:59 2014
@@ -22,7 +22,6 @@ import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.observation.Event;
-import javax.jcr.security.Privilege;
 import java.util.Map;
 import java.util.Set;
 
@@ -48,12 +47,12 @@ public class PersistingJcrEventReplicati
 
     public PersistingJcrEventReplicationTrigger(SlingRepository repository, String path,
String servicename, String nuggetsPath) {
         super(repository, path, servicename);
-        this.nuggetsPath = nuggetsPath == null ? DEFAULT_NUGGETS_PATH : nuggetsPath;
+        this.nuggetsPath = nuggetsPath == null || nuggetsPath.length() == 0 ? DEFAULT_NUGGETS_PATH
: nuggetsPath;
     }
 
     @Override
     protected ReplicationRequest processEvent(Event event) throws RepositoryException {
-        log.debug("processing event {}", event);
+        log.info("processing event {}", event);
 
         ReplicationRequest replicationRequest = null;
 
@@ -63,8 +62,8 @@ public class PersistingJcrEventReplicati
             initializeNuggetsPath(session);
         }
 
-        if (session.hasPermission(nuggetsPath, Privilege.JCR_ADD_CHILD_NODES)) {
-            log.debug("persisting event under {}", nuggetsPath);
+        if (session.hasPermission(nuggetsPath, Session.ACTION_ADD_NODE)) {
+            log.info("persisting event under {}", nuggetsPath);
             Node nuggetsNode = session.getNode(nuggetsPath);
             if (nuggetsNode != null) {
                 String nodeName = event.getIdentifier() != null ? event.getIdentifier() :
String.valueOf(System.nanoTime());
@@ -82,7 +81,7 @@ public class PersistingJcrEventReplicati
                         nuggetsNode.setProperty("info." + entry.getKey(), String.valueOf(entry.getValue()));
                     }
                     session.save();
-                    log.debug("event persisted at {}", path);
+                    log.info("event persisted at {}", path);
                     replicationRequest = new ReplicationRequest(System.currentTimeMillis(),
ReplicationActionType.ADD, path);
                 } else {
                     log.warn("could not create node {}", nuggetsPath + "/" + nodeName);
@@ -98,21 +97,28 @@ public class PersistingJcrEventReplicati
     }
 
     private void initializeNuggetsPath(Session session) throws RepositoryException {
+        log.info("initializing nuggets path");
         if (session != null) {
             Node parent = session.getRootNode();
-            if (session.hasPermission(parent.getPath(), Privilege.JCR_ADD_CHILD_NODES)) {
+            if (session.hasPermission(parent.getPath(), Session.ACTION_ADD_NODE)) {
                 for (String nodeName : nuggetsPath.split("/")) {
-                    if (!parent.hasNode(nodeName)) {
-                        parent = parent.addNode(nodeName, "sling:Folder");
-                    } else {
-                        parent = parent.getNode(nodeName);
+                    if (nodeName.length() > 0) {
+                        if (!parent.hasNode(nodeName)) {
+                            log.info("adding {}", nodeName);
+                            parent = parent.addNode(nodeName, "sling:Folder");
+                        } else {
+                            log.info("{} exists", nodeName);
+                            parent = parent.getNode(nodeName);
+                        }
                     }
                 }
+                session.save();
             }
         }
     }
 
     public void enable() {
+        log.info("enabling persisting jcr event listener");
         Session session = null;
         try {
             session = getSession();
@@ -129,6 +135,6 @@ public class PersistingJcrEventReplicati
     }
 
     public void disable() {
-
+        log.info("disabling persisting jcr event listener");
     }
 }

Modified: sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTriggerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTriggerTest.java?rev=1636530&r1=1636529&r2=1636530&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTriggerTest.java
(original)
+++ sling/trunk/contrib/extensions/replication/core/src/test/java/org/apache/sling/replication/trigger/impl/PersistingJcrEventReplicationTriggerTest.java
Tue Nov  4 09:48:59 2014
@@ -62,8 +62,8 @@ public class PersistingJcrEventReplicati
     public void testProcessEventWithoutPrivilegesAndNuggetsPath() throws Exception {
         String serviceName = "serviceId";
         Session session = mock(Session.class);
-        when(session.hasPermission(eq("var"), eq(Privilege.JCR_ADD_CHILD_NODES))).thenReturn(true);
-        when(session.hasPermission(eq("nuggets"), eq(Privilege.JCR_ADD_CHILD_NODES))).thenReturn(true);
+        when(session.hasPermission(eq("var"), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
+        when(session.hasPermission(eq("nuggets"), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
         when(session.nodeExists("/var/nuggets")).thenReturn(false); // first time it doesn't
exist and should be created
         when(session.nodeExists("/var/nuggets")).thenReturn(true); // second time it should
exist
         Node rootNode = mock(Node.class);
@@ -93,7 +93,7 @@ public class PersistingJcrEventReplicati
         ObservationManager observationManager = mock(ObservationManager.class);
         when(workspace.getObservationManager()).thenReturn(observationManager);
         when(session.getWorkspace()).thenReturn(workspace);
-        when(session.hasPermission(nuggetsPath, Privilege.JCR_ADD_CHILD_NODES)).thenReturn(true);
+        when(session.hasPermission(nuggetsPath, Session.ACTION_ADD_NODE)).thenReturn(true);
 
         SlingRepository repository = mock(SlingRepository.class);
         when(repository.loginService(serviceName, null)).thenReturn(session);
@@ -131,7 +131,7 @@ public class PersistingJcrEventReplicati
         ObservationManager observationManager = mock(ObservationManager.class);
         when(workspace.getObservationManager()).thenReturn(observationManager);
         when(session.getWorkspace()).thenReturn(workspace);
-        when(session.hasPermission(any(String.class), eq(Privilege.JCR_ADD_CHILD_NODES))).thenReturn(true);
+        when(session.hasPermission(any(String.class), eq(Session.ACTION_ADD_NODE))).thenReturn(true);
 
         SlingRepository repository = mock(SlingRepository.class);
         when(repository.loginService(serviceName, null)).thenReturn(session);

Modified: sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.component.impl.GenericReplicationComponentFactory-trigger-test-persisting-event.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.component.impl.GenericReplicationComponentFactory-trigger-test-persisting-event.json?rev=1636530&r1=1636529&r2=1636530&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.component.impl.GenericReplicationComponentFactory-trigger-test-persisting-event.json
(original)
+++ sling/trunk/contrib/extensions/replication/it/src/main/resources/SLING-CONTENT/libs/test/install.author/org.apache.sling.replication.component.impl.GenericReplicationComponentFactory-trigger-test-persisting-event.json
Tue Nov  4 09:48:59 2014
@@ -6,7 +6,7 @@
 
     "properties": [
         "type=persistedJcrEvent",
-        "path=/content",
+        "path=/content/persistedEvents",
         "servicename=replicationService"
     ]
 



Mime
View raw message