Implementing a Custom Predicate Evaluator for Replication Metadata
As an example this section describes how to create a custom predicate evaluator that helps data based on the replication metadata:
-
cq:lastReplicatedthat stores the date of the last replication action -
cq:lastReplicatedBythat stores the id of the user who triggered the last replication action -
cq:lastReplicationActionthat stores the last replication action (for example, Activation, Deactivation)
Querying Replication Metadata with Default Predicate Evaluators
The following query fetches the list of nodes in /content branch that have been activated by admin since the beginning of the year.
This query is valid but hard to read and does not highlight the relationship between the three replication properties. Implementing a custom predicate evaluator reduces the complexity and improve the semantic of this query.
Objectives
The goal of the ReplicationPredicateEvaluator is to support the above query using the following syntax.
Grouping replication metadata predicates with a custom predicate evaluator helps to create a meaningful query.
Updating Maven Dependencies
First, update the Maven dependencies of your project. The PredicateEvaluator is part of the cq-search artifact so it must be added to your Maven pom.xml file.
cq-search dependency is set to provided because cq-search is provided by the OSGi container.pom.xml
The following snippet shows the differences in unified diff format
aem-search-custom-predicate-evaluator - pom.xml
Writing The ReplicationPredicateEvaluator
The cq-search project contains the AbstractPredicateEvaluator abstract class. This can be extended with a few steps to implement your own custom predicate evaluator (PredicateEvaluator).
Xpath expression to filter data. Another option would be to implement the includes method that selects data on a row basis. See the Java™ documentation for more information.-
Create a Java™ class which extends
com.day.cq.search.eval.AbstractPredicateEvaluator -
Annotate your class with a
@Componentlike the followingsrc/main/java/com/adobe/aem/docs/search/ReplicationPredicateEvaluator.java
The following snippet shows the differences in unified diff format
aem-search-custom-predicate-evaluator - src/main/java/com/adobe/aem/docs/search/ReplicationPredicateEvaluator.java
NOTE
Thefactorymust be a unique string starting withcom.day.cq.search.eval.PredicateEvaluator/and ending with the name of your customPredicateEvaluator.NOTE
The name of thePredicateEvaluatoris the predicate name, which is used when building queries. -
Override:
In the override method, you build a
Xpathexpression based on thePredicategiven in argument.
Example of a Custom Predicate Evaluator for Replication Metadata
The complete implementation of this PredicateEvaluator might be similar to the following class.
src/main/java/com/adobe/aem/docs/search/ReplicationPredicateEvaluator.java
Was this content helpful?
Announcements
Get hands-on with agentic AI.
Explore how AI agents work together through real examples and hands-on practice. Join your local User Group to design an agent workflow with your peers and leave with a practical framework you can apply to your own work.
Find an eventAdobe Experience Manager Roadmap Webinar, Part 1 (Sites & Assets) - Americas & EMEA
Preview the AEM Sites and Assets roadmap and agentic innovations. Ask the team live.
Adobe Experience Manager Roadmap Webinar, Part 1 (Sites & Assets) - Americas & APAC
Preview the AEM Sites and Assets roadmap and agentic innovations. Ask the team live.
Adobe Brand Visibility Roadmap Webinar - Americas & EMEA
Preview the Brand Visibility roadmap across Brand Concierge and AEM Sites. Ask live.