12-10-2015 12:38 PM
I've followed this article in Nuxeo Blog for sending amail when some documents are expired, Here is what i've done
<?xml version="1.0"?>
<component name="org.nuxeo.sample.scheduler.notifContract">
<extension
target="org.nuxeo.ecm.core.scheduler.SchedulerService"
point="schedule">
<schedule id="notifContractScehdulerId">
<username>Administrator</username>
<eventId>notifContract</eventId>
<eventCategory>default</eventCategory>
<cronExpression>0 * * * * ?</cronExpression>
</schedule>
</extension>
</component>
<?xml version="1.0"?>
<component name="org.nuxeo.sample.listener.contrib.notifContract">
<extension target="org.nuxeo.ecm.core.event.EventServiceComponent"
point="listener">
<listener name="notifContractListener" async="true" postCommit="false" priority="120"
class="org.nuxeo.sample.restAPI.ContractNotifListener" >
<event>notifContract</event>
</listener>
</extension>
</component>
contract-notif-contrib.xml :
<?xml version="1.0"?>
<component
name="org.nuxeo.sample.contract.notifcontrib">
<extension
target="org.nuxeo.ecm.platform.ec.notification.service.NotificationService"
point="notifications">
<notification name="Contract Expired" channel="email" enabled="true" availableIn="Workspace"
autoSubscribed="false" template="contractExpired" subject="Contract expired" label="label.nuxeo.notifications.contractExpired">
<event name="contractExpired"/>
</notification>
</extension>
<extension
target="org.nuxeo.ecm.platform.ec.notification.service.NotificationService"
point="templates">
<template name="contractExpired" src="templates/contractExpired.ftl" />
</extension>
</component>
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);
}
}
}
### MANIEST.MF
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
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.
Update :
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
Event contractExpiredEvent = ctx.newEvent("contractExpired");
eventService.fireEvent(event);
we should have eventService.fireEvent(contractExpiredEvent);
01-18-2016 11:18 AM
[Greg Drayon](https
01-19-2016 03:36 AM
I guess the component is defined in the MANIFEST.MF and has a unique component name, as well as the scheduler id?
01-19-2016 04:02 AM
[Greg Drayon](https
01-19-2016 04:58 AM
Is there a reason why your listener does not implement EventListener? In the article you gave, it does.
01-19-2016 05:13 AM
[Greg Drayon](https
01-19-2016 05:28 AM
You can see [here](http
01-19-2016 05:32 AM
Ok thank you [Greg Drayon](https
01-19-2016 05:37 AM
In "contract-listener-contrib.xml", the extension tag isn't closed in the code you give here.
01-19-2016 05:46 AM
i've modified it but with no luck
01-19-2016 05:59 AM
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...
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.