Search in sources :

Example 11 with SubProcessNode

use of org.jbpm.workflow.core.node.SubProcessNode in project jbpm by kiegroup.

the class SubProcessNodeBuilder method build.

@Override
public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) {
    super.build(process, processDescr, context, node);
    WorkflowProcess wfProcess = (WorkflowProcess) process;
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("imports", wfProcess.getImports());
    parameters.put("classloader", context.getConfiguration().getClassLoader());
    for (DataAssociation dataAssociation : ((SubProcessNode) node).getInAssociations()) {
        Transformation transformation = dataAssociation.getTransformation();
        if (transformation != null) {
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters));
        }
    }
    for (DataAssociation dataAssociation : ((SubProcessNode) node).getOutAssociations()) {
        Transformation transformation = dataAssociation.getTransformation();
        if (transformation != null) {
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters));
        }
    }
}
Also used : Transformation(org.jbpm.workflow.core.node.Transformation) DataTransformer(org.kie.api.runtime.process.DataTransformer) HashMap(java.util.HashMap) DataAssociation(org.jbpm.workflow.core.node.DataAssociation) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess)

Example 12 with SubProcessNode

use of org.jbpm.workflow.core.node.SubProcessNode in project jbpm by kiegroup.

the class SubProcessNodeHandler method handleNode.

public void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    SubProcessNode subProcessNode = (SubProcessNode) node;
    String processId = element.getAttribute("processId");
    if (processId != null && processId.length() > 0) {
        subProcessNode.setProcessId(processId);
    }
    String waitForCompletion = element.getAttribute("waitForCompletion");
    subProcessNode.setWaitForCompletion(!"false".equals(waitForCompletion));
    String independent = element.getAttribute("independent");
    subProcessNode.setIndependent(!"false".equals(independent));
    for (String eventType : subProcessNode.getActionTypes()) {
        handleAction(subProcessNode, element, eventType);
    }
}
Also used : SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode)

Example 13 with SubProcessNode

use of org.jbpm.workflow.core.node.SubProcessNode in project jbpm by kiegroup.

the class SubProcessNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    SubProcessNode subProcessNode = (SubProcessNode) node;
    writeNode("subProcess", subProcessNode, xmlDump, includeMeta);
    String processId = subProcessNode.getProcessId();
    if (processId != null) {
        xmlDump.append("processId=\"" + processId + "\" ");
    }
    if (!subProcessNode.isWaitForCompletion()) {
        xmlDump.append("waitForCompletion=\"false\" ");
    }
    if (!subProcessNode.isIndependent()) {
        xmlDump.append("independent=\"false\" ");
    }
    xmlDump.append(">" + EOL);
    if (includeMeta) {
        writeMetaData(subProcessNode, xmlDump);
    }
    Map<String, String> inMappings = subProcessNode.getInMappings();
    for (Map.Entry<String, String> inMapping : inMappings.entrySet()) {
        xmlDump.append("      <mapping type=\"in\" " + "from=\"" + inMapping.getValue() + "\" " + "to=\"" + inMapping.getKey() + "\" />" + EOL);
    }
    Map<String, String> outMappings = subProcessNode.getOutMappings();
    for (Map.Entry<String, String> outMapping : outMappings.entrySet()) {
        xmlDump.append("      <mapping type=\"out\" " + "from=\"" + outMapping.getKey() + "\" " + "to=\"" + outMapping.getValue() + "\" />" + EOL);
    }
    for (String eventType : subProcessNode.getActionTypes()) {
        writeActions(eventType, subProcessNode.getActions(eventType), xmlDump);
    }
    writeTimers(subProcessNode.getTimers(), xmlDump);
    endNode("subProcess", xmlDump);
}
Also used : SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) Map(java.util.Map)

Example 14 with SubProcessNode

use of org.jbpm.workflow.core.node.SubProcessNode in project jbpm by kiegroup.

the class SubProcessTest method testAsynchronousSubProcess.

@Test
public void testAsynchronousSubProcess() {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process.process");
    process.setName("Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    process.addNode(startNode);
    EndNode endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(2);
    process.addNode(endNode);
    SubProcessNode subProcessNode = new SubProcessNode();
    subProcessNode.setName("SubProcessNode");
    subProcessNode.setId(3);
    subProcessNode.setProcessId("org.drools.core.process.subprocess");
    process.addNode(subProcessNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, subProcessNode, Node.CONNECTION_DEFAULT_TYPE);
    new ConnectionImpl(subProcessNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    RuleFlowProcess subProcess = new RuleFlowProcess();
    subProcess.setId("org.drools.core.process.subprocess");
    subProcess.setName("SubProcess");
    startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    subProcess.addNode(startNode);
    endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(2);
    subProcess.addNode(endNode);
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setName("WorkItem");
    Work work = new WorkImpl();
    work.setName("MyWork");
    workItemNode.setWork(work);
    workItemNode.setId(4);
    subProcess.addNode(workItemNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, workItemNode, Node.CONNECTION_DEFAULT_TYPE);
    new ConnectionImpl(workItemNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    KieSession ksession = createKieSession(process, subProcess);
    ksession.getWorkItemManager().registerWorkItemHandler("MyWork", new WorkItemHandler() {

        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            logger.info("Executing work item");
            SubProcessTest.this.workItem = workItem;
        }

        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
        }
    });
    ksession.startProcess("org.drools.core.process.process");
    TestProcessEventListener procEventListener = new TestProcessEventListener();
    ksession.addEventListener(procEventListener);
    assertNotNull(workItem);
    assertEquals(2, ksession.getProcessInstances().size());
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertEquals(0, ksession.getProcessInstances().size());
    verifyEventHistory(asyncEventOrder, procEventListener.getEventHistory());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) EndNode(org.jbpm.workflow.core.node.EndNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl) KieSession(org.kie.api.runtime.KieSession) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestProcessEventListener(org.jbpm.process.test.TestProcessEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 15 with SubProcessNode

use of org.jbpm.workflow.core.node.SubProcessNode in project jbpm by kiegroup.

the class ProcessHandler method checkBoundaryEventCompensationHandler.

/**
 * This logic belongs in {@link RuleFlowProcessValidator} -- except that {@link Association}s are a jbpm-bpmn2 class,
 * and {@link RuleFlowProcessValidator} is a jbpm-flow class..
 * </p>
 * Maybe we should have a BPMNProcessValidator class?
 *
 * @param association The association to check.
 * @param source The source of the association.
 * @param target The target of the association.
 */
private static void checkBoundaryEventCompensationHandler(Association association, Node source, Node target) {
    // - event node is boundary event node
    if (!(source instanceof BoundaryEventNode)) {
        throw new IllegalArgumentException("(Compensation) activities may only be associated with Boundary Event Nodes (not with" + source.getClass().getSimpleName() + " nodes [node " + ((String) source.getMetaData().get("UniqueId")) + "].");
    }
    BoundaryEventNode eventNode = (BoundaryEventNode) source;
    // - event node has compensationEvent
    List<EventFilter> eventFilters = eventNode.getEventFilters();
    boolean compensationCheckPassed = false;
    if (eventFilters != null) {
        for (EventFilter filter : eventFilters) {
            if (filter instanceof EventTypeFilter) {
                String type = ((EventTypeFilter) filter).getType();
                if (type != null && type.equals("Compensation")) {
                    compensationCheckPassed = true;
                }
            }
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("An Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] linked from an association [" + association.getId() + "] must be a (Boundary) Compensation Event.");
    }
    // - boundary event node is attached to the correct type of node?
    /**
     * Tasks:
     * business: RuleSetNode
     * manual: WorkItemNode
     * receive: WorkItemNode
     * script: ActionNode
     * send: WorkItemNode
     * service: WorkItemNode
     * task: WorkItemNode
     * user: HumanTaskNode
     */
    String attachedToId = eventNode.getAttachedToNodeId();
    Node attachedToNode = null;
    for (Node node : eventNode.getNodeContainer().getNodes()) {
        if (attachedToId.equals(node.getMetaData().get("UniqueId"))) {
            attachedToNode = node;
            break;
        }
    }
    if (attachedToNode == null) {
        throw new IllegalArgumentException("Boundary Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] is not attached to a node [" + attachedToId + "] that can be found.");
    }
    if (!(attachedToNode instanceof RuleSetNode || attachedToNode instanceof WorkItemNode || attachedToNode instanceof ActionNode || attachedToNode instanceof HumanTaskNode || attachedToNode instanceof CompositeNode || attachedToNode instanceof SubProcessNode)) {
        throw new IllegalArgumentException("Compensation Boundary Event [" + ((String) eventNode.getMetaData("UniqueId")) + "] must be attached to a task or sub-process.");
    }
    // - associated node is a task or subProcess
    compensationCheckPassed = false;
    if (target instanceof WorkItemNode || target instanceof HumanTaskNode || target instanceof CompositeContextNode || target instanceof SubProcessNode) {
        compensationCheckPassed = true;
    } else if (target instanceof ActionNode) {
        Object nodeTypeObj = ((ActionNode) target).getMetaData("NodeType");
        if (nodeTypeObj != null && nodeTypeObj.equals("ScriptTask")) {
            compensationCheckPassed = true;
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("An Activity [" + ((String) ((NodeImpl) target).getMetaData("UniqueId")) + "] associated with a Boundary Compensation Event must be a Task or a (non-Event) Sub-Process");
    }
    // - associated node does not have outgoingConnections of it's own
    compensationCheckPassed = true;
    NodeImpl targetNode = (NodeImpl) target;
    Map<String, List<org.kie.api.definition.process.Connection>> connectionsMap = targetNode.getOutgoingConnections();
    ConnectionImpl outgoingConnection = null;
    for (String connectionType : connectionsMap.keySet()) {
        List<org.kie.api.definition.process.Connection> connections = connectionsMap.get(connectionType);
        if (connections != null && !connections.isEmpty()) {
            for (org.kie.api.definition.process.Connection connection : connections) {
                Object hiddenObj = connection.getMetaData().get("hidden");
                if (hiddenObj != null && ((Boolean) hiddenObj)) {
                    continue;
                }
                outgoingConnection = (ConnectionImpl) connection;
                compensationCheckPassed = false;
                break;
            }
        }
    }
    if (!compensationCheckPassed) {
        throw new IllegalArgumentException("A Compensation Activity [" + ((String) targetNode.getMetaData("UniqueId")) + "] may not have any outgoing connection [" + (String) outgoingConnection.getMetaData("UniqueId") + "]");
    }
}
Also used : RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) StateNode(org.jbpm.workflow.core.node.StateNode) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ActionNode(org.jbpm.workflow.core.node.ActionNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) List(java.util.List) ArrayList(java.util.ArrayList) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) Connection(org.jbpm.workflow.core.Connection) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventFilter(org.jbpm.process.core.event.EventFilter) CompositeNode(org.jbpm.workflow.core.node.CompositeNode)

Aggregations

SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)17 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)9 EndNode (org.jbpm.workflow.core.node.EndNode)8 StartNode (org.jbpm.workflow.core.node.StartNode)8 HashMap (java.util.HashMap)6 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)6 ActionNode (org.jbpm.workflow.core.node.ActionNode)6 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)6 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)5 Test (org.junit.Test)5 Map (java.util.Map)4 Work (org.jbpm.process.core.Work)4 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 FaultNode (org.jbpm.workflow.core.node.FaultNode)4 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)4 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)4 StateNode (org.jbpm.workflow.core.node.StateNode)4 ArrayList (java.util.ArrayList)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3