Search in sources :

Example 1 with Variable

use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.

the class XmlWorkflowProcessDumper method visitVariables.

public static void visitVariables(List<Variable> variables, StringBuilder xmlDump) {
    if (variables != null && variables.size() > 0) {
        xmlDump.append("    <variables>" + EOL);
        for (Variable variable : variables) {
            xmlDump.append("      <variable name=\"" + variable.getName() + "\" >" + EOL);
            visitDataType(variable.getType(), xmlDump);
            Object value = variable.getValue();
            if (value != null) {
                visitValue(variable.getValue(), variable.getType(), xmlDump);
            }
            xmlDump.append("      </variable>" + EOL);
        }
        xmlDump.append("    </variables>" + EOL);
    }
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable)

Example 2 with Variable

use of org.jbpm.process.core.context.variable.Variable 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 3 with Variable

use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.

the class WorkItemPersistenceTest method getWorkItemProcess.

private RuleFlowProcess getWorkItemProcess(String processId, String workName) {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId(processId);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("UserName");
    variable.setType(new StringDataType());
    variables.add(variable);
    variable = new Variable();
    variable.setName("MyObject");
    variable.setType(new ObjectDataType());
    variables.add(variable);
    variable = new Variable();
    variable.setName("Number");
    variable.setType(new IntegerDataType());
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    HumanTaskNode workItemNode = new HumanTaskNode();
    workItemNode.setName("workItemNode");
    workItemNode.setId(2);
    workItemNode.addInMapping("Attachment", "MyObject");
    workItemNode.addOutMapping("Result", "MyObject");
    workItemNode.addOutMapping("Result.length()", "Number");
    Work work = new WorkImpl();
    work.setName(workName);
    Set<ParameterDefinition> parameterDefinitions = new HashSet<ParameterDefinition>();
    ParameterDefinition parameterDefinition = new ParameterDefinitionImpl("ActorId", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Content", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Comment", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    work.setParameterDefinitions(parameterDefinitions);
    work.setParameter("ActorId", "#{UserName}");
    work.setParameter("Content", "#{Person.name}");
    workItemNode.setWork(work);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    connect(startNode, workItemNode);
    connect(workItemNode, endNode);
    process.addNode(startNode);
    process.addNode(workItemNode);
    process.addNode(endNode);
    return process;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) Variable(org.jbpm.process.core.context.variable.Variable) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) ArrayList(java.util.ArrayList) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) ParameterDefinitionImpl(org.jbpm.process.core.impl.ParameterDefinitionImpl) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) EndNode(org.jbpm.workflow.core.node.EndNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) HashSet(java.util.HashSet)

Example 4 with Variable

use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitVariables.

public static void visitVariables(List<Variable> variables, StringBuilder xmlDump) {
    if (!variables.isEmpty()) {
        xmlDump.append("    <!-- process variables -->" + EOL);
        for (Variable variable : variables) {
            if (variable.getMetaData("DataObject") == null) {
                xmlDump.append("    <property id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
                if (variable.getType() != null) {
                    xmlDump.append("itemSubjectRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute((String) variable.getMetaData("ItemSubjectRef")) + "\"");
                }
                // TODO: value?
                Map<String, Object> metaData = getMetaData(variable.getMetaData());
                if (metaData.isEmpty()) {
                    xmlDump.append("/>" + EOL);
                } else {
                    xmlDump.append(">" + EOL + "      <extensionElements>" + EOL);
                    writeMetaData(metaData, xmlDump);
                    xmlDump.append("      </extensionElements>" + EOL + "    </property>" + EOL);
                }
            }
        }
        for (Variable variable : variables) {
            if (variable.getMetaData("DataObject") != null) {
                xmlDump.append("    <dataObject id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
                if (variable.getType() != null) {
                    xmlDump.append("itemSubjectRef=\"_" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\"");
                }
                // TODO: value?
                Map<String, Object> metaData = getMetaData(variable.getMetaData());
                if (metaData.isEmpty()) {
                    xmlDump.append("/>" + EOL);
                } else {
                    xmlDump.append(">" + EOL + "      <extensionElements>" + EOL);
                    writeMetaData(metaData, xmlDump);
                    xmlDump.append("      </extensionElements>" + EOL + "    </property>" + EOL);
                }
            }
        }
        xmlDump.append(EOL);
    }
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable)

Example 5 with Variable

use of org.jbpm.process.core.context.variable.Variable in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method visitVariableScope.

private void visitVariableScope(VariableScope variableScope, String prefix, StringBuilder xmlDump, Set<String> dumpedItemDefs) {
    if (variableScope != null && !variableScope.getVariables().isEmpty()) {
        int variablesAdded = 0;
        for (Variable variable : variableScope.getVariables()) {
            String itemDefId = (String) variable.getMetaData("ItemSubjectRef");
            if (itemDefId == null) {
                itemDefId = prefix + variable.getName();
            }
            if (itemDefId != null && !dumpedItemDefs.add(itemDefId.intern())) {
                continue;
            }
            if (!visitedVariables.add(variable.getName())) {
                continue;
            }
            ++variablesAdded;
            xmlDump.append("  <itemDefinition id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(itemDefId) + "\" ");
            if (variable.getType() != null && !"java.lang.Object".equals(variable.getType().getStringType())) {
                xmlDump.append("structureRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getType().getStringType()) + "\" ");
            }
            xmlDump.append("/>" + EOL);
        }
        if (variablesAdded > 0) {
            xmlDump.append(EOL);
        }
    }
}
Also used : Variable(org.jbpm.process.core.context.variable.Variable) Constraint(org.jbpm.workflow.core.Constraint)

Aggregations

Variable (org.jbpm.process.core.context.variable.Variable)38 ArrayList (java.util.ArrayList)18 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)17 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)16 EndNode (org.jbpm.workflow.core.node.EndNode)14 StartNode (org.jbpm.workflow.core.node.StartNode)14 ActionNode (org.jbpm.workflow.core.node.ActionNode)12 VariableScope (org.jbpm.process.core.context.variable.VariableScope)11 DroolsAction (org.jbpm.workflow.core.DroolsAction)10 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)10 Test (org.junit.Test)10 Action (org.jbpm.process.instance.impl.Action)9 TestProcessEventListener (org.jbpm.process.test.TestProcessEventListener)9 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)9 KieSession (org.kie.api.runtime.KieSession)9 ProcessContext (org.kie.api.runtime.process.ProcessContext)9 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)8 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)8 EventNode (org.jbpm.workflow.core.node.EventNode)7