Hi @sail83812260 ,
If this still doesn't work, may be you can try this example using EventHandler. Its working for me.
@Service
@Component(label = "Listener on ACTIVATE Action", description = "REPLICATE sample content.", immediate = true, metatype = true)
public class SamplePublishListener implements EventHandler {
@Property(name = "event.topics", value = {ReplicationAction.EVENT_TOPIC})
private static final String EVENT_TOPIC = "";
@Property(name = "allowed.paths.regex", value = {
"/content/dam/projectA/(.*)"})
private static final String PATH_REGEX = "";
@Reference
private JobManager jobManager;
private List<String> regexPaths;
/**
* The job topic for activate job events.
*/
public static final String ACTIVATE_JOB_TOPIC = "com/sling/eventing/activate/sample/job";
/**
* The job name for activate job events.
*/
private static final String ACTIVATE_JOB_NAME = "Sample Activate Job";
@Activate
protected void activate(final Map<String, Object> props) {
this.update(props);
}
@Modified
protected void update(final Map<String, Object> props) {
initCollections();
String[] configuredPaths = (String[]) props.get("allowed.paths.regex");
if (null != configuredPaths) {
List<String> tempconfiguredPaths = Arrays.asList(configuredPaths);
for (String path : tempconfiguredPaths) {
this.regexPaths.add(path);
}
}
}
@Override
public void handleEvent(Event event) {
ReplicationAction action = ReplicationAction.fromEvent(event);
if (action != null) {
ReplicationActionType eventType = action.getType();
String path = action.getPaths()[0];
if (isValidPath(path) && eventType.equals(ReplicationActionType.ACTIVATE)) {
final Map<String, Object> payload = new HashMap<>();
payload.put("resourcePath", path);
jobManager.addJob(ACTIVATE_JOB_TOPIC, payload);
}
}
}
/**
* Init the collections.
*/
private void initCollections() {
if (null == this.regexPaths) {
this.regexPaths = new ArrayList<String>();
} else {
this.regexPaths.clear();
}
}
/**
* Return a true if the current path matches the regular expression.
*
* @param path current node path
* @return boolean true if matches
*/
private boolean isValidPath(String path) {
for (String regEx : this.regexPaths) {
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(path);
if (m.matches()) {
return true;
}
}
return false;
}
}