Search in sources :

Example 6 with HumanTaskNode

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

the class ChecklistItemFactory method getPendingChecklistItems.

private static void getPendingChecklistItems(NodeContainer container, List<ChecklistItem> result, String processId) {
    for (Node node : container.getNodes()) {
        if (node instanceof HumanTaskNode) {
            Work workItem = ((HumanTaskNode) node).getWork();
            int priority = 0;
            String priorityString = (String) workItem.getParameter("Priority");
            if (priorityString != null) {
                try {
                    priority = new Integer(priorityString);
                } catch (NumberFormatException e) {
                // Do nothing
                }
            }
            String actorId = (String) workItem.getParameter("ActorId");
            if (actorId != null && actorId.trim().length() == 0) {
                actorId = null;
            }
            String groupId = (String) workItem.getParameter("GroupId");
            if (groupId != null && groupId.trim().length() == 0) {
                groupId = null;
            }
            String actors = null;
            if (actorId == null) {
                if (groupId == null) {
                    actors = "";
                } else {
                    actors = groupId;
                }
            } else {
                if (groupId == null) {
                    actors = actorId;
                } else {
                    actors = actorId + "," + groupId;
                }
            }
            Status status = Status.Pending;
            if (((HumanTaskNode) node).getDefaultIncomingConnections().size() == 0) {
                status = Status.Optional;
            }
            result.add(createChecklistItem((String) workItem.getParameter("TaskName"), "HumanTaskNode", actors, (String) workItem.getParameter("Comment"), priority, processId, status));
        } else if (node instanceof NodeContainer) {
            getPendingChecklistItems((NodeContainer) node, result, processId);
        } else {
            String docs = (String) node.getMetaData().get("Documentation");
            if (docs != null) {
                int position = docs.indexOf("OrderingNb=");
                if (position >= 0) {
                    int end = docs.indexOf(";", position + 1);
                    String orderingNumber = docs.substring(position + 11, end);
                    Status status = Status.Pending;
                    if (((NodeImpl) node).getDefaultIncomingConnections().size() == 0 && !(node instanceof StartNode)) {
                        status = Status.Optional;
                    }
                    result.add(createChecklistItem(node.getName(), node.getClass().getSimpleName(), "", orderingNumber, 0, processId, status));
                }
            }
        }
    }
}
Also used : Status(org.jbpm.examples.checklist.ChecklistItem.Status) StartNode(org.jbpm.workflow.core.node.StartNode) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) StartNode(org.jbpm.workflow.core.node.StartNode) Node(org.kie.api.definition.process.Node) Work(org.jbpm.process.core.Work) NodeContainer(org.kie.api.definition.process.NodeContainer) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Example 7 with HumanTaskNode

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

the class HumanTaskNodeHandler 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);
    HumanTaskNode humanTaskNode = (HumanTaskNode) node;
    final String swimlane = element.getAttribute("swimlane");
    if (swimlane != null && !"".equals(swimlane)) {
        humanTaskNode.setSwimlane(swimlane);
    }
}
Also used : HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Example 8 with HumanTaskNode

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

the class UserTaskHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    HumanTaskNode humanTaskNode = (HumanTaskNode) node;
    writeNode("userTask", humanTaskNode, xmlDump, metaDataType);
    xmlDump.append(">" + EOL);
    writeExtensionElements(humanTaskNode, xmlDump);
    writeIO(humanTaskNode, xmlDump);
    String ownerString = (String) humanTaskNode.getWork().getParameter("ActorId");
    if (ownerString != null) {
        String[] owners = ownerString.split(",");
        for (String owner : owners) {
            xmlDump.append("      <potentialOwner>" + EOL + "        <resourceAssignmentExpression>" + EOL + "          <formalExpression>" + owner + "</formalExpression>" + EOL + "        </resourceAssignmentExpression>" + EOL + "      </potentialOwner>" + EOL);
        }
    }
    endNode("userTask", xmlDump);
}
Also used : HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Example 9 with HumanTaskNode

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

the class UserTaskHandler method handleNode.

protected 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);
    HumanTaskNode humanTaskNode = (HumanTaskNode) node;
    Work work = humanTaskNode.getWork();
    work.setName("Human Task");
    Map<String, String> dataInputs = new HashMap<String, String>();
    Map<String, String> dataOutputs = new HashMap<String, String>();
    List<String> owners = new ArrayList<String>();
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        // ioSpec and data{Input,Output}Spec handled in super.handleNode(...)
        if ("potentialOwner".equals(nodeName)) {
            String owner = readPotentialOwner(xmlNode, humanTaskNode);
            if (owner != null) {
                owners.add(owner);
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
    if (owners.size() > 0) {
        String owner = owners.get(0);
        for (int i = 1; i < owners.size(); i++) {
            owner += "," + owners.get(i);
        }
        humanTaskNode.getWork().setParameter("ActorId", owner);
    }
    humanTaskNode.getWork().setParameter("NodeName", humanTaskNode.getName());
}
Also used : HashMap(java.util.HashMap) Work(org.jbpm.process.core.Work) ArrayList(java.util.ArrayList) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Example 10 with HumanTaskNode

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

HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)13 StartNode (org.jbpm.workflow.core.node.StartNode)6 EndNode (org.jbpm.workflow.core.node.EndNode)5 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)5 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)5 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)5 ArrayList (java.util.ArrayList)4 Work (org.jbpm.process.core.Work)4 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 ActionNode (org.jbpm.workflow.core.node.ActionNode)4 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 FaultNode (org.jbpm.workflow.core.node.FaultNode)4 StateNode (org.jbpm.workflow.core.node.StateNode)4 HashMap (java.util.HashMap)3 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)3 Node (org.kie.api.definition.process.Node)3 StringReader (java.io.StringReader)2 HashSet (java.util.HashSet)2 SemanticModules (org.drools.core.xml.SemanticModules)2