<?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 Re: Getting the session inside a event in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313892#M893</link>
    <description>&lt;P&gt;[pmbroca](https&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2016 14:29:00 GMT</pubDate>
    <dc:creator>ITShine_</dc:creator>
    <dc:date>2016-01-20T14:29:00Z</dc:date>
    <item>
      <title>Getting the session inside a event</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313890#M891</link>
      <description>&lt;P&gt;Hello!
I have implemented a scheduler associated with an event. I would like to search documents inside it with the session. Unfortunately when I try to get the session from the event it returns null.
There's the code of my scheduler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt; &amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;component name="fr.sword.bdf.arche.distribution.core.schedule"&amp;gt;
	&amp;lt;extension target="org.nuxeo.ecm.core.scheduler.SchedulerService"
		point="schedule"&amp;gt;
		&amp;lt;schedule id="embargoSchedule"&amp;gt;
			&amp;lt;eventId&amp;gt;EmbargoEvent&amp;lt;/eventId&amp;gt;
			&amp;lt;eventCategory&amp;gt;default&amp;lt;/eventCategory&amp;gt;
			&amp;lt;!-- Every 2 minutes --&amp;gt;
			&amp;lt;cronExpression&amp;gt;0 0/2 * 1/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;The code of my event contrib:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;component name="fr.sword.bdf.arche.distribution.core.event"&amp;gt;

	&amp;lt;extension target="org.nuxeo.ecm.core.event.EventServiceComponent"
		point="listener"&amp;gt;

		&amp;lt;listener name="EmbargoEvent" async="false" postCommit="true"
			priority="140" class="fr.sword.bdf.arche.distribution.core.event.EmbargoEvent"&amp;gt;
			&amp;lt;event&amp;gt;EmbargoEvent&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;And the code of the event listener:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;public class EmbargoEvent implements EventListener {

	private static final Log LOG = LogFactory.getLog(EmbargoEvent.class);

	public static final String EVENT_NAME = "EmbargoEvent";

	protected Lock lock = new ReentrantLock();

	@Override
	public void handleEvent(Event event) throws ClientException {
		if (event != null &amp;amp;&amp;amp; EVENT_NAME.equals(event.getName())) {
			final EventContext context = event.getContext();
			final CoreSession session = context.getCoreSession();
			List&amp;lt;DocumentModel&amp;gt; docs = getDocListEmbargo(session, event);
			LOG.error("Size docs: " + docs.size());
		}
	}

	public static List&amp;lt;DocumentModel&amp;gt; getDocListEmbargo(CoreSession session, Event event) throws ClientException {
		try {
			List&amp;lt;DocumentModel&amp;gt; results = new ArrayList&amp;lt;DocumentModel&amp;gt;();

			// Requête de récupération des documents statut
			final StringBuilder query = new StringBuilder("SELECT * FROM ");
			query.append(DocumentConstants.DOCUMENT_EXTERNE_DOC_TYPE);
			query.append(" WHERE ");
			query.append(DocumentConstants.DOCUMENT_EXTERNE_SCHEMA_PREFIX);
			query.append(" AND ");
			query.append("ecm:isProxy = 0 ");
			query.append(" AND ");
			query.append("ecm:currentLifeCycleState != 'deleted' ");
			query.append(" AND ");
			query.append("(dext:niveauConfidentialite = 2 OR dext:niveauConfidentialite = 3) ");

			final DocumentModelList docs = session.query(query.toString());

			for (int i = 0; i &amp;lt; docs.size(); i++) {
				results.add(docs.get(i));
			}

			return results;
		} catch (Exception e) {
			event.markRollBack(null, e);
			throw new ClientException(e);
		}
	}
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2015 10:19:47 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313890#M891</guid>
      <dc:creator>pmbroca_</dc:creator>
      <dc:date>2015-04-03T10:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the session inside a event</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313891#M892</link>
      <description>&lt;P&gt;Forget about it I found the solution thanks to this link: &lt;A href="https://github.com/easysoa/EasySOA/wiki/Nuxeo-CoreSession-and-Transactions"&gt;https://github.com/easysoa/EasySOA/wiki/Nuxeo-CoreSession-and-Transactions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2015 10:33:28 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313891#M892</guid>
      <dc:creator>pmbroca_</dc:creator>
      <dc:date>2015-04-03T10:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the session inside a event</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313892#M893</link>
      <description>&lt;P&gt;[pmbroca](https&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 14:29:00 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313892#M893</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-20T14:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the session inside a event</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313893#M894</link>
      <description>&lt;P&gt;just need a help...just need to know if you have created the scheduler as a nuxeo component and the listener as a document listener?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 10:14:50 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/getting-the-session-inside-a-event/m-p/313893#M894</guid>
      <dc:creator>Parul_Puri</dc:creator>
      <dc:date>2016-06-06T10:14:50Z</dc:date>
    </item>
  </channel>
</rss>

