Hi All,
Have defined EVENT_FILTER in my code so that my replication event gets trigger only in that respective path mentioned as event filter. But here event gets trigger at every location path.
Below is the sample snippet have defined for filter:
@component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "= DAM Asset Events",
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "path=/content/dam/projectA"})
If replication events are triggered under folder "/content/dam/projectB" then those are also triggering logic. This is not expected so needs to restrict it. Could anyone let me know how to resolve it.
Thanks
RSL
Solved! Go to Solution.
Try this
@component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "= DAM Asset Events",
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "=(paths=/content/dam/projectA/*)" })
Hi @sail83812260,
OSGI Event Filter property follows LDAP filter syntax. Hence try the below
EventConstants.EVENT_FILTER + "=" + "(path=/content/dam/projectA)"
@Component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "= DAM Asset Events",
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "=" + "(path=/content/dam/projectA)"})
HI @Vijayalakshmi_S , have applied the changes but don`t see its working. The logic itself is not getting triggered on any replication event.
Views
Replies
Total Likes
Hi @sail83812260,
After reproducing it in my local, could see that the culprit is "=" after the event.filter property.
With this correction, replication events are listened but path/filter value is not respected - It is listening to all paths.
Have tried below possible trials, couldn't see positive outcome.
One last option left is to try with Felix SCR annotation. Will try and update my findings.
As an alternative/interim, you can try solution from @ChitraMadan which uses Felix SCR annotation and the path is validated at the time of handling event. (all replication events are listened)
Screenshot 1:
Views
Replies
Total Likes
Try with
EventConstants.EVENT_FILTER + "(path=/content/dam/projectA/*/jcr:content)"}
Example
https://github.com/arunpatidar02/aem63app-repo/blob/master/java/TestEventHandler.java
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;
}
}
Try this
@component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "= DAM Asset Events",
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "=(paths=/content/dam/projectA/*)" })
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies