Hi @sherinregi ,
You can try to implement an onTime event handler for requirement. This will trigger On change in Validity status (onTime) of a page, this handler service will publish all referenced assets on the page. This service is meant to run in author instance only you can set configuration policy as require for this purpose.
You can further tweak this logic as per your need based on only on assets if you want to trigger it.
@Component(immediate = true, service = EventHandler.class, property = {
EventConstants.EVENT_TOPIC + "=" + PageEvent.EVENT_TOPIC }, configurationPolicy = ConfigurationPolicy.REQUIRE)
public class OnTimeEventHandler implements EventHandler {
@Override
public void handleEvent(final Event event) {
final PageEvent pgEvent = PageEvent.fromEvent(event);
final Iterator<PageModification> modifications = pgEvent.getModifications();
while (modifications.hasNext()) {
final PageModification modification = modifications.next();
final ModificationType modType = modification.getType();
if (modType.equals(PageModification.ModificationType.VALID)) {
LOGGER.info(
"OnTimeEventHandler : handleEvent() : Page Valid Event captured for page : {} : Starting Referenced Assets Replication",
modification.getPath());
startAssetReplication(modification.getPath());
}
}
}
private void startAssetReplication(final String pagePath) {
ResourceResolver resolver = Utils.getResourceResolver(resolverFactory, "subservice");
try {
final Set<com.day.cq.wcm.api.reference.Reference> referencesSet = new HashSet<com.day.cq.wcm.api.reference.Reference>();
if (null != resolver) {
final Resource pageResource = resolver
.getResource(pagePath + "/" + JcrConstants.JCR_CONTENT);
if (null != pageResource) {
for (ReferenceProvider referenceProvider : this.referenceProviders) {
referencesSet.addAll(referenceProvider.findReferences(pageResource));
}
replicateReferences(referencesSet, resolver.adaptTo(Session.class), pagePath);
} else {
LOGGER.warn(
"OnTimeEventHandler : startAssetReplication() : Could not get resource for page path : {}",
pagePath);
}
} else {
LOGGER.warn(
"OnTimeEventHandler : startAssetReplication() : Getting {} Resource Resolver as NULL while getting references assets for page path : {}",
, pagePath);
}
} finally {
if (resolver != null && resolver.isLive()) {
resolver.close();
}
}
}
}
Thanks
Tarun