Created
November 24, 2014 06:41
-
-
Save yupadhyay/b3979f0c6935be653d42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.jcr.Node; | |
import javax.jcr.Session; | |
import org.apache.felix.scr.annotations.Component; | |
import org.apache.felix.scr.annotations.Property; | |
import org.apache.felix.scr.annotations.Reference; | |
import org.apache.felix.scr.annotations.Service; | |
import org.apache.sling.api.SlingConstants; | |
import org.apache.sling.event.EventUtil; | |
import org.apache.sling.event.JobProcessor; | |
import org.apache.sling.jcr.api.SlingRepository; | |
import org.osgi.service.event.Event; | |
import org.osgi.service.event.EventHandler; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
/** | |
* @author yogeshupadhyay | |
* | |
*/ | |
@Component(metatype = false, immediate = true, label = "SOME LABEL", | |
description="This component will change event heading end date property at specific time") | |
@Service(value = {JobProcessor.class,EventHandler.class }) | |
@Property(name="event.topics", value=<TOPIC THAT YOU CREATED IN LAST CLASS>) | |
@SuppressWarnings("deprecation") | |
public class TestEventProcessor implements EventHandler,JobProcessor{ | |
/** Default log. */ | |
protected final Logger log = LoggerFactory.getLogger(this.getClass()); | |
@Reference | |
private SlingRepository repository; | |
public void handleEvent(Event event) { | |
if (EventUtil.isLocal(event)) { | |
EventUtil.processJob(event, this); | |
} | |
} | |
public boolean process(Event event){ | |
Session session=null; | |
try { | |
log.debug("In process method"); | |
session = repository.loginAdministrative(null); | |
//DO SOMETHING WITH EVENT | |
if(session.hasPendingChanges()) { | |
session.save(); | |
} | |
} | |
} | |
} catch (Exception e) { | |
log.error(e.getMessage()); | |
}finally{ | |
if(session!=null){ | |
session.logout(); | |
session=null; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment