Get current ScriptNode object from ExecutionEntity in ExecutionListener?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2013 04:30 PM
What's the best way to get a hold of the ScriptNode instance that triggered an ExecutionListener in a workflow? I've been poking around and printing out the IDs, but haven't found a path to the ScriptNode that's embedded in the workflow.
In javascript, I can get it via the following code:
What's the equivalent in Java? I'm trying to get it through the ExecutionEntity task since I haven't been able to get Spring to give me a reference to the ServiceRegistry.
Thanks
In javascript, I can get it via the following code:
function wfGetNode(){ if( bpm_package.children.length <= 0 ) { throw "no node attached to workflow"; } return bpm_package.children[0];}
What's the equivalent in Java? I'm trying to get it through the ExecutionEntity task since I haven't been able to get Spring to give me a reference to the ServiceRegistry.
Thanks
public class IssuePost extends BaseJavaDelegate implements ExecutionListener{ private Logger _logger = Logger.getLogger( IssuePost.class ); @Override public void notify( DelegateExecution task ) throws Exception { try { NodeRef workflowPackage = null; ActivitiScriptNode scriptNode = ( ActivitiScriptNode )(( ExecutionEntity ) task ).getVariable( WorkflowNotificationUtils.PROP_PACKAGE ); if( scriptNode != null ) { workflowPackage = scriptNode.getNodeRef(); _logger.info( "IssuePost: workflowPackage " + workflowPackage.getId() + " workflow task " + task.getId() + " scriptNode " + scriptNode.getId() + " " + scriptNode.getName()); Scriptable nodeKids = scriptNode.getChildren(); for( int i=0; i < nodeKids.getIds().length; i++ ) { _logger.info( "IssuePost: nodeKids.getIds()[" + i + "] = " + nodeKids.getIds() ); }
Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2013 03:05 AM
you can use helper class in which those services are injected.
That is what alfresco use check out some of the OOTB classes.
That is what alfresco use check out some of the OOTB classes.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2013 10:25 AM
That was my plan, but Spring doesn't seem to be cooperating, and I haven't been able to figure out why. My class does extend the BaseJavaDelegate class. Are there others I should use? I'm having a hard time finding documentation on this.
That being said, I should be able to get the ScriptNode object via other means, like the workflow task. I just haven't been able to find the correct classes/methods yet. Thanks
That being said, I should be able to get the ScriptNode object via other means, like the workflow task. I just haven't been able to find the correct classes/methods yet. Thanks

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2013 04:49 PM
So I've done some more digging. Seems that the Spring config is fine. I've consolidated it to this:
I turned on the Spring debugging, and see this:
I added the logging in the setServiceRegistry method to verify that it's called by Spring (it is) and that the ServiceRegistry isn't null (it isn't).
But when the workflow calls the listener on the RecieveTask a few minutes later, the ServiceRegistry is null in my bean.
Is the workflow creating a new instance of the IssuePost bean, one that hasn't been initialized properly by Spring? Or could Spring clean up the bean somehow? Why is that property null when the workflow calls my listener?
Workflow snippet below:
<bean id="IssuePost" class="com.epnet.alfresco.metadata.listener.IssuePost" depends-on="activitiBeanRegistry"> <property name="serviceRegistry" ref="ServiceRegistry" /> </bean>
I turned on the Spring debugging, and see this:
[factory.support.DefaultListableBeanFactory] Creating shared instance of singleton bean 'IssuePost'[factory.support.DefaultListableBeanFactory] Creating instance of bean 'IssuePost'[factory.support.DefaultListableBeanFactory] Eagerly caching bean 'IssuePost' to allow for resolving potential circular references[factory.support.DefaultListableBeanFactory] Returning cached instance of singleton bean 'ServiceRegistry'[metadata.listener.IssuePost] IssuePost: In setServiceRegistry(). ServiceRegistry is not null[factory.support.DefaultListableBeanFactory] Finished creating instance of bean 'IssuePost'
I added the logging in the setServiceRegistry method to verify that it's called by Spring (it is) and that the ServiceRegistry isn't null (it isn't).
But when the workflow calls the listener on the RecieveTask a few minutes later, the ServiceRegistry is null in my bean.
[metadata.listener.IssuePost] IssuePost: Service Registry still null.
Is the workflow creating a new instance of the IssuePost bean, one that hasn't been initialized properly by Spring? Or could Spring clean up the bean somehow? Why is that property null when the workflow calls my listener?
Workflow snippet below:
<receiveTask id="IssuePost" name="Issue Post"> <extensionElements> <activiti:executionListener event="start" class="com.epnet.alfresco.metadata.listener.IssuePost"></activiti:executionListener> </extensionElements> </receiveTask>

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2013 05:57 PM
Ok, got it working. Took a bit for it to sink in.. 😎
<bean id="AbstractWorkflowDelegate" parent="baseJavaDelegate" abstract="true" depends-on="activitiBeanRegistry" /> <bean id="IssuePost" parent="AbstractWorkflowDelegate" class="com.epnet.alfresco.metadata.listener.IssuePost" />
package com.epnet.alfresco.metadata.listener;public class IssuePost extends BaseJavaDelegate implements ExecutionListener{}
<receiveTask id="IssuePost" name="Issue Post"> <extensionElements> <activiti:executionListener event="start" delegateExpression="${IssuePost}"></activiti:executionListener> </extensionElements> </receiveTask>

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2013 09:57 PM
Now for the first question: how can I get at the ScriptNode? I can get the NodeRef object for the ScriptNode (they have the same Id), but I haven't been able to find the path from the NodeRef to a ScriptNode or ActivitiScriptNode.
The ScriptNode has all the properties I need to get at that were set in my javascript webscripts.
The ScriptNode has all the properties I need to get at that were set in my javascript webscripts.
public void notify( DelegateExecution task ) throws Exception { try { ActivitiScriptNode scriptNode = ( ActivitiScriptNode )(( ExecutionEntity ) task ).getVariable( WorkflowNotificationUtils.PROP_PACKAGE ); if( scriptNode != null ) { NodeRef workflowPackage = scriptNode.getNodeRef(); NodeRef currentNodeRef = nodeService.getChildAssocs( workflowPackage ).get(0).getChildRef(); logger.info( "IssuePost: currentNodeRef " + currentNodeRef.getId() );???

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2013 09:29 AM
Again, with more digging though the source code, I found the way.
String myVal = ( String )nodeService.getProperty( nodeRef, "property name" );
Posting here in case anyone finds this useful.
String myVal = ( String )nodeService.getProperty( nodeRef, "property name" );
Posting here in case anyone finds this useful.
