08-02-2012 03:54 PM
${person.properties["cm:firstName"]} ${person.properties["cm:lastName"]}
I'd like to do the same thing using the assignee user NodeRef, but this doesn't appear to be available in the template. Looking at the code, it seems I'll have to extend MailActionExecuter and override the createEmailTemplateModel method so that I can inject this argument for the template, and then override the Spring bean to wire it in.08-03-2012 01:25 AM
@Override
public void sendNotification(NotificationContext notificationContext)
{
List<String> to = notificationContext.getTo();
if (to != null && to.size() == 1) {
String assignee = to.get(0);
Map<String, Serializable> args = notificationContext.getTemplateArgs();
try {
NodeRef personRef = serviceRegistry.getPersonService().getPerson(assignee, false);
args.put("assignee", new TemplateNode(personRef, serviceRegistry, null));
notificationContext.setTemplateArgs(args);
} catch (NoSuchPersonException ex) {
logger.warn("Could not find a person with the name " + assignee);
}
}
super.sendNotification(notificationContext);
}
Then I overrode the "emailNotificationProvider" in my custom context file, using this new class.
<#assign assignee=args["assignee"]/>
Now I'm able to use the assignee user as follows:
<#if assignee?exists>
${assignee.properties["cm:firstName"]} ${assignee.properties["cm:lastName"]}
</#if>
02-26-2019 09:40 AM
Missing code how was implemented serviceRegistry
package PACKAGE_NAME; // replace with own package name.
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.template.TemplateNode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.notification.NotificationContext;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.NoSuchPersonException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;public class EMailNotificationProvider extends org.alfresco.repo.notification.EMailNotificationProvider {
private static Log logger = LogFactory.getLog(EMailNotificationProvider.class);private ServiceRegistry serviceRegistry;
@Override
public void sendNotification(NotificationContext notificationContext) {
List<String> to = notificationContext.getTo();
if (to != null && to.size() == 1) {
String assignee = to.get(0);
Map<String, Serializable> args = notificationContext.getTemplateArgs();
try {
NodeRef personRef = this.serviceRegistry.getPersonService().getPerson(assignee, false);
args.put("assignee", new TemplateNode(personRef, this.serviceRegistry, null));
notificationContext.setTemplateArgs(args);
} catch (NoSuchPersonException ex) {
logger.error("Could not find a person with the name " + assignee);
} catch (Exception ex){
logger.error("Exception: " + ex.getMessage());
}
}
super.sendNotification(notificationContext);
}
/**
* @param serviceRegistry provides access to the service APIs
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
}
Missing example of bean definition in file module-context.xml
<!-- EMail notification provider, source https://github.com/Alfresco/alfresco-repository/blob/master/src/main/resources/alfresco/notification-services-context.xml -->
<bean id="emailNotificationProvider" class="PACKAGE_NAME.EMailNotificationProvider" init-method="init">
<property name="notificationService" ref="notificationService"/>
<property name="nodeService" ref="NodeService"/>
<property name="actionService" ref="ActionService"/>
<property name="personService" ref="PersonService"/>
<property name="repository" ref="repositoryHelper"/>
<property name="fileFolderService" ref="FileFolderService"/>
<property name="repoAdminService" ref="RepoAdminService"/>
<property name="serviceRegistry" ref="ServiceRegistry" />
</bean>
Tags
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.