Repository: adobe-consulting-services/acs-aem-commons
Issue: bug/Dispatcher Flush Rules - Regex replace not implemented for ResourceOnly flushing

/content/geometrixx/([^/]+)/([^/]+)=/content/$1/geometrixx/$2

Does not work for ResourceOnly flushing (was not implemented)


Changed files:
bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java
bundle/src/test/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImplTest.java

diff --git a/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java b/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java
index dd6bb44fa..b8e0efd8c 100644
--- a/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java
+++ b/bundle/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImpl.java
@@ -74,8 +74,10 @@ public class DispatcherFlushRulesImpl implements Preprocessor {
     private static final String OPTION_DELETE = "DELETE";
 
 
-    private static final DispatcherFlushFilter HIERARCHICAL_FILTER = new DispatcherFlushRulesFilter(FlushType.Hierarchical);
-    private static final DispatcherFlushFilter RESOURCE_ONLY_FILTER = new DispatcherFlushRulesFilter(FlushType.ResourceOnly);
+    private static final DispatcherFlushFilter HIERARCHICAL_FILTER =
+            new DispatcherFlushRulesFilter(FlushType.Hierarchical);
+    private static final DispatcherFlushFilter RESOURCE_ONLY_FILTER =
+            new DispatcherFlushRulesFilter(FlushType.ResourceOnly);
 
     /* Replication Action Type Property */
 
@@ -154,7 +156,8 @@ public class DispatcherFlushRulesImpl implements Preprocessor {
                 final Matcher m = pattern.matcher(path);
 
                 if (m.matches()) {
-                	final String flushPath = m.replaceAll(entry.getValue());
+                    final String flushPath = m.replaceAll(entry.getValue());
+
                     log.debug("Requesting hierarchical flush of associated path: {} ~> {}", path,
                     		flushPath);
                     dispatcherFlusher.flush(resourceResolver, flushActionType, false,
@@ -169,10 +172,12 @@ public class DispatcherFlushRulesImpl implements Preprocessor {
                 final Matcher m = pattern.matcher(path);
 
                 if (m.matches()) {
+                    final String flushPath = m.replaceAll(entry.getValue());
+
                     log.debug("Requesting ResourceOnly flush of associated path: {} ~> {}", path, entry.getValue());
                     dispatcherFlusher.flush(resourceResolver, flushActionType, false,
                             RESOURCE_ONLY_FILTER,
-                            entry.getValue());
+                            flushPath);
                 }
             }
 
diff --git a/bundle/src/test/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImplTest.java b/bundle/src/test/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImplTest.java
index f1a0a06ec..4e6ec06b5 100644
--- a/bundle/src/test/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImplTest.java
+++ b/bundle/src/test/java/com/adobe/acs/commons/replication/dispatcher/impl/DispatcherFlushRulesImplTest.java
@@ -391,4 +391,33 @@ public class DispatcherFlushRulesImplTest {
         verifyNoMoreInteractions(dispatcherFlusher);
     }
 
+
+    @Test
+    public void testPreprocess_success_resourceonly_translation2() throws Exception {
+        resourceOnlyFlushRules.put(Pattern.compile("/content/acs-aem-commons/(.*)/(.*)"), "/content/target/$1/acs-aem-commons/$2");
+
+        final ReplicationAction replicationAction = mock(ReplicationAction.class);
+        when(replicationAction.getPath()).thenReturn("/content/acs-aem-commons/en/page");
+        when(replicationAction.getType()).thenReturn(ReplicationActionType.ACTIVATE);
+
+        final ReplicationOptions replicationOptions = new ReplicationOptions();
+        replicationOptions.setSynchronous(false);
+
+        final ArgumentCaptor<DispatcherFlushFilter> agentFilterCaptor = ArgumentCaptor.forClass(DispatcherFlushFilter
+                .class);
+
+        dispatcherFlushRules.preprocess(replicationAction, replicationOptions);
+
+        verify(dispatcherFlusher, times(1)).flush(any(ResourceResolver.class), eq(ReplicationActionType.ACTIVATE),
+                eq(false),
+                agentFilterCaptor.capture(),
+                eq("/content/target/en/acs-aem-commons/page"));
+
+        assertEquals(DispatcherFlushFilter.FlushType.ResourceOnly, agentFilterCaptor.getValue().getFlushType());
+        // Private impl class; no access to test for instanceof
+        assertEquals("DispatcherFlushRulesFilter", agentFilterCaptor.getValue().getClass().getSimpleName());
+
+        verifyNoMoreInteractions(dispatcherFlusher);
+    }
+
 }