Search in sources :

Example 6 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction 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 7 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm by kiegroup.

the class EndEventHandler method handleMessageNode.

@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    EndNode endNode = (EndNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInputAssociation".equals(nodeName)) {
            readEndDataInputAssociation(xmlNode, endNode);
        } else if ("messageEventDefinition".equals(nodeName)) {
            String messageRef = ((Element) xmlNode).getAttribute("messageRef");
            Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
            if (messages == null) {
                throw new IllegalArgumentException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new IllegalArgumentException("Could not find message " + messageRef);
            }
            String variable = (String) endNode.getMetaData("MappingVariable");
            endNode.setMetaData("MessageType", message.getType());
            List<DroolsAction> actions = new ArrayList<DroolsAction>();
            actions.add(new DroolsConsequenceAction("java", "org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();" + EOL + "workItem.setName(\"Send Task\");" + EOL + "workItem.setNodeInstanceId(kcontext.getNodeInstance().getId());" + EOL + "workItem.setProcessInstanceId(kcontext.getProcessInstance().getId());" + EOL + "workItem.setNodeId(kcontext.getNodeInstance().getNodeId());" + EOL + "workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL + (variable == null ? "" : "workItem.setParameter(\"Message\", " + variable + ");" + EOL) + "workItem.setDeploymentId((String) kcontext.getKnowledgeRuntime().getEnvironment().get(\"deploymentId\"));" + EOL + "((org.drools.core.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
            endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) Message(org.jbpm.bpmn2.core.Message) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) EndNode(org.jbpm.workflow.core.node.EndNode) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 8 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm by kiegroup.

the class AbstractNodeHandler method handleScript.

protected void handleScript(final ExtendedNodeImpl node, final Element element, String type) {
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        if (nodeList.item(i) instanceof Element) {
            Element xmlNode = (Element) nodeList.item(i);
            String nodeName = xmlNode.getNodeName();
            if (nodeName.equals("extensionElements")) {
                NodeList subNodeList = xmlNode.getChildNodes();
                for (int j = 0; j < subNodeList.getLength(); j++) {
                    org.w3c.dom.Node subXmlNode = subNodeList.item(j);
                    if (subXmlNode.getNodeName().contains(type + "-script")) {
                        List<DroolsAction> actions = node.getActions(type);
                        if (actions == null) {
                            actions = new ArrayList<DroolsAction>();
                            node.setActions(type, actions);
                        }
                        DroolsAction action = extractScript((Element) subXmlNode);
                        actions.add(action);
                    }
                }
            }
        }
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 9 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm by kiegroup.

the class SubProcessNodeFactory method onEntryAction.

public SubProcessNodeFactory onEntryAction(String dialect, String action) {
    if (getSubProcessNode().getActions(dialect) != null) {
        getSubProcessNode().getActions(dialect).add(new DroolsConsequenceAction(dialect, action));
    } else {
        List<DroolsAction> actions = new ArrayList<DroolsAction>();
        actions.add(new DroolsConsequenceAction(dialect, action));
        getSubProcessNode().setActions(MilestoneNode.EVENT_NODE_ENTER, actions);
    }
    return this;
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ArrayList(java.util.ArrayList)

Example 10 with DroolsAction

use of org.jbpm.workflow.core.DroolsAction in project jbpm by kiegroup.

the class WorkItemNodeFactory method onEntryAction.

public WorkItemNodeFactory onEntryAction(String dialect, String action) {
    if (getWorkItemNode().getActions(dialect) != null) {
        getWorkItemNode().getActions(dialect).add(new DroolsConsequenceAction(dialect, action));
    } else {
        List<DroolsAction> actions = new ArrayList<DroolsAction>();
        actions.add(new DroolsConsequenceAction(dialect, action));
        getWorkItemNode().setActions(MilestoneNode.EVENT_NODE_ENTER, actions);
    }
    return this;
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ArrayList(java.util.ArrayList)

Aggregations

DroolsAction (org.jbpm.workflow.core.DroolsAction)53 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)40 ArrayList (java.util.ArrayList)30 ActionNode (org.jbpm.workflow.core.node.ActionNode)25 Action (org.jbpm.process.instance.impl.Action)22 EndNode (org.jbpm.workflow.core.node.EndNode)22 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)19 Test (org.junit.Test)18 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 StartNode (org.jbpm.workflow.core.node.StartNode)17 KieSession (org.kie.api.runtime.KieSession)17 ProcessContext (org.kie.api.runtime.process.ProcessContext)17 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)15 EventNode (org.jbpm.workflow.core.node.EventNode)14 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)13 Variable (org.jbpm.process.core.context.variable.Variable)10 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)10 TestProcessEventListener (org.jbpm.process.test.TestProcessEventListener)9 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)8 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)8