Search in sources :

Example 1 with MyVariableExtendingSerializable

use of org.jbpm.persistence.session.objects.MyVariableExtendingSerializable in project jbpm by kiegroup.

the class VariablePersistenceStrategyTest method getKnowledgeBaseForExtendingInterfaceVariablePersistence.

private KieBase getKnowledgeBaseForExtendingInterfaceVariablePersistence(String processId, final String variableText) {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId(processId);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("x");
    ObjectDataType extendingSerializableDataType = new ObjectDataType();
    extendingSerializableDataType.setClassName(MyVariableExtendingSerializable.class.getName());
    variable.setType(extendingSerializableDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setName("workItemNode");
    workItemNode.setId(2);
    Work work = new WorkImpl();
    work.setName("MyWork");
    workItemNode.setWork(work);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("Print");
    DroolsAction action = new DroolsConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            Assert.assertEquals(variableText, ((MyVariableExtendingSerializable) context.getVariable("x")).getText());
            ;
        }
    });
    actionNode.setAction(action);
    actionNode.setId(3);
    EndNode endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(4);
    connect(startNode, workItemNode);
    connect(workItemNode, actionNode);
    connect(actionNode, endNode);
    process.addNode(startNode);
    process.addNode(workItemNode);
    process.addNode(actionNode);
    process.addNode(endNode);
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    ((KnowledgeBaseImpl) kbase).addProcess(process);
    return kbase;
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DroolsAction(org.jbpm.workflow.core.DroolsAction) Action(org.jbpm.process.instance.impl.Action) Variable(org.jbpm.process.core.context.variable.Variable) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ArrayList(java.util.ArrayList) ActionNode(org.jbpm.workflow.core.node.ActionNode) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) ProcessContext(org.kie.api.runtime.process.ProcessContext) NamingException(javax.naming.NamingException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException) RollbackException(javax.transaction.RollbackException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) MyVariableExtendingSerializable(org.jbpm.persistence.session.objects.MyVariableExtendingSerializable) EndNode(org.jbpm.workflow.core.node.EndNode) KieBase(org.kie.api.KieBase) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl)

Example 2 with MyVariableExtendingSerializable

use of org.jbpm.persistence.session.objects.MyVariableExtendingSerializable in project jbpm by kiegroup.

the class VariablePersistenceStrategyTest method testExtendingInterfaceVariablePersistence.

@Test
public void testExtendingInterfaceVariablePersistence() throws Exception {
    // Setup
    Environment env = createEnvironment();
    String processId = "extendingInterfaceVariablePersistence";
    String variableText = "my extending serializable variable text";
    KieBase kbase = getKnowledgeBaseForExtendingInterfaceVariablePersistence(processId, variableText);
    KieSession ksession = createSession(kbase, env);
    Map<String, Object> initialParams = new HashMap<String, Object>();
    initialParams.put("x", new MyVariableExtendingSerializable(variableText));
    // Start process and execute workItem
    long processInstanceId = ksession.startProcess(processId, initialParams).getId();
    ksession = reloadSession(ksession, kbase, env);
    long workItemId = TestWorkItemHandler.getInstance().getWorkItem().getId();
    ksession.getWorkItemManager().completeWorkItem(workItemId, null);
    // Test
    Assert.assertNull(ksession.getProcessInstance(processInstanceId));
}
Also used : MyVariableExtendingSerializable(org.jbpm.persistence.session.objects.MyVariableExtendingSerializable) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) Environment(org.kie.api.runtime.Environment) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Aggregations

MyVariableExtendingSerializable (org.jbpm.persistence.session.objects.MyVariableExtendingSerializable)2 KieBase (org.kie.api.KieBase)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NamingException (javax.naming.NamingException)1 HeuristicMixedException (javax.transaction.HeuristicMixedException)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 NotSupportedException (javax.transaction.NotSupportedException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 Work (org.jbpm.process.core.Work)1 Variable (org.jbpm.process.core.context.variable.Variable)1 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)1 WorkImpl (org.jbpm.process.core.impl.WorkImpl)1 Action (org.jbpm.process.instance.impl.Action)1 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)1 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 DroolsAction (org.jbpm.workflow.core.DroolsAction)1 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)1