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);
12-11-2015 03:44 AM
Hi! Quick question
12-11-2015 04:32 AM
Hi [Greg Drayon](https
12-18-2015 10:26 AM
OK, then you can add some logs at the beginning of your
01-08-2016 04:53 AM
[Greg Drayon](https
01-13-2016 04:10 AM
To add logs, as I said, add the category in your log4j.xml, with a DEBUG level.
01-14-2016 10:57 AM
Thank you [Greg Drayon](https
01-14-2016 11:43 AM
01-14-2016 12:34 PM
okay thank you [Greg Drayon](https
01-15-2016 04:13 AM
I would check the cron expression, but this is all I can think about. Maybe add a "year" value, such as "*"?
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.