11-10-2011 07:05 PM
Hi
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
In Java Doc i found the NotificationManager with the method; addSubscription(String username, String notification, DocumentModel doc, Boolean sendConfirmationEmail, NuxeoPrincipal principal, String notificationName)
But i am not sure what the two Strings "notification" and "notificationName" represents and how they are linked with the actual DocumentEventTypes.
I tried the following with no success;
@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);
If i get;
notificationManager.getSubscriptionsForUserOnDocument(username, doc.getId())
i can see a notification "documentModified" but i don't see it selected if i look in Document Management.
Does anyone have an idea on how to do this? ...examples?... links to source code ?
tx
Michel
11-14-2011 09:43 AM
"notification" is used in the UserSubscription to identify the notification:
UserSubscription subscription = new UserSubscription(notification, username, doc.getId());
whereas "notificationName" is only a label used in the sent email:
// options for confirmation email
options.put("recipients", username);
options.put("notifName", notificationName);
11-14-2011 08:40 AM
Hi,
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:
11-14-2011 09:43 AM
"notification" is used in the UserSubscription to identify the notification:
UserSubscription subscription = new UserSubscription(notification, username, doc.getId());
whereas "notificationName" is only a label used in the sent email:
// options for confirmation email
options.put("recipients", username);
options.put("notifName", notificationName);
11-14-2011 12:29 PM
hi Julient
11-23-2011 05:05 PM
Hi,
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.
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.
@Param(name = "username") protected String username;
@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();
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.