EVENT FILTER is not working | Community
Skip to main content
sail83812260
August 10, 2020
Solved

EVENT FILTER is not working

  • August 10, 2020
  • 4 replies
  • 5234 views

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:

@8220494(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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Vishalverma

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/*)" })

4 replies

Vijayalakshmi_S
August 10, 2020

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)"})

 

sail83812260
August 10, 2020

HI @vijayalakshmi_s , have applied the changes but don`t see its working. The logic itself is not getting triggered on any replication event.

arunpatidar
Community Advisor
Community Advisor
August 10, 2020

Try with

EventConstants.EVENT_FILTER + "(path=/content/dam/projectA/*/jcr:content)"}

 

Example

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/TestEventHandler.java

Arun Patidar
ChitraMadan
Community Advisor
Community Advisor
August 10, 2020

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;
}

}
VishalvermaAdobe EmployeeAccepted solution
Adobe Employee
August 11, 2020

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/*)" })

sail83812260
August 12, 2020
It worked @vishalverma thank you.