Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.techrevel.dam.core.fmdita.listeners;
import java.util.HashMap;
import java.util.Map;
import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.dam.api.DamConstants;
/**
* Appends path property to DITA Assets. Needed for Fluid Topic Integration
*
*/
@Component(service = EventHandler.class, property = {
EventConstants.EVENT_TOPIC + "=com/adobe/fmdita/postprocess/complete", EventConstants.EVENT_FILTER
+ "=(|(operation=org/apache/sling/api/resource/Resource/ADDED)(operation=org/apache/sling/api/resource/Resource/CHANGED))" })
public class PostProcessingEventHandler implements EventHandler {
private static final Logger LOG = LoggerFactory.getLogger(PostProcessingEventHandler.class);
@Reference
private ResourceResolverFactory resolverFactory;
@Override
public void handleEvent(Event event) {
LOG.debug("Processing the JOB *******");
// The path of the file that triggered this event. Typically, this is the file
// on which an operation has been performed.
String path = (String) event.getProperty("path");
// Fetch resource resolver
Map<String, Object> serviceParams = new HashMap<>();
serviceParams.put(ResourceResolverFactory.SUBSERVICE, "subServiceName");
ResourceResolver resolver = null;
try {
resolver = resolverFactory.getServiceResourceResolver(serviceParams);
// Resolve path of DITA Asset
String ditaResourcePath = path.substring(0, path.indexOf(JcrConstants.JCR_CONTENT) - 1);
// Resolve metadata resource of DITA Asset
String metadataResourcePath = path.substring(0, path.indexOf(DamConstants.RENDITIONS_FOLDER))
+ DamConstants.METADATA_FOLDER;
} catch (LoginException e) {
LOG.error("Exception while commiting path property ", e);
} finally {
if (resolver != null) {
resolver.close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.