I am trying to schedule an event in nuxeo IDE but facing error while creating event listener in IDE:
the scheduler contribution is:
<?xml version="1.0"?>
<component name="org.nuxeo.sample.ScheduleCall" version="1.0">
<extension target="org.nuxeo.ecm.core.scheduler.SchedulerService"
point="schedule">
<schedule id="testschedule">
<username>Administrator</username>
<eventId>my_user_created</eventId>
<eventCategory>default</eventCategory>
<cronExpression>0 1 * * * ?</cronExpression>
</schedule>
</extension>
</component>
the listener contribution is:
<component name="org.nuxeo.sample.listener.contrib.ScheduleListener">
<extension target="org.nuxeo.ecm.core.event.EventServiceComponent"
point="listener">
<listener name="schedulelistener" async="false" postCommit="false"
class="org.nuxeo.sample.ScheduleListener" priority="100">
<event>my_user_created</event>
</listener>
</extension>
</component>
The listener java class is:
package org.nuxeo.sample;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.NuxeoException;
import org.nuxeo.ecm.core.event.Event;
import org.nuxeo.ecm.core.event.EventContext;
import org.nuxeo.ecm.core.event.EventListener;
import org.nuxeo.ecm.core.event.impl.DocumentEventContext;
public class ScheduleListener implements EventListener {
public void handleEvent(Event event) throws ClientException {
try{
EventContext ctx = event.getContext();
if (!(ctx instanceof DocumentEventContext)) {
return;
}
DocumentModel doc = ((DocumentEventContext)ctx).getSourceDocument();
if(doc==null){
return;
}
String doctype = doc.getType();
System.out.println("*******"+doctype);
}
catch (Exception e){
e.printStackTrace();
}
}
}
The error is:
2016-06-03 11:47:01,005 ERROR [Quartz_Worker-1] [org.nuxeo.ecm.core.event.impl.EventServiceImpl] Exception during timezoneSelector sync listener execution, continuing to run other listeners
java.lang.ClassCastException: org.nuxeo.ecm.core.event.impl.EventContextImpl cannot be cast to org.nuxeo.ecm.core.event.impl.DocumentEventContext
at org.nuxeo.ecm.user.center.profile.localeProvider.UserLocaleSelectorListener.handleEvent(UserLocaleSelectorListener.java:43)
at org.nuxeo.ecm.core.event.impl.EventServiceImpl.fireEvent(EventServiceImpl.java:200)
at org.nuxeo.ecm.core.scheduler.EventJob.execute(EventJob.java:119)
at org.nuxeo.ecm.core.scheduler.EventJob.execute(EventJob.java:65)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
2016-06-03 11:47:01,008 WARN [Nuxeo-Work-default-4] [org.nuxeo.ecm.platform.ec.notification.NotificationEventListener] Can not handle notification on a event that is not bound to a DocumentEventContext