<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to make an event listener in nuxeo IDE in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315669#M2670</link>
    <description>&lt;H3&gt;I am trying to schedule an event in nuxeo IDE but facing error while creating event listener in IDE:&lt;/H3&gt;
&lt;P&gt;&lt;STRONG&gt;the scheduler contribution is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0"?&amp;gt;

&amp;lt;component name="org.nuxeo.sample.ScheduleCall" version="1.0"&amp;gt;
&amp;lt;extension target="org.nuxeo.ecm.core.scheduler.SchedulerService"
 point="schedule"&amp;gt;
 &amp;lt;schedule id="testschedule"&amp;gt;
 &amp;lt;username&amp;gt;Administrator&amp;lt;/username&amp;gt;
 &amp;lt;eventId&amp;gt;my_user_created&amp;lt;/eventId&amp;gt;
 &amp;lt;eventCategory&amp;gt;default&amp;lt;/eventCategory&amp;gt;

 &amp;lt;cronExpression&amp;gt;0 1 * * * ?&amp;lt;/cronExpression&amp;gt;
 &amp;lt;/schedule&amp;gt;
 &amp;lt;/extension&amp;gt;  
&amp;lt;/component&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;the listener contribution is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;component name="org.nuxeo.sample.listener.contrib.ScheduleListener"&amp;gt;

  &amp;lt;extension target="org.nuxeo.ecm.core.event.EventServiceComponent"
    point="listener"&amp;gt;

    &amp;lt;listener name="schedulelistener" async="false" postCommit="false"
      class="org.nuxeo.sample.ScheduleListener" priority="100"&amp;gt;
    
          &amp;lt;event&amp;gt;my_user_created&amp;lt;/event&amp;gt;
         &amp;lt;/listener&amp;gt;
  &amp;lt;/extension&amp;gt;

&amp;lt;/component&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;The listener java class is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;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();
    		
    	}
    }
    

}



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;The error is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;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
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Jun 2016 06:18:33 GMT</pubDate>
    <dc:creator>Parul_Puri</dc:creator>
    <dc:date>2016-06-03T06:18:33Z</dc:date>
    <item>
      <title>How to make an event listener in nuxeo IDE</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315669#M2670</link>
      <description>&lt;H3&gt;I am trying to schedule an event in nuxeo IDE but facing error while creating event listener in IDE:&lt;/H3&gt;
&lt;P&gt;&lt;STRONG&gt;the scheduler contribution is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0"?&amp;gt;

&amp;lt;component name="org.nuxeo.sample.ScheduleCall" version="1.0"&amp;gt;
&amp;lt;extension target="org.nuxeo.ecm.core.scheduler.SchedulerService"
 point="schedule"&amp;gt;
 &amp;lt;schedule id="testschedule"&amp;gt;
 &amp;lt;username&amp;gt;Administrator&amp;lt;/username&amp;gt;
 &amp;lt;eventId&amp;gt;my_user_created&amp;lt;/eventId&amp;gt;
 &amp;lt;eventCategory&amp;gt;default&amp;lt;/eventCategory&amp;gt;

 &amp;lt;cronExpression&amp;gt;0 1 * * * ?&amp;lt;/cronExpression&amp;gt;
 &amp;lt;/schedule&amp;gt;
 &amp;lt;/extension&amp;gt;  
&amp;lt;/component&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;the listener contribution is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;component name="org.nuxeo.sample.listener.contrib.ScheduleListener"&amp;gt;

  &amp;lt;extension target="org.nuxeo.ecm.core.event.EventServiceComponent"
    point="listener"&amp;gt;

    &amp;lt;listener name="schedulelistener" async="false" postCommit="false"
      class="org.nuxeo.sample.ScheduleListener" priority="100"&amp;gt;
    
          &amp;lt;event&amp;gt;my_user_created&amp;lt;/event&amp;gt;
         &amp;lt;/listener&amp;gt;
  &amp;lt;/extension&amp;gt;

&amp;lt;/component&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;The listener java class is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;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();
    		
    	}
    }
    

}



&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;The error is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;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
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Jun 2016 06:18:33 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315669#M2670</guid>
      <dc:creator>Parul_Puri</dc:creator>
      <dc:date>2016-06-03T06:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an event listener in nuxeo IDE</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315670#M2671</link>
      <description>&lt;P&gt;Have you investigated this further?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-css"&gt;java.lang.ClassCastException: org.nuxeo.ecm.core.event.impl.EventContextImpl cannot be cast to org.nuxeo.ecm.core.event.impl.DocumentEventContext
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I believe your problem is here, as I'm sure you are aware:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-java"&gt; DocumentModel doc = ((DocumentEventContext)ctx).getSourceDocument();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Seems as though you should be specifying an index because the event data is exposed as a list of arguments. Does that many any sense?&lt;/P&gt;
&lt;P&gt;See the source code:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://community.nuxeo.com/api/nuxeo/5.4/javadoc/org/nuxeo/ecm/core/event/EventContext.html" target="test_blank"&gt;http://community.nuxeo.com/api/nuxeo/5.4/javadoc/org/nuxeo/ecm/core/event/EventContext.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://community.nuxeo.com/api/nuxeo/5.4/javadoc/org/nuxeo/ecm/core/event/impl/DocumentEventContext.html" target="test_blank"&gt;http://community.nuxeo.com/api/nuxeo/5.4/javadoc/org/nuxeo/ecm/core/event/impl/DocumentEventContext.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/nuxeo/nuxeo/blob/434093e97825bf7e02578efd428e71f588704f20/nuxeo-core/nuxeo-core-event/src/main/java/org/nuxeo/ecm/core/event/impl/ShallowEvent.java" target="test_blank"&gt;https://github.com/nuxeo/nuxeo/blob/434093e97825bf7e02578efd428e71f588704f20/nuxeo-core/nuxeo-core-event/src/main/java/org/nuxeo/ecm/core/event/impl/ShallowEvent.java&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;-Y&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 16:13:18 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315670#M2671</guid>
      <dc:creator>Yousuf_Nejati</dc:creator>
      <dc:date>2016-06-06T16:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an event listener in nuxeo IDE</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315671#M2672</link>
      <description>&lt;P&gt;Thank you, yes the error lies on this line only. My IDE wasn't appropriately configured so now this error is gone but I am unable to get any output now. I just want to see if the output is printed after regular intervals. Please let me know if you can help with this error&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 05:23:23 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315671#M2672</guid>
      <dc:creator>Parul_Puri</dc:creator>
      <dc:date>2016-06-07T05:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an event listener in nuxeo IDE</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315672#M2673</link>
      <description>&lt;P&gt;Hey Parul,&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jun 2016 19:19:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315672#M2673</guid>
      <dc:creator>Yousuf_Nejati</dc:creator>
      <dc:date>2016-06-07T19:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an event listener in nuxeo IDE</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315673#M2674</link>
      <description>&lt;P&gt;The server log says there is an error with calling nuxeo online services but I don't know if it has anything to do with my code&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 12:35:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315673#M2674</guid>
      <dc:creator>Parul_Puri</dc:creator>
      <dc:date>2016-06-08T12:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to make an event listener in nuxeo IDE</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315674#M2675</link>
      <description>&lt;P&gt;Hi Parul,&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 16:09:20 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/how-to-make-an-event-listener-in-nuxeo-ide/m-p/315674#M2675</guid>
      <dc:creator>Yousuf_Nejati</dc:creator>
      <dc:date>2016-06-08T16:09:20Z</dc:date>
    </item>
  </channel>
</rss>

