Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

EVENT FILTER is not working

Avatar

Avatar
Boost 1
Level 1
sail83812260
Level 1

Like

1 like

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
sail83812260
Level 1

Like

1 like

Total Posts

5 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile
sail83812260
Level 1

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
Boost 5
Level 2
Vishalverma
Level 2

Likes

6 likes

Total Posts

5 posts

Correct Reply

4 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Affirm 3
Affirm 1
View profile

Avatar
Boost 5
Level 2
Vishalverma
Level 2

Likes

6 likes

Total Posts

5 posts

Correct Reply

4 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Affirm 3
Affirm 1
View profile
Vishalverma
Level 2

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
Establish
MVP
ChitraMadan
MVP

Likes

227 likes

Total Posts

124 posts

Correct Reply

50 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back
View profile

Avatar
Establish
MVP
ChitraMadan
MVP

Likes

227 likes

Total Posts

124 posts

Correct Reply

50 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back
View profile
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
Coach
MVP
Arun_Patidar
MVP

Likes

1,260 likes

Total Posts

3,140 posts

Correct Reply

886 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,260 likes

Total Posts

3,140 posts

Correct Reply

886 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
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
Give Back 50
MVP
Vijayalakshmi_S
MVP

Likes

436 likes

Total Posts

574 posts

Correct Reply

191 solutions
Top badges earned
Give Back 50
Give Back 5
Ignite 10
Ignite 5
Ignite 3
View profile

Avatar
Give Back 50
MVP
Vijayalakshmi_S
MVP

Likes

436 likes

Total Posts

574 posts

Correct Reply

191 solutions
Top badges earned
Give Back 50
Give Back 5
Ignite 10
Ignite 5
Ignite 3
View profile
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)"})