EVENT FILTER is not working

Avatar

Avatar

sail83812260

Avatar

sail83812260

sail83812260

10-08-2020

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Vishalverma

Avatar

Vishalverma

Vishalverma

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

Answers (3)

Answers (3)

Avatar

Avatar

ChitraMadan

MVP

Avatar

ChitraMadan

MVP

ChitraMadan
MVP

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

}

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831
Arun_Patidar
MVP

10-08-2020

Try with

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

 

Example

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

Avatar

Avatar

Vijayalakshmi_S

MVP

Avatar

Vijayalakshmi_S

MVP

Vijayalakshmi_S
MVP

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