Author: rombert
Date: Wed Sep 21 09:02:07 2016
New Revision: 1761699

URL: http://svn.apache.org/viewvc?rev=1761699&view=rev
Log:
SLING-6063 - plumber servlet doesn't persist changes anymore

Submitted-By: Nicolas Peltier

Modified:
    
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java
    
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PlumberServlet.java
    
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/impl/PlumberImpl.java
    
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PlumberServletTest.java

Modified: 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java?rev=1761699&r1=1761698&r2=1761699&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java
 (original)
+++ 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/Plumber.java
 Wed Sep 21 09:02:07 2016
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.pipes;
 
+import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 
@@ -27,7 +28,7 @@ import java.util.Set;
  */
 public interface Plumber {
 
-    public static final String RESOURCE_TYPE = "slingPipes/plumber";
+    String RESOURCE_TYPE = "slingPipes/plumber";
 
     /**
      * Instantiate a pipe from the given resource and returns it
@@ -59,9 +60,19 @@ public interface Plumber {
     Set<String> execute(ResourceResolver resolver, Pipe pipe, Map bindings, 
boolean save) throws Exception;
 
     /**
+     * Persist some pipe changes, and eventually distribute changes
+     * @param resolver
+     * @param pipe pipe from which the change occurred
+     * @param paths set of changed paths
+     */
+    void persist(ResourceResolver resolver, Pipe pipe, Set<String> paths) 
throws PersistenceException;
+
+    /**
      * Registers
      * @param type
      * @param pipeClass
      */
     void registerPipe(String type, Class<? extends BasePipe> pipeClass);
+
+
 }

Modified: 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PlumberServlet.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PlumberServlet.java?rev=1761699&r1=1761698&r2=1761699&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PlumberServlet.java
 (original)
+++ 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/PlumberServlet.java
 Wed Sep 21 09:02:07 2016
@@ -33,7 +33,9 @@ import org.slf4j.LoggerFactory;
 
 import javax.servlet.ServletException;
 import java.io.IOException;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Set;
 
 /**
  * Servlet executing plumber for a pipe path given as 'path' parameter,
@@ -110,13 +112,16 @@ public class PlumberServlet extends Slin
             OutputWriter writer = getWriter(request, response, pipe);
             int i = 0;
             Iterator<Resource> resourceIterator = pipe.getOutput();
+            Set<String> paths = new HashSet<String>();
             while (resourceIterator.hasNext()){
                 Resource resource = resourceIterator.next();
+                paths.add(resource.getPath());
                 if (++i < size) {
                     writer.writeItem(resource);
                 }
             }
             writer.ends(i);
+            plumber.persist(resolver, pipe, paths);
         } catch (Exception e) {
             throw new ServletException(e);
         }

Modified: 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/impl/PlumberImpl.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/impl/PlumberImpl.java?rev=1761699&r1=1761698&r2=1761699&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/impl/PlumberImpl.java
 (original)
+++ 
sling/trunk/contrib/extensions/sling-pipes/src/main/java/org/apache/sling/pipes/impl/PlumberImpl.java
 Wed Sep 21 09:02:07 2016
@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.distribution.DistributionRequest;
@@ -30,17 +31,32 @@ import org.apache.sling.distribution.Dis
 import org.apache.sling.distribution.DistributionResponse;
 import org.apache.sling.distribution.Distributor;
 import org.apache.sling.distribution.SimpleDistributionRequest;
-import org.apache.sling.pipes.*;
+import org.apache.sling.pipes.AuthorizablePipe;
+import org.apache.sling.pipes.BasePipe;
+import org.apache.sling.pipes.ContainerPipe;
+import org.apache.sling.pipes.FilterPipe;
+import org.apache.sling.pipes.JsonPipe;
+import org.apache.sling.pipes.MovePipe;
+import org.apache.sling.pipes.MultiPropertyPipe;
+import org.apache.sling.pipes.NotPipe;
+import org.apache.sling.pipes.ParentPipe;
+import org.apache.sling.pipes.PathPipe;
+import org.apache.sling.pipes.Pipe;
+import org.apache.sling.pipes.Plumber;
+import org.apache.sling.pipes.ReferencePipe;
+import org.apache.sling.pipes.RemovePipe;
+import org.apache.sling.pipes.SlingQueryPipe;
+import org.apache.sling.pipes.WritePipe;
+import org.apache.sling.pipes.XPathPipe;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.logging.Filter;
+
 
 /**
  * implements plumber interface, and registers default pipes
@@ -52,7 +68,7 @@ public class PlumberImpl implements Plum
 
     Map<String, Class<? extends BasePipe>> registry;
 
-    @Reference (policy= ReferencePolicy.DYNAMIC, cardinality= 
ReferenceCardinality.OPTIONAL_UNARY)
+    @Reference(policy= ReferencePolicy.DYNAMIC, cardinality= 
ReferenceCardinality.OPTIONAL_UNARY)
     protected volatile Distributor distributor = null;
 
     @Activate
@@ -115,18 +131,25 @@ public class PlumberImpl implements Plum
                 set.add(resource.getPath());
             }
         }
-        if  (pipe.modifiesContent() && save && resolver.hasChanges() && 
!pipe.isDryRun()){
+        if (save) {
+            persist(resolver, pipe, set);
+        }
+        log.info("[{}] done executing.", pipe.getName());
+        return set;
+    }
+
+    @Override
+    public void persist(ResourceResolver resolver, Pipe pipe, Set<String> 
paths) throws PersistenceException {
+        if  (pipe.modifiesContent() && resolver.hasChanges() && 
!pipe.isDryRun()){
             log.info("[{}] saving changes...", pipe.getName());
             resolver.commit();
             if (distributor != null && 
StringUtils.isNotBlank(pipe.getDistributionAgent())) {
                 log.info("a distribution agent is configured, will try to 
distribute the changes");
-                DistributionRequest request = new 
SimpleDistributionRequest(DistributionRequestType.ADD, true, set.toArray(new 
String[set.size()]));
+                DistributionRequest request = new 
SimpleDistributionRequest(DistributionRequestType.ADD, true, paths.toArray(new 
String[paths.size()]));
                 DistributionResponse response = 
distributor.distribute(pipe.getDistributionAgent(), resolver, request);
                 log.info("distribution response : {}", response);
             }
         }
-        log.info("[{}] done executing.", pipe.getName());
-        return set;
     }
 
     @Override

Modified: 
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PlumberServletTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PlumberServletTest.java?rev=1761699&r1=1761698&r2=1761699&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PlumberServletTest.java
 (original)
+++ 
sling/trunk/contrib/extensions/sling-pipes/src/test/java/org/apache/sling/pipes/PlumberServletTest.java
 Wed Sep 21 09:02:07 2016
@@ -103,6 +103,7 @@ public class PlumberServletTest  extends
         servlet.execute(request, response, true);
         String finalResponse = stringResponse.toString();
         assertFalse("There should be a response", 
StringUtils.isBlank(finalResponse));
+        assertFalse("There should be no more pending changes", 
context.resourceResolver().hasChanges());
     }
 
     /**


Reply via email to