Search in sources :

Example 1 with ContextContainer

use of org.jbpm.process.core.ContextContainer in project jbpm by kiegroup.

the class ProcessHandler method linkBoundaryErrorEvent.

private static void linkBoundaryErrorEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    ContextContainer compositeNode = (ContextContainer) attachedNode;
    ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope == null) {
        exceptionScope = new ExceptionScope();
        compositeNode.addContext(exceptionScope);
        compositeNode.setDefaultContext(exceptionScope);
    }
    String errorCode = (String) node.getMetaData().get("ErrorEvent");
    boolean hasErrorCode = (Boolean) node.getMetaData().get("HasErrorEvent");
    String errorStructureRef = (String) node.getMetaData().get("ErrorStructureRef");
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    String variable = ((EventNode) node).getVariableName();
    DroolsConsequenceAction action = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Error-" + attachedTo + "-" + errorCode + "\", kcontext.getVariable(\"" + variable + "\"));");
    exceptionHandler.setAction(action);
    exceptionHandler.setFaultVariable(variable);
    exceptionScope.setExceptionHandler(hasErrorCode ? errorCode : null, exceptionHandler);
    if (errorStructureRef != null) {
        exceptionScope.setExceptionHandler(errorStructureRef, exceptionHandler);
    }
    List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
    if (actions == null) {
        actions = new ArrayList<DroolsAction>();
    }
    DroolsConsequenceAction cancelAction = new DroolsConsequenceAction("java", null);
    cancelAction.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
    actions.add(cancelAction);
    ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) ContextContainer(org.jbpm.process.core.ContextContainer) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) CancelNodeInstanceAction(org.jbpm.process.instance.impl.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ExceptionScope(org.jbpm.process.core.context.exception.ExceptionScope) ActionExceptionHandler(org.jbpm.process.core.context.exception.ActionExceptionHandler)

Example 2 with ContextContainer

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

use of org.jbpm.process.core.ContextContainer 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)

Example 4 with ContextContainer

use of org.jbpm.process.core.ContextContainer in project jbpm by kiegroup.

the class ProcessInstanceImpl method getContextInstance.

public ContextInstance getContextInstance(String contextId) {
    ContextInstance contextInstance = this.contextInstances.get(contextId);
    if (contextInstance != null) {
        return contextInstance;
    }
    Context context = ((ContextContainer) getProcess()).getDefaultContext(contextId);
    if (context != null) {
        contextInstance = getContextInstance(context);
        return contextInstance;
    }
    return null;
}
Also used : Context(org.jbpm.process.core.Context) ContextContainer(org.jbpm.process.core.ContextContainer) ContextInstance(org.jbpm.process.instance.ContextInstance)

Example 5 with ContextContainer

use of org.jbpm.process.core.ContextContainer in project jbpm by kiegroup.

the class CompensationTest method addCompensationScope.

/*
     * General HELPER methods
     */
private void addCompensationScope(final Node node, final org.kie.api.definition.process.NodeContainer parentContainer, final String compensationHandlerId) {
    ContextContainer contextContainer = (ContextContainer) parentContainer;
    CompensationScope scope = null;
    boolean addScope = false;
    if (contextContainer.getContexts(CompensationScope.COMPENSATION_SCOPE) == null) {
        addScope = true;
    } else {
        scope = (CompensationScope) contextContainer.getContexts(CompensationScope.COMPENSATION_SCOPE).get(0);
        if (scope == null) {
            addScope = true;
        }
    }
    if (addScope) {
        scope = new CompensationScope();
        contextContainer.addContext(scope);
        contextContainer.setDefaultContext(scope);
        scope.setContextContainer(contextContainer);
    }
    CompensationHandler handler = new CompensationHandler();
    handler.setNode(node);
    scope.setExceptionHandler(compensationHandlerId, handler);
    node.setMetaData("isForCompensation", Boolean.TRUE);
}
Also used : ContextContainer(org.jbpm.process.core.ContextContainer) CompensationHandler(org.jbpm.process.core.context.exception.CompensationHandler) CompensationScope(org.jbpm.process.core.context.exception.CompensationScope)

Aggregations

ContextContainer (org.jbpm.process.core.ContextContainer)11 ActionExceptionHandler (org.jbpm.process.core.context.exception.ActionExceptionHandler)4 ExceptionScope (org.jbpm.process.core.context.exception.ExceptionScope)4 List (java.util.List)3 CompensationScope (org.jbpm.process.core.context.exception.CompensationScope)3 Variable (org.jbpm.process.core.context.variable.Variable)3 VariableScope (org.jbpm.process.core.context.variable.VariableScope)3 DroolsAction (org.jbpm.workflow.core.DroolsAction)3 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)3 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 CompensationHandler (org.jbpm.process.core.context.exception.CompensationHandler)2 CancelNodeInstanceAction (org.jbpm.process.instance.impl.CancelNodeInstanceAction)2 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)2 Node (org.kie.api.definition.process.Node)2 SAXParseException (org.xml.sax.SAXParseException)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)1 ProcessBuildData (org.jbpm.compiler.xml.ProcessBuildData)1