<?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: implement an operation  - Subscribe to an Alert in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315620#M2621</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Finally the USER_PREFIX constant  resolved the problem. Concerning the principal it's not mandatory, but if you put it , the user will also receive a notification indicating that the Principal (Administrator in this context) subscribed him to the notification.&lt;/P&gt;
&lt;P&gt;I didn't understand what the
UserSubscription subscription = new UserSubscription(notification, username, doc.getId());
add to this. I can subscribe to a notification , receive the email , without it.&lt;/P&gt;
&lt;P&gt;@Param(name = "username")
protected String username;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@OperationMethod
public String run(DocumentModel doc) throws Exception{
	
	final String CONSTANT_CREATION = "Creation";
	
	try
	{
				
	//Create a notification Manager	
	NotificationManager  notificationManager = Framework.getService(NotificationManager.class);
	
	//add a subscription
	notificationManager.addSubscription(NotificationConstants.USER_PREFIX + username,CONSTANT_CREATION, doc, true, (NuxeoPrincipal)doc.getCoreSession().getPrincipal(), null);
	
	//save session
	session.save();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Nov 2011 22:05:21 GMT</pubDate>
    <dc:creator>mcaissie_</dc:creator>
    <dc:date>2011-11-23T22:05:21Z</dc:date>
    <item>
      <title>implement an operation  - Subscribe to an Alert</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315616#M2617</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I would like to implement an operation to allow me to subscribe a user to an alert.
So i am looking for the same behavior than  if a go in Document Management - click on a file&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;select Alerts  and  click  on Subscribe  Modification.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;In Java Doc i found  the  NotificationManager  with the method;
addSubscription(String username, String notification, DocumentModel doc, Boolean sendConfirmationEmail, NuxeoPrincipal principal, String notificationName)&lt;/P&gt;
&lt;P&gt;But  i am not sure what the two Strings "notification" and  "notificationName"  represents  and how they are linked with the actual  DocumentEventTypes.&lt;/P&gt;
&lt;P&gt;I tried  the following with no success;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@Param(name = "username")
protected String username;

@Param(name = "DocumentEventType")
protected String DocumentEventType;

@OperationMethod
public  run(DocumentModel doc) throws Exception{

NotificationManager  notificationManager = Framework.getService(NotificationManager.class);
				
notificationManager.addSubscription(username, DocumentEventType, doc, true, null, DocumentEventType);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If i get;&lt;/P&gt;
&lt;P&gt;notificationManager.getSubscriptionsForUserOnDocument(username, doc.getId())&lt;/P&gt;
&lt;P&gt;i can see a notification "documentModified"  but  i don't see it  selected  if i look in Document Management.&lt;/P&gt;
&lt;P&gt;Does anyone have an idea  on how to do this? ...examples?... links to source code ?&lt;/P&gt;
&lt;P&gt;tx&lt;/P&gt;
&lt;P&gt;Michel&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2011 00:05:27 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315616#M2617</guid>
      <dc:creator>mcaissie_</dc:creator>
      <dc:date>2011-11-11T00:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: implement an operation  - Subscribe to an Alert</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315617#M2618</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;That's a nice approach:)
First of all, for the username, you must prefix it for telling if it is a group or a user.
The prefix to use are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;NotificationConstants.USER_PREFIX&lt;/LI&gt;
&lt;LI&gt;NotificationConstants.GROUP_PREFIX&lt;/LI&gt;
&lt;/UL&gt;
&lt;H2&gt;Then, I can see that the API expects the principal (you put null). You should probably put the principal of the current Session.&lt;/H2&gt;</description>
      <pubDate>Mon, 14 Nov 2011 13:40:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315617#M2618</guid>
      <dc:creator>Alain_ESCAFFRE</dc:creator>
      <dc:date>2011-11-14T13:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: implement an operation  - Subscribe to an Alert</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315618#M2619</link>
      <description>&lt;P&gt;"notification" is used in the UserSubscription to identify the notification:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;UserSubscription subscription = new UserSubscription(notification, username, doc.getId());
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;whereas "notificationName" is only a label used in the sent email:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;// options for confirmation email
options.put("recipients", username);
options.put("notifName", notificationName);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Nov 2011 14:43:48 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315618#M2619</guid>
      <dc:creator>Julien_Carsique</dc:creator>
      <dc:date>2011-11-14T14:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: implement an operation  - Subscribe to an Alert</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315619#M2620</link>
      <description>&lt;P&gt;hi Julient&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2011 17:29:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315619#M2620</guid>
      <dc:creator>mcaissie_</dc:creator>
      <dc:date>2011-11-14T17:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: implement an operation  - Subscribe to an Alert</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315620#M2621</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Finally the USER_PREFIX constant  resolved the problem. Concerning the principal it's not mandatory, but if you put it , the user will also receive a notification indicating that the Principal (Administrator in this context) subscribed him to the notification.&lt;/P&gt;
&lt;P&gt;I didn't understand what the
UserSubscription subscription = new UserSubscription(notification, username, doc.getId());
add to this. I can subscribe to a notification , receive the email , without it.&lt;/P&gt;
&lt;P&gt;@Param(name = "username")
protected String username;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;@OperationMethod
public String run(DocumentModel doc) throws Exception{
	
	final String CONSTANT_CREATION = "Creation";
	
	try
	{
				
	//Create a notification Manager	
	NotificationManager  notificationManager = Framework.getService(NotificationManager.class);
	
	//add a subscription
	notificationManager.addSubscription(NotificationConstants.USER_PREFIX + username,CONSTANT_CREATION, doc, true, (NuxeoPrincipal)doc.getCoreSession().getPrincipal(), null);
	
	//save session
	session.save();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2011 22:05:21 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/implement-an-operation-subscribe-to-an-alert/m-p/315620#M2621</guid>
      <dc:creator>mcaissie_</dc:creator>
      <dc:date>2011-11-23T22:05:21Z</dc:date>
    </item>
  </channel>
</rss>

