Search in sources :

Example 1 with VariableScope

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

the class CompositeNodeHandler method createNode.

protected Node createNode() {
    CompositeContextNode result = new CompositeContextNode();
    VariableScope variableScope = new VariableScope();
    result.addContext(variableScope);
    result.setDefaultContext(variableScope);
    return result;
}
Also used : CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 2 with VariableScope

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

the class ActivityTest method testMinimalProcessMetaData.

@Test
public void testMinimalProcessMetaData() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MinimalProcessMetaData.bpmn2");
    ksession = createKnowledgeSession(kbase);
    final List<String> list1 = new ArrayList<String>();
    final List<String> list2 = new ArrayList<String>();
    final List<String> list3 = new ArrayList<String>();
    final List<String> list4 = new ArrayList<String>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            logger.debug("before node");
            Map<String, Object> metaData = event.getNodeInstance().getNode().getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTag");
            if (customTag != null) {
                list1.add(customTag);
            }
            String customTag2 = (String) metaData.get("customTag2");
            if (customTag2 != null) {
                list2.add(customTag2);
            }
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            logger.debug("after variable");
            VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.impl.ProcessImpl) event.getProcessInstance().getProcess()).resolveContext(VariableScope.VARIABLE_SCOPE, event.getVariableId());
            if (variableScope == null) {
                return;
            }
            Map<String, Object> metaData = variableScope.findVariable(event.getVariableId()).getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTagVar");
            if (customTag != null) {
                list3.add(customTag);
            }
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
            logger.debug("after process");
            Map<String, Object> metaData = event.getProcessInstance().getProcess().getMetaData();
            for (Map.Entry<String, Object> entry : metaData.entrySet()) {
                logger.debug(entry.getKey() + " " + entry.getValue());
            }
            String customTag = (String) metaData.get("customTagProcess");
            if (customTag != null) {
                list4.add(customTag);
            }
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "krisv");
    ProcessInstance processInstance = ksession.startProcess("Minimal", params);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(3, list1.size());
    assertEquals(2, list2.size());
    assertEquals(1, list3.size());
    assertEquals(1, list4.size());
}
Also used : ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Test(org.junit.Test)

Example 3 with VariableScope

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

the class SubProcessHandler method createNode.

protected Node createNode(Attributes attrs) {
    CompositeContextNode subProcessNode = new CompositeContextNode();
    String eventSubprocessAttribute = attrs.getValue("triggeredByEvent");
    if (eventSubprocessAttribute != null && Boolean.parseBoolean(eventSubprocessAttribute)) {
        subProcessNode = new EventSubProcessNode();
    }
    VariableScope variableScope = new VariableScope();
    subProcessNode.addContext(variableScope);
    subProcessNode.setDefaultContext(variableScope);
    String compensation = attrs.getValue("isForCompensation");
    if (compensation != null) {
        boolean isForCompensation = Boolean.parseBoolean(compensation);
        if (isForCompensation) {
            subProcessNode.setMetaData("isForCompensation", isForCompensation);
        }
    }
    subProcessNode.setAutoComplete(true);
    return subProcessNode;
}
Also used : CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 4 with VariableScope

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

the class PropertyHandler method start.

@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String id = attrs.getValue("id");
    final String name = attrs.getValue("name");
    final String itemSubjectRef = attrs.getValue("itemSubjectRef");
    Object parent = parser.getParent();
    if (parent instanceof ContextContainer) {
        ContextContainer contextContainer = (ContextContainer) parent;
        VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
        List variables = variableScope.getVariables();
        Variable variable = new Variable();
        // if name is given use it as variable name instead of id
        if (name != null && name.length() > 0) {
            variable.setName(name);
        } else {
            variable.setName(id);
        }
        variable.setMetaData("ItemSubjectRef", itemSubjectRef);
        variables.add(variable);
        ((ProcessBuildData) parser.getData()).setMetaData("Variable", variable);
        return variable;
    }
    return new Variable();
}
Also used : ContextContainer(org.jbpm.process.core.ContextContainer) Variable(org.jbpm.process.core.context.variable.Variable) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) List(java.util.List) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Example 5 with VariableScope

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

the class DataObjectHandler method start.

@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String id = attrs.getValue("id");
    final String itemSubjectRef = attrs.getValue("itemSubjectRef");
    Object parent = parser.getParent();
    if (parent instanceof ContextContainer) {
        ContextContainer contextContainer = (ContextContainer) parent;
        VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
        List variables = variableScope.getVariables();
        Variable variable = new Variable();
        variable.setMetaData("DataObject", "true");
        variable.setName(id);
        // retrieve type from item definition
        DataType dataType = new ObjectDataType();
        Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
        if (itemDefinitions != null) {
            ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
            if (itemDefinition != null) {
                String structureRef = itemDefinition.getStructureRef();
                if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
                    dataType = new BooleanDataType();
                } else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
                    dataType = new IntegerDataType();
                } else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
                    dataType = new FloatDataType();
                } else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
                    dataType = new StringDataType();
                } else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
                    // use FQCN of Object
                    dataType = new ObjectDataType("java.lang.Object");
                } else {
                    dataType = new ObjectDataType(structureRef, parser.getClassLoader());
                }
            }
        }
        variable.setType(dataType);
        variables.add(variable);
        return variable;
    }
    return new Variable();
}
Also used : FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) Variable(org.jbpm.process.core.context.variable.Variable) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) ContextContainer(org.jbpm.process.core.ContextContainer) DataType(org.jbpm.process.core.datatype.DataType) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) FloatDataType(org.jbpm.process.core.datatype.impl.type.FloatDataType) List(java.util.List) BooleanDataType(org.jbpm.process.core.datatype.impl.type.BooleanDataType) Map(java.util.Map) VariableScope(org.jbpm.process.core.context.variable.VariableScope)

Aggregations

VariableScope (org.jbpm.process.core.context.variable.VariableScope)24 Variable (org.jbpm.process.core.context.variable.Variable)11 Map (java.util.Map)7 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)6 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ContextContainer (org.jbpm.process.core.ContextContainer)3 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)3 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)3 Node (org.jbpm.workflow.core.Node)3 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)3 HashSet (java.util.HashSet)2 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)2 MVELCompilationUnit (org.drools.core.base.mvel.MVELCompilationUnit)2 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)2 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)2 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)2 IntegerDataType (org.jbpm.process.core.datatype.impl.type.IntegerDataType)2 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)2