Fórum

Using velocity in Kaleo workflow

Petr Tresl, modificado 12 Anos atrás.

Using velocity in Kaleo workflow

New Member Postagens: 4 Data de Entrada: 15/03/11 Postagens Recentes
Hello.

I was looking for some examples or solutions how to use velocity in Kaleo workflow but did not find anything usable on internet. The "try and see" approach did not work so I would like to ask the community.

My goal is to use the Kaleo workflow for approval of web content articles (and also other content in the future) while keeping workflow participants well informed about what is happening. What I would like to implement is:

1) provide rich content of messages sent to workflow participants - add to standard notification message of type "You have a new submission waiting for your review in the workflow." (see for example the single-approver-definition.xml provided as basic workflow example) basic information about web content:

a) asset title
b) asset author
c) date created
d) workflow status
e) task comments

Is it possible to provide rich content of messages and how (what is the working code)?

2) notify content creator when the submission is approved (either in any workflow stage or at least after final approval) - unfortunately Liferay (6.0.6) returns an "Error" when I try to add workflow definition that contains "<user />" in a notification recipients list (see example code below); when I use for example specific mail address "<address>test@liferay.com</address>" everything works fine:

      <notification>
          <name>Final Approval Notification</name>
          <execution-type>onEntry</execution-type>
          <template>Your submission has been approved.</template>
          <template-language>text</template-language>
          <notification-type>email</notification-type>
          <recipients>
              <user />
          </recipients>
      </notification>


This seems like a Liferay bug that does not allow using "<user />" in recipients list. Do you know any workaround (either Kaleo workflow fix or code to assign notification recipients dynamically)?

Thanks for your advice.

Regards, Petr
thumbnail
Sagar A Vyas, modificado 12 Anos atrás.

RE: Using velocity in Kaleo workflow

Liferay Master Postagens: 679 Data de Entrada: 17/04/09 Postagens Recentes
Hi Petr,

Best way to explore workflow tags.

Just go through respective liferay-workflow-definition_6_X_Y.xsd file of your kaleo version.

Thanks,
Sagar Vyas
Petr Tresl, modificado 12 Anos atrás.

RE: Using velocity in Kaleo workflow

New Member Postagens: 4 Data de Entrada: 15/03/11 Postagens Recentes
Hi Sagar,

thank you. Of course I examined the liferay-workflow-definition_6_0_0.xsd file included in my installation of Liferay portal (6.0.6 CE) and I tested various options before I asked my question. The definition allows using address, role and user in a recipients list. And user definition allows user-id, screen-name, and email-address. Everything works fine if you use any static user id, screen name or email address.

The definition also allows using role and user in an assignments list. There is an option for assignments to use the "<user />" tag that allows to assign the task back to the user who created the asset. However, the "<user />" tag is not accepted in the recipient list. I am not sure if this is a Liferay bug or a Liferay "feature".

In any case, sending a notification to the creator of the asset when the asset is approved is a logical step in any asset workflow so I am looking for a workaround (either Kaleo workflow fix, instructions where to obtain and how to install a newer version of Kaleo, or code how to assign notification recipients dynamically) to be able to realize this functionality.

Regards,
Petr
thumbnail
Marcellus Tavares, modificado 12 Anos atrás.

RE: Using velocity in Kaleo workflow

Regular Member Postagens: 142 Data de Entrada: 26/10/09 Postagens Recentes
Hey Petr,

For #1, take a look on this article, it contains details that can help you to create the templates. Not all the values you're looking for can be found on workflow context though. I guess you should try to use the serviceLocator in order to get all the info you need.

Regarding the #2, if it's an error, could you create a LPS ticket describing the error message and your environment?

Regards
Petr Tresl, modificado 12 Anos atrás.

RE: Using velocity in Kaleo workflow

New Member Postagens: 4 Data de Entrada: 15/03/11 Postagens Recentes
Hi Marcellus,

thank you for your advise. Regarding #1, I read the recommended article and few other ones before I asked my question. I will try to rephrase my original question to go to core of the problem: Is there any way to include in workflow e-mails basic information about (at least) web content (e.g. asset title, asset creator, date created, workflow status, task reviewer comments) without hacking the Liferay code? If it is, please could you just provide a working example? If it is not, please could you provide a working example how to hack the Liferay code to provide the requested functionality for web content workflow that could be used by inexperienced Java developers like me? Thanks. I believe many people would really appreciate it.

Regarding #2, I will create the LPS ticket as soon as I collect more information. Just for your information, I am using standard Liferay 6.0.6 CE installation (source file liferay-portal-tomcat-6.0.6-20110225.zip) with 7Cogs test environment running on Windows. Liferay just returns "Error" in UI and no error is logged in Tomcat console.

Another question, is it possible to disable sending assignment notification when a user assigns a workflow task to himself? If it is, how?

Regards,
Petr
thumbnail
Marcellus Tavares, modificado 12 Anos atrás.

RE: Using velocity in Kaleo workflow

Regular Member Postagens: 142 Data de Entrada: 26/10/09 Postagens Recentes
Hi Petr, here's a piece of code that you can use to get the fields you want:


<notification>
	<name>Review Notification</name>
	<template>
		#set ($workflowHandlerRegistryUtil = $portal.getClass().forName("com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil"))		
		#set($workflowHandler = $workflowHandlerRegistryUtil.getWorkflowHandler($entryClassName))
		#set ($classPK = $getterUtil.getInteger($entryClassPK))
		#set ($assetRenderer = $workflowHandler.getAssetRenderer($classPK))
		#set ($assetRendererFactory = $workflowHandler.getAssetRendererFactory())
		#set ($assetEntry = $assetRendererFactory.getAssetEntry($assetRendererFactory.getClassName(), $assetRenderer.getClassPK()))
		#set ($locale = $localeUtil.getDefault())

		Asset title: ${assetRenderer.getTitle($locale)}
		Asset creator: ${assetEntry.userName}
		Date created: ${assetEntry.createDate}
		Comments: ${taskComments}
	</template>
	<template-language>velocity</template-language>
	<notification-type>email</notification-type>
	<execution-type>onAssignment</execution-type>
</notification>


Regarding your other question, It's not possible rt now to disable that. But it would be a good thing to be implemented. Could you create a LPS ticket with your suggestion?

Regards
Petr Tresl, modificado 12 Anos atrás.

RE: Using velocity in Kaleo workflow

New Member Postagens: 4 Data de Entrada: 15/03/11 Postagens Recentes
Hello Marcellus,

thank you for a piece of code you provided. I used the code to replace a reviewer notification in a standard example workflow definition (single-approver-definition.xml) but it seems it is not working. I receive the following errors in Tomcat console:

13:31:43,443 ERROR [PathElementMessageListener:40] Unable to process message {de
stinationName=liferay/kaleo_graph_walker, responseDestinationName=null, response
Id=null, payload=com.liferay.portal.workflow.kaleo.runtime.graph.PathElement@104
f7a1, values=null}
com.liferay.portal.workflow.kaleo.runtime.notification.NotificationMessageGenera
tionException: Unable to generate notification message
        at com.liferay.portal.workflow.kaleo.runtime.notification.VelocityNotifi
cationMessageGenerator.generateMessage(VelocityNotificationMessageGenerator.java
:63)
        at com.liferay.portal.workflow.kaleo.runtime.notification.NotificationUt
il._sendKaleoNotification(NotificationUtil.java:57)
        at com.liferay.portal.workflow.kaleo.runtime.notification.NotificationUt
il.sendKaleoNotifications(NotificationUtil.java:44)
        at com.liferay.portal.workflow.kaleo.runtime.node.TaskNodeExecutor.doEnt
er(TaskNodeExecutor.java:100)
        at com.liferay.portal.workflow.kaleo.runtime.node.BaseNodeExecutor.enter
(BaseNodeExecutor.java:43)
        at com.liferay.portal.workflow.kaleo.runtime.graph.DefaultGraphWalker.fo
llow(DefaultGraphWalker.java:78)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:110)
        at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionIntercept
or.invoke(DynamicDataSourceTransactionInterceptor.java:44)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invok
e(ExposeInvocationInterceptor.java:89)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:202)
        at $Proxy277.follow(Unknown Source)
        at com.liferay.portal.workflow.kaleo.runtime.graph.messaging.PathElement
MessageListener.doReceive(PathElementMessageListener.java:64)
        at com.liferay.portal.workflow.kaleo.runtime.graph.messaging.PathElement
MessageListener.receive(PathElementMessageListener.java:37)
        at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(In
vokerMessageListener.java:63)
        at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(Paralle
lDestination.java:61)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908)
        at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation o
f method 'getTitle' in  class com.liferay.portlet.journal.asset.JournalArticleAs
setRenderer threw exception java.lang.IllegalArgumentException: wrong number of
arguments at Review Notification15575[line 10, column 54]
        at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationExc
eption(ASTMethod.java:337)
        at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.j
ava:290)
        at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTRefer
ence.java:262)
        at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTRefere
nce.java:342)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.
java:336)
        at org.apache.velocity.Template.merge(Template.java:328)
        at org.apache.velocity.Template.merge(Template.java:235)
        at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.j
ava:381)
        at com.liferay.portal.velocity.VelocityEngineImpl.mergeTemplate(Velocity
EngineImpl.java:155)
        at com.liferay.portal.workflow.kaleo.runtime.notification.VelocityNotifi
cationMessageGenerator.generateMessage(VelocityNotificationMessageGenerator.java
:56)
        ... 26 more
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.do
Invoke(UberspectImpl.java:389)
        at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.in
voke(UberspectImpl.java:378)
        at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.j
ava:270)
        ... 34 more


I am using standard Liferay 6.0.6 CE installation (source file liferay-portal-tomcat-6.0.6-20110225.zip) with 7Cogs test environment running on Windows.

Regarding the other question, I will create the LPS as you recommend.

Regards,

Robert
Gauri Bansode, modificado 12 Anos atrás.

RE: Using velocity in Kaleo workflow

Junior Member Postagens: 44 Data de Entrada: 04/05/11 Postagens Recentes
Hi,

I am sorry for posting here again because I have already posted a new thread.but I did not get response so decided to post here as it is related to my doubt.

I also want to add task reviewer Comments into the workflow emails.I tried using
${taskComments
} in template tag in my WF defination but I could not get comments in my email.

If anybody knows the right approach how to get Comments given by reviewer into email, please help me.

Thanks in advance.


Regards,
Gauri
Rose Navas, modificado 9 Anos atrás.

RE: Using velocity in Kaleo workflow

New Member Postagens: 12 Data de Entrada: 04/08/14 Postagens Recentes
Hi all

I have the same problem. I have not been able to send task comments in the mail notification

Anyone can help me please?

Please apologise my English.

thanks in advance