<?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: sending email for expired documents in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325293#M12294</link>
    <description>&lt;P&gt;To add logs, as I said, add the category in your log4j.xml, with a DEBUG level.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2016 09:10:33 GMT</pubDate>
    <dc:creator>Greg_Drayon</dc:creator>
    <dc:date>2016-01-13T09:10:33Z</dc:date>
    <item>
      <title>sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325288#M12289</link>
      <description>&lt;P&gt;I've followed this   &lt;A href="http://www.nuxeo.com/blog/qa-friday-upcoming-document-expiration-notification/"&gt;article&lt;/A&gt; in Nuxeo Blog for sending amail when some documents are expired,
Here is what i've done&lt;/P&gt;
&lt;H3&gt;&lt;STRONG&gt;contract-scheduler-contrib.xml :&lt;/STRONG&gt;&lt;/H3&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0"?&amp;gt;
 &amp;lt;component name="org.nuxeo.sample.scheduler.notifContract"&amp;gt;
 &amp;lt;extension
 target="org.nuxeo.ecm.core.scheduler.SchedulerService"
 point="schedule"&amp;gt;
 &amp;lt;schedule id="notifContractScehdulerId"&amp;gt;
 &amp;lt;username&amp;gt;Administrator&amp;lt;/username&amp;gt;
 &amp;lt;eventId&amp;gt;notifContract&amp;lt;/eventId&amp;gt;
 &amp;lt;eventCategory&amp;gt;default&amp;lt;/eventCategory&amp;gt;
 
 &amp;lt;cronExpression&amp;gt;0 * * * * ?&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;H3&gt;&lt;STRONG&gt;contract-listener-contrib.xml&lt;/STRONG&gt;&lt;/H3&gt;
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;?xml version="1.0"?&amp;gt;
 &amp;lt;component name="org.nuxeo.sample.listener.contrib.notifContract"&amp;gt;
 &amp;lt;extension target="org.nuxeo.ecm.core.event.EventServiceComponent"
 point="listener"&amp;gt;
 &amp;lt;listener name="notifContractListener" async="true" postCommit="false" priority="120"
 class="org.nuxeo.sample.restAPI.ContractNotifListener" &amp;gt;
 &amp;lt;event&amp;gt;notifContract&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;contract-notif-contrib.xml :&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.contract.notifcontrib"&amp;gt;

&amp;lt;extension
target="org.nuxeo.ecm.platform.ec.notification.service.NotificationService"
point="notifications"&amp;gt;
&amp;lt;notification name="Contract Expired" channel="email" enabled="true" availableIn="Workspace"
autoSubscribed="false" template="contractExpired" subject="Contract expired" label="label.nuxeo.notifications.contractExpired"&amp;gt;
&amp;lt;event name="contractExpired"/&amp;gt;

&amp;lt;/notification&amp;gt;
&amp;lt;/extension&amp;gt;

&amp;lt;extension
target="org.nuxeo.ecm.platform.ec.notification.service.NotificationService"
point="templates"&amp;gt;
&amp;lt;template name="contractExpired" src="templates/contractExpired.ftl" /&amp;gt;
&amp;lt;/extension&amp;gt;

&amp;lt;/component&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H3&gt;&lt;STRONG&gt;ContractNotifListener.java&lt;/STRONG&gt;&lt;/H3&gt;
&lt;PRE&gt;&lt;CODE&gt;package org.nuxeo.sample.restAPI;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

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.DocumentModelList;
import org.nuxeo.ecm.core.event.Event;
import org.nuxeo.ecm.core.event.EventListener;
import org.nuxeo.ecm.core.event.EventService;
import org.nuxeo.ecm.core.event.impl.DocumentEventContext;
import org.nuxeo.runtime.api.Framework;

public class ContractNotifListener implements EventListener {
	
	private static final String QUERY_CONTRACTS = "Select * From Document WHERE ecm:isCheckedInVersion = 0 AND ecm:currentLifeCycleState != 'deleted' AND dc:expired = DATE '%s'";

	public void handleEvent(Event event) throws ClientException {
		CoreSession coreSession = event.getContext().getCoreSession();
		Calendar expirationDate = Calendar.getInstance();
		expirationDate.add(Calendar.DATE, 1);
		Date now = expirationDate.getTime();
		String date = new SimpleDateFormat("yyyy-MM-dd").format(now);
		String query = String.format(QUERY_CONTRACTS, date);
		DocumentModelList contracts = coreSession.query(query);

		EventService eventService;
		try {
		eventService = Framework.getService(EventService.class);
		for (DocumentModel contract : contracts) {
		DocumentEventContext ctx = new DocumentEventContext(
		coreSession, coreSession.getPrincipal(), contract);
		Event contractExpiredEvent = ctx.newEvent("contractExpired");
		eventService.fireEvent(contractExpiredEvent);
		}
		} catch (Exception e) {
		throw new RuntimeException("could not get the EventService", e);
		}
		}
		}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;### MANIEST.MF&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Manifest-Version: 1.0
Bundle-ManifestVersion: 1
Bundle-Name: Nuxeo Sample project
Bundle-SymbolicName: org.nuxeo.project.sample;singleton:=true
Bundle-Version: 1.0.0
Bundle-Vendor: Nuxeo
Provide-Package: org.nuxeo.project.sample
Require-Bundle: org.nuxeo.runtime,
 org.nuxeo.ecm.core.api,
 org.nuxeo.ecm.core,
 org.nuxeo.ecm.webapp.core
Nuxeo-Component: OSGI-INF/contract-scheduler-contrib.xml,
 OSGI-INF/contract-listener-contrib.xml,
 OSGI-INF/contract-notif-contrib.xml,
 OSGI-INF/core-types-contrib.xml,
 OSGI-INF/lifecycle-contrib.xml,
 OSGI-INF/ui-types-contrib.xml,
 OSGI-INF/login-contrib.xml,
 OSGI-INF/theme-contrib.xml,
 OSGI-INF/my-directories-contrib.xml,
 OSGI-INF/layouts-contrib.xml,
 OSGI-INF/actions-contrib.xml,
 OSGI-INF/contentviews-contrib.xml,
 OSGI-INF/versioningrules-contrib.xml,
 OSGI-INF/workflow-contrib.xml,
 OSGI-INF/directory-layout-contrib.xml
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, i can't get the email , the code is not executed and i have nothing in my log file,  can you tell what i'm missing ? Any help would appreciated.&lt;/P&gt;
&lt;P&gt;Update :&lt;/P&gt;
&lt;P&gt;I've tried sending alert using documentCreated event that i send when clicking in a button, so i end up noticing that i have a problem with the Scheduler or with the new event 'contractExpired' .
I want to mention that in those lines&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Event contractExpiredEvent = ctx.newEvent("contractExpired");
eventService.fireEvent(event);


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;we should have &lt;CODE&gt;eventService.fireEvent(contractExpiredEvent);&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 17:38:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325288#M12289</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2015-12-10T17:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325289#M12290</link>
      <description>&lt;P&gt;Hi! Quick question&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 08:44:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325289#M12290</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2015-12-11T08:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325290#M12291</link>
      <description>&lt;P&gt;Hi [Greg Drayon](https&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2015 09:32:56 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325290#M12291</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2015-12-11T09:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325291#M12292</link>
      <description>&lt;P&gt;OK, then you can add some logs at the beginning of your&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2015 15:26:29 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325291#M12292</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2015-12-18T15:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325292#M12293</link>
      <description>&lt;P&gt;[Greg Drayon](https&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 09:53:41 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325292#M12293</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-08T09:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325293#M12294</link>
      <description>&lt;P&gt;To add logs, as I said, add the category in your log4j.xml, with a DEBUG level.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2016 09:10:33 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325293#M12294</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2016-01-13T09:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325294#M12295</link>
      <description>&lt;P&gt;Thank you [Greg Drayon](https&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 15:57:46 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325294#M12295</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-14T15:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325295#M12296</link>
      <description>&lt;OL&gt;
&lt;LI&gt;'notifContract' is an event triggered by the scheduler, every day at 1 am.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 14 Jan 2016 16:43:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325295#M12296</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2016-01-14T16:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325296#M12297</link>
      <description>&lt;P&gt;okay thank you [Greg Drayon](https&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 17:34:44 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325296#M12297</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-14T17:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325297#M12298</link>
      <description>&lt;P&gt;I would check the cron expression, but this is all I can think about. Maybe add a "year" value, such as "*"?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2016 09:13:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325297#M12298</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2016-01-15T09:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325298#M12299</link>
      <description>&lt;P&gt;[Greg Drayon](https&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2016 16:18:20 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325298#M12299</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-18T16:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325299#M12300</link>
      <description>&lt;P&gt;I guess the component is defined in the MANIFEST.MF and has a unique component name, as well as the scheduler id?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 08:36:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325299#M12300</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2016-01-19T08:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325300#M12301</link>
      <description>&lt;P&gt;[Greg Drayon](https&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 09:02:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325300#M12301</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-19T09:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325301#M12302</link>
      <description>&lt;P&gt;Is there a reason why your listener does not implement EventListener? In the article you gave, it does.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 09:58:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325301#M12302</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2016-01-19T09:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325302#M12303</link>
      <description>&lt;P&gt;[Greg Drayon](https&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 10:13:32 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325302#M12303</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-19T10:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325303#M12304</link>
      <description>&lt;P&gt;You can see [here](http&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 10:28:21 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325303#M12304</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2016-01-19T10:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325304#M12305</link>
      <description>&lt;P&gt;Ok thank you [Greg Drayon](https&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 10:32:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325304#M12305</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-19T10:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325305#M12306</link>
      <description>&lt;P&gt;In "contract-listener-contrib.xml", the extension tag isn't closed in the code you give here.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 10:37:27 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325305#M12306</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2016-01-19T10:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325306#M12307</link>
      <description>&lt;P&gt;i've modified it but with no luck&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 10:46:53 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325306#M12307</guid>
      <dc:creator>ITShine_</dc:creator>
      <dc:date>2016-01-19T10:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: sending email for expired documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325307#M12308</link>
      <description>&lt;P&gt;Are you sure the event is not fired? You may raise an Exception from your listener and see if it appears in the log file. If it does, the event is fired. If not, maybe check if you components are deployed, using the platform-explorer (if you have a Studio account). If it is, then either it comes from the cron expression, or I'm at loss for words...&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 10:59:16 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/sending-email-for-expired-documents/m-p/325307#M12308</guid>
      <dc:creator>Greg_Drayon</dc:creator>
      <dc:date>2016-01-19T10:59:16Z</dc:date>
    </item>
  </channel>
</rss>

