cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow Context - getting node content

stacktrace
Champ in-the-making
Champ in-the-making
Hello all,

I am really bad stuck trying to figure out how to get content of the node that has been submitted for the approval. I have tried by using ActionHandler jBPM class and defining action in workflow definition but I cant get the content of the node.

I want that when user submits the node (document actually from web interface), after document has been approved to get the contents of the node/document and do my own processing. My idea was to assign my jBPM action handler and to get data somehow from org.jbpm.graph.exe.ExecutionContext in the method org.jbpm.graph.def.ActionHandler.execute(). However call such as

nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT) where
((NodeRef)executionContext.getContextInstance().getVariable("bpm_package")).getNodeRef();
returns null. I have tried like almost all possible propereties but I really can not get reference to actual data.

I would really appreciate response, cause this is probably like 1-2 lines of code and it should not take too much time.

Thanks in advance and cheers

PS Actually I must use, if possible, the ActionHandler class.
6 REPLIES 6

stacktrace
Champ in-the-making
Champ in-the-making
I have managed to find this but it does not help. http://forums.alfresco.com/viewtopic.php?t=8699&highlight=workflow+jbpm

Strange thing is that I can get information about the node but cant get the actual content:

nodeService.getProperty(nodeRef, ContentModel.PROP_NAME) returns value different than NULL

nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED) returns value different than NULL

nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_UUID) returns value different than NULL

but

nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT) returns NULL.

I have following as well:

contentService.getReader( nodeRef, ContentModel.PROP_CONTENT)  returns NULL/

I have manually uploaded some txt file with content, and I choose option on the file thru Alfresco interface 'Start Advanced Workflow'. I have assigned my handler to handle transition.

Workflow definition is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.1" name="wf:myReview">

    <swimlane name="initiator" />

    <start-state name="start">
        <task name="wf:submitReviewTask" swimlane="initiator" />
        <transition name="one" to="review" />
    </start-state>

    <swimlane name="reviewer">
        <assignment class="org.alfresco.repo.workflow.jbpm.AlfrescoAssignment">
            <actor>#{bpm_assignee}</actor>
        </assignment>   
    </swimlane>

    <task-node name="review">
        <task name="wf:reviewTask" swimlane="reviewer">
            <event type="task-create">
                <script>
                    if (bpm_workflowDueDate != void) taskInstance.dueDate = bpm_workflowDueDate;
                    if (bpm_workflowPriority != void) taskInstance.priority = bpm_workflowPriority;
                </script>
            </event>
        </task>
        <transition name="reject" to="rejected" />
        <transition name="approve" to="approved">
         <action class="com.mycompany.core.alfresco.MyHandler"/>
      </transition>
    </task-node>

    <task-node name="rejected">
        <task name="wf:rejectedTask" swimlane="initiator" />
        <transition name="two" to="end" />
    </task-node>

    <task-node name="approved">
        <task name="wf:approvedTask" swimlane="initiator" />
        <transition name="three" to="end">
        <script>
         
        </script>
      </transition>
    </task-node>

    <end-state name="end" />

</process-definition>

My handler code is as shown above.

Workflow completes all ok, I get the task to approve, however I can not get the content of the document in question.

Can someone just confirm that this is doable or not (requires huge modifications).

Thanks in advance

davidc
Star Contributor
Star Contributor
Hello,

You can use Alfresco Javascript within your process definition to access the content being routed via workflow.

e.g. to access the content of the first document

bpm_package.children[0].content;

See http://wiki.alfresco.com/wiki/WorkflowAdministration#Actions_.26_Scripting

stacktrace
Champ in-the-making
Champ in-the-making
Thank you David for response.

I have tried to make it Java script based, but I cant figure out how to extract the content. I mean, does it actually make any difference if I am using Java script, shouldn't I be able to do it from Java code since Java script is interpreted in Java anyways?

We were thinking on starting using Alfresco in some real business cases, we would modify it according to our needs become partner and so forth (and I ain't saying that cause I am stuck), so this kind of is really pushing us back (we are demonstrating powers-to-be that it is a viable invesment).

For our integration platform we need to exchange data between Alfresco as client, ESB and some other clients, with another Alfresco instance running in ESB as our canonical model (XML Schema/WSDL based) manager (persistent repository, versioning etc) with our addons.

I apologize for spamming, if anyone has done something to share, similar I would really appreciate it.

Cheers all


Here is the class being executed as jBpm action handler:

———————————————————————–
import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.jbpm.JBPMNode;
import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.log4j.Logger;
import org.jbpm.graph.exe.ExecutionContext;
import org.springframework.beans.factory.BeanFactory;

import com.acando.mia.core.alfresco.MyHandler;


public class Test extends JBPMSpringActionHandler {
   
   private static final Logger logger = Logger.getLogger(MyHandler.class);
   
   private BeanFactory factory;
   
   @Override
   protected void initialiseHandler(BeanFactory factory) {
      this.factory = factory;
   }

   public void execute(ExecutionContext executionContext) throws Exception {   
      try {
         Object res = executionContext.getContextInstance().getVariable("bpm_package");
         if(res == null) {
            //never enters here
            logger.fatal("bpm_package is null");
            return;
         }
         final NodeRef nodeRef = ((JBPMNode) res).getNodeRef();
         if(nodeRef == null) {
             //never enters here
            logger.fatal("NodeRef is null");
            return;
         }
         //prints value
         logger.fatal("Node ref id:" + nodeRef.getId());
         
         NodeService nodeService = (NodeService) this.factory.getBean("nodeService");
         //prints value
         logger.fatal("Prop name = " + nodeService.getProperty(nodeRef, ContentModel.PROP_NAME));
         //prints value
         logger.fatal("Prop created= " + nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED));
         //prints value
         logger.fatal("Prop uuid = " + nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_UUID));   
         if(nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT) != null) {
            // never enters here
            logger.warn("Content property is not null");
         }
         ContentService contentService = (ContentService) this.factory.getBean("contentService");
         ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
         
         if(contentReader == null) {
             //always goes here
            logger.fatal("Content reader not found");
            return;
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
———————————————————————–

davidc
Star Contributor
Star Contributor
Your Java is on the right track, except you're attempting to get content off the workflow package; not the children of the workflow package i.e. the documents themselves.

You also need to use nodeService.getChildren()

stacktrace
Champ in-the-making
Champ in-the-making
Thank you David for your kind help. We have managed to figure it out with that tip so we are now up and running. 😃

Cheers

huberd
Champ in-the-making
Champ in-the-making
Thank you David for your kind help. We have managed to figure it out with that tip so we are now up and running. 😃

Cheers

Hi,

I do not understand how to used nodeService.getChildren()

Could you please give us the source of your code updated with the solution to solved your original problem.

Many thanks.