-
1. Re: Unclear on how to get a Process param into my WorkItem
calca Aug 10, 2011 12:44 PM (in response to olddave)I think the idea is that you declare the process variables as a parameter of the node, and then use
workItem.getParameter("...")
Demian
-
2. Re: Unclear on how to get a Process param into my WorkItem
olddave Aug 10, 2011 12:54 PM (in response to calca)I tried that. So in my Process parameters definition in the property sheet for the Process I entered
myContext as an Object type and the fully qualified class name.
Then in the "Parameter Mapping" section of my custom WorkItem I put the same "Parameter" name "myContext" and the fully qualified class name again in the "Variable" part.
I get this
Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to com.example.tdm.AClass
Ed
-
3. Re: Unclear on how to get a Process param into my WorkItem
olddave Aug 10, 2011 1:04 PM (in response to calca)I just realised you think this parameter is for this Workitem only. It is not, one of my tasks populates 2 of the fields in this parameter and it needs to be passed onto a workitem later in the Process which contributes values to 2 other fields in the parameter and so on.
That is why it is at Process level and so on. I would have thought this would be quite a common requirement?
Ed
-
4. Re: Unclear on how to get a Process param into my WorkItem
calca Aug 10, 2011 1:28 PM (in response to olddave)Yes, you define the item type:
<itemDefinition id="_myVariableItem" structureRef="com.MyVariableClass" />
Then, define the process variables:
<property id="myVariable" itemSubjectRef="_myVariableItem"/>
And then you declare it as inputs or outputs of the nodes that will needs it for input, needs to modify it (will be output), or both:
<task ...
<dataInput id="_17_myVariableInput" name="myVariable" /> -> this is the name that will be used inside the work item handler.
..
<inputSet>
...
<dataInputRefs>_17_myVariableInput</dataInputRefs>
...
</inputSet>
<dataInputAssociation>
<sourceRef>myVariable</sourceRef> -> this is the name of the process variable
<targetRef>_17_myVariableInput</targetRef>
</dataInputAssociation>
And for output:
<dataOutput id="_17_myVariableOutput" name="myVariable" /> -> name that will be passed in the key of the .completeWorkItem result map.
...
<outputSet>
<dataOutputRefs>_17_myVariableOutput</dataOutputRefs>
</outputSet>
...
<dataOutputAssociation>
<sourceRef>_17_myVariableOutput</sourceRef>
<targetRef>myVariable</targetRef> -> here we assign the internal variable to process variable
</dataOutputAssociation>
I usually make it writing bpmn file, and not eclipse, but I think that should work with Parameter Mapping.
Regards,
Demian
-
5. Re: Unclear on how to get a Process param into my WorkItem
olddave Aug 10, 2011 2:13 PM (in response to calca)Well it seems that this is where the problem lies. My users will never edit xml, they will use the property sheet of my workitem in the BPMN2 designer. Which looks like this
As you can see there are no inputSet dataInputAssociation etc. Ignore the double period in the classname it is just for example.
I made another post about this. Answers here assume that people are editing xml, whereas if you have a nice graphical designer the end users are likely to use that. But I have found no where that explains how you map input and output for parameters using the property sheet.
Ed
-
6. Re: Unclear on how to get a Process param into my WorkItem
calca Aug 10, 2011 2:16 PM (in response to olddave)In Parameter Mapping, I think you have to put:
{param=processVar,...}
where param is the name of the parameter used inside the task and processVar is the process variable (you should define it in process properties sheet).
And the same for Result Mapping.
Hope it helps,
Demian
-
7. Re: Unclear on how to get a Process param into my WorkItem
olddave Aug 11, 2011 9:11 AM (in response to calca)Yes, that is right, except as I said it does not work.
I had Process Parameter "myContext" as an Object type and the fully qualified class name "com.example.tdm.workflow.AClass".
I had WorkItem Parameter Mapping "myContext" and the fully qualified class name "com.example.tdm.workflow.AClass".
When I enter my
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { AClass aObject = (AClass)workItem.getParameter("myContext"); There is no aObject, it is null. So I figure I am doing something wrong.
Thx.
Ed
-
8. Re: Unclear on how to get a Process param into my WorkItem
calca Aug 11, 2011 9:17 AM (in response to olddave)But I think in the parameter mapping you don't have to put the full class name, just the param name and the process variable name.
-
9. Re: Unclear on how to get a Process param into my WorkItem
olddave Aug 11, 2011 10:39 AM (in response to calca)Tried that too.
{code}
AClass myContext = (AClass)workItem.getParameter("myContext"); {/code}
When the fully qualified classname as the value I'd get this:
Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to com.example.tdm.workflow.AClass
When I simply used the name of the Process parameter it returned null.
Maybe one of the developers could chip in at this point. The documentation that I have read simply does not cover this stuff, unless you want to edit xml
Ed
-
10. Re: Unclear on how to get a Process param into my WorkItem
eaa Aug 11, 2011 10:38 AM (in response to olddave)Can you share your process definition? Also, if you debug your WorkItemHandler code, what is the value of workItem.getParameter("myContext")?
-
11. Re: Unclear on how to get a Process param into my WorkItem
olddave Aug 11, 2011 1:05 PM (in response to eaa)I cannot really share the full xml at the moment. But here is the generate xml when I use Process parameter workflowContext with variable com.example.tdm.workflow.AClass and the WorkItem with a parameter workflowContext and variable workflowContext
{code}
...
<itemDefinition id="_workflowContextItem" structureRef="com.example.tdm.workflow.AClass" />
<process processType="Private" isExecutable="true" id="_94ff85d0-5463-4b53-b5ce-3fa3c60eaf8d" name="Load_Stuff" >
<!-- process variables -->
<property id="workflowContext" itemSubjectRef="_workflowContextItem"/>
...
<task id="_3" name="Load_Test" tns:taskName="ETLGroup" >
<ioSpecification>
<dataInput id="_3_workflowContextInput" name="workflowContext" />
<dataOutput id="_3_workflowContextOutput" name="workflowContext" />
<inputSet>
<dataInputRefs>_3_workflowContextInput</dataInputRefs>
</inputSet>
<outputSet>
<dataOutputRefs>_3_workflowContextOutput</dataOutputRefs>
</outputSet>
</ioSpecification>
<dataInputAssociation>
<sourceRef>workflowContext</sourceRef>
<targetRef>_3_workflowContextInput</targetRef>
</dataInputAssociation>
<dataOutputAssociation>
<sourceRef>_3_workflowContextOutput</sourceRef>
<targetRef>workflowContext</targetRef>
</dataOutputAssociation>
</task>
...
{code}
What I get in the WorkItem is a String value "workflowContext" not the Process parameter of the same name. This is using the org.drools.eclipse 5.2.0 plugin designer. I cannot see any association between the Process parameter and the WorkItem parameters.
Ed
-
12. Re: Unclear on how to get a Process param into my WorkItem
eaa Aug 12, 2011 4:41 AM (in response to olddave)I have prepared a simple test showing how to pass parameters to a Work Item. You can find it here: https://github.com/esteban-aliverti/JBPM-Samples/tree/master/Simple-WorkItem-Sample Please take a look at it.
-
13. Re: Unclear on how to get a Process param into my WorkItem
olddave Aug 12, 2011 6:16 AM (in response to eaa)Hi,
This confirmed that there are no structural differences between what the org.drools.eclipse plugin produces and what you coded.
I found the problem. I had accidently used the wrong case for the first character of parameter "workflowContext" for my workitem parameter in the UI. When you dismiss the dialog the Property sheet does NOT update until you tab or click out of that property, so it looked fine and I clicked on another Task node without realizing my mistake. I ran my tests with the wrong parameter name and had not checked seen the incorrect name in the xml. I fixed the name in the xml and re-ran my test, and it worked!
Thank you
Ed