Search in sources :

Example 11 with RuleSetNode

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

the class RuleSetNodeHandler 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);
    RuleSetNode ruleSetNode = (RuleSetNode) node;
    String ruleFlowGroup = element.getAttribute("ruleFlowGroup");
    if (ruleFlowGroup != null && ruleFlowGroup.length() > 0) {
        ruleSetNode.setRuleFlowGroup(ruleFlowGroup);
    }
}
Also used : RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode)

Example 12 with RuleSetNode

use of org.jbpm.workflow.core.node.RuleSetNode 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)

Example 13 with RuleSetNode

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

the class ServicesProcessDataEventListener method onNodeAdded.

@SuppressWarnings("unchecked")
@Override
public void onNodeAdded(Node node) {
    logger.debug("Added node " + node);
    if (node instanceof HumanTaskNode) {
        HumanTaskNode humanTaskNode = (HumanTaskNode) node;
        String name = humanTaskNode.getName();
        UserTaskDefinitionImpl task = (UserTaskDefinitionImpl) processDescriptor.getTasks().get(name);
        if (task == null) {
            task = new UserTaskDefinitionImpl();
            task.setId(humanTaskNode.getUniqueId());
            task.setName(name);
            processDescriptor.getTasks().put(task.getName(), task);
        }
        Map<String, Object> parameters = humanTaskNode.getWork().getParameters();
        Collection<String> currentAssignment = processDescriptor.getTaskAssignments().get(humanTaskNode.getName());
        for (String parameter : parameters.keySet()) {
            if (parameter.equals("GroupId") || parameter.equals("ActorId")) {
                if (currentAssignment == null) {
                    currentAssignment = new ArrayList<String>();
                    processDescriptor.getTaskAssignments().put(humanTaskNode.getName(), currentAssignment);
                }
                currentAssignment.add(humanTaskNode.getWork().getParameter(parameter).toString());
            }
        }
        ((UserTaskDefinitionImpl) processDescriptor.getTasks().get(humanTaskNode.getName())).setAssociatedEntities(currentAssignment);
        Map<String, String> inputParams = new HashMap<String, String>();
        for (Map.Entry<String, String> in : ((Map<String, String>) humanTaskNode.getMetaData("DataInputs")).entrySet()) {
            inputParams.put(in.getKey(), in.getValue());
        }
        Map<String, String> outputParams = new HashMap<String, String>();
        for (Map.Entry<String, String> out : ((Map<String, String>) humanTaskNode.getMetaData("DataOutputs")).entrySet()) {
            outputParams.put(out.getKey(), out.getValue());
        }
        task.setTaskInputMappings(inputParams);
        task.setTaskOutputMappings(outputParams);
        task.setComment(asString(humanTaskNode.getWork().getParameter("Comment")));
        task.setCreatedBy(asString(humanTaskNode.getWork().getParameter("CreatedBy")));
        task.setPriority(asInt(humanTaskNode.getWork().getParameter("Priority")));
        task.setSkippable(asBoolean(humanTaskNode.getWork().getParameter("Skippable")));
        task.setFormName(asString(humanTaskNode.getWork().getParameter("TaskName")));
        processDescriptor.getTaskInputMappings().put(task.getName(), inputParams);
        processDescriptor.getTaskOutputMappings().put(task.getName(), outputParams);
    } else if (node instanceof RuleSetNode) {
        RuleSetNode ruleSetNode = (RuleSetNode) node;
        String ruleFlowGroup = ruleSetNode.getRuleFlowGroup();
        if (ruleFlowGroup != null) {
            processDescriptor.getReferencedRules().add(ruleFlowGroup);
        }
    } else if (node instanceof WorkItemNode) {
        processDescriptor.getServiceTasks().put(node.getName(), ((WorkItemNode) node).getWork().getName());
    } else if (node instanceof SubProcessNode) {
        SubProcessNode subProcess = (SubProcessNode) node;
        String processId = subProcess.getProcessId();
        if (subProcess.getProcessName() != null) {
            processDescriptor.addReusableSubProcessName(subProcess.getProcessName());
        } else {
            processDescriptor.getReusableSubProcesses().add(processId);
        }
    }
}
Also used : HashMap(java.util.HashMap) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) UserTaskDefinitionImpl(org.jbpm.kie.services.impl.bpmn2.UserTaskDefinitionImpl) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) HashMap(java.util.HashMap) Map(java.util.Map) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Aggregations

RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)13 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)6 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)6 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)4 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)4 List (java.util.List)3 Map (java.util.Map)3 Variable (org.jbpm.process.core.context.variable.Variable)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 DynamicNode (org.jbpm.workflow.core.node.DynamicNode)3 EndNode (org.jbpm.workflow.core.node.EndNode)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 FaultNode (org.jbpm.workflow.core.node.FaultNode)3 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)3 Join (org.jbpm.workflow.core.node.Join)3 MilestoneNode (org.jbpm.workflow.core.node.MilestoneNode)3 Split (org.jbpm.workflow.core.node.Split)3 StartNode (org.jbpm.workflow.core.node.StartNode)3