JBoss Community

Re: JBPM5 Implementation

created by Donald Walters in jBPM - View the full discussion

Thanks Guys. I was able to make something work based on the answers above. It may not be as clean as it aught to be it is similar to what I have in the JBPM4.

 

Basically i created a dummy interface... This is just so that the BPMN2 xml won't scream :)

 

<itemDefinition id="_2_InMessageType" structureRef="java.lang.String"/>

    <message id="_2_InMessage" itemRef="_2_InMessageType"/>

    <interface id="_2_ServiceInterface" name="com.core.DummyService">

        <operation id="_2_ServiceOperation" name="handle">

            <inMessageRef>_2_InMessage</inMessageRef>

        </operation>

    </interface>

 

...

 

<serviceTask id="prompt6" name="prompt6" operationRef="_2_ServiceOperation" implementation="Other">

            <ioSpecification>

                <dataInput id="prompt6_type" name="type"/>

                <dataInput id="prompt6_processItem" name="processItem"/>

                <dataInput id="prompt6_message" name="message"/>

                <dataOutput id="prompt6_result" name="processItem"/>

                <inputSet>

                    <dataInputRefs>prompt6_type</dataInputRefs>

                    <dataInputRefs>prompt6_processItem</dataInputRefs>

                    <dataInputRefs>prompt6_message</dataInputRefs>

                </inputSet>

                <outputSet>

                    <dataOutputRefs>prompt6_result</dataOutputRefs>

                </outputSet>

            </ioSpecification>

            <dataInputAssociation>

                <targetRef>prompt6_message</targetRef>

                <assignment>

                    <from xsi:type="tFormalExpression">Hello World!!</from>

                    <to xsi:type="tFormalExpression">prompt6_message</to>

                </assignment>

            </dataInputAssociation>

            <dataInputAssociation>

                <targetRef>prompt6_type</targetRef>

                <assignment>

                    <from xsi:type="tFormalExpression">com.core.test.Prompt</from>

                    <to xsi:type="tFormalExpression">prompt6_type</to>

                </assignment>

            </dataInputAssociation>

            <dataInputAssociation>

                <sourceRef>processItem</sourceRef>

                <targetRef>prompt6_processItem</targetRef>

            </dataInputAssociation>

            <dataOutputAssociation>

                <sourceRef>prompt6_result</sourceRef>

                <targetRef>processItem</targetRef>

            </dataOutputAssociation>

        </serviceTask>

 

 

 

Then I created a handler and register it for the Service Task. This will take the process type parameter and create the necessary class.

 

@Override

    public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

        String className = (String) workItem.getParameter("processType");

        try {

            Class clazz = Class.forName(className);

 

 

            Constructor constructor = clazz.getConstructor(Map.class);

 

 

            ProcessItem processItem = (ProcessItem)workItem.getParameter("processItem");

            Map params = workItem.getParameters();

            params.remove("Interface");

            params.remove("Operation");

            params.remove("ParameterType");

            params.remove("processItem");

 

 

            GenericProcess process =(GenericProcess) constructor.newInstance(params);

           

            Object result = process.execute(processItem);

            Map<String, Object> results = new HashMap<String, Object>();

            results.put("processItem", result);

        System.out.println("=================================\n");

            manager.completeWorkItem(workItem.getId(), results);

        } catch (ClassNotFoundException e) {

            e.printStackTrace();

        } catch (InstantiationException e) {

            e.printStackTrace();

        } catch (IllegalAccessException e) {

            e.printStackTrace();

        } catch (NoSuchMethodException e) {

            e.printStackTrace();

        } catch (InvocationTargetException e) {

            e.printStackTrace();

        }

    }

 

Also, I used the timer event to do the state with <on event="timer>

 

<intermediateCatchEvent id="wait4" name="wait4">

            <timerEventDefinition>

                <timeDuration>180000</timeDuration>

            </timerEventDefinition>

        </intermediateCatchEvent>

 

But I have 1 issue with that. The timer application does not exist after the time is expired. I think it is still there waiting. (not sure on this)

 

Also, how do I get the activity (node id) in order to cancel the timer?

Reply to this message by going to Community

Start a new discussion in jBPM at Community