public final void trigger(NodeInstance from, String type) { boolean hidden = false; if (getNode().getMetaData().get("hidden") != null) { hidden = true; int level = ((org.jbpm.workflow.instance.NodeInstance)from).getLevel(); ((org.jbpm.workflow.instance.NodeInstanceContainer)getNodeInstanceContainer()).setCurrentLevel(level); Collection<Connection> incoming = getNode().getIncomingConnections(type); for (Connection conn : incoming) { if (conn.getFrom().getId() == from.getNodeId()) { this.metaData.put("IncomingConnection", conn.getMetaData().get("UniqueId")); break; setVariable(entry.getKey(), entry.getValue()); configureSla(); InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); if (!hidden) { ((InternalProcessRuntime) kruntime.getProcessRuntime()) getExecutionErrorHandler().processing(this); internalTrigger(from, type); throw new WorkflowRuntimeException(this, getProcessInstance(), e);
@Override public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { NodeInstance nodeInstance = event.getNodeInstance(); String uniqId = ((NodeInstanceImpl) nodeInstance).getUniqueId(); String nodeName = ((NodeInstanceImpl) nodeInstance).getNode().getName(); String prevNodeName = nodeIdNodeNameMap.put( uniqId, nodeName ); if( prevNodeName != null ) { assertEquals(uniqId + " is used for more than one node instance: ", prevNodeName, nodeName); } }
@Override public AuditEvent buildEvent(ProcessNodeTriggeredEvent pnte) { ProcessInstanceImpl pi = (ProcessInstanceImpl) pnte.getProcessInstance(); NodeInstanceImpl nodeInstance = (NodeInstanceImpl) pnte.getNodeInstance(); Node node = nodeInstance.getNode(); String nodeId = null; String nodeType = null; String nodeContainerId = null; if (node != null) { nodeId = (String)node.getMetaData().get("UniqueId"); nodeType = node.getClass().getSimpleName(); nodeContainerId = getNodeContainerId(node.getNodeContainer()); } else { nodeId = Long.toString(nodeInstance.getNodeId()); nodeType = (String)nodeInstance.getMetaData("NodeType"); NodeInstanceLog.TYPE_ENTER, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName()); if (nodeInstance instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) nodeInstance).getWorkItem() != null) { log.setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItem().getId()); String connection = (String)nodeInstance.getMetaData().get("IncomingConnection"); log.setConnection(connection); log.setExternalId(""+((KieSession) pnte.getKieRuntime()).getIdentifier()); log.setNodeType(nodeType); log.setNodeContainerId(nodeContainerId); log.setDate(pnte.getEventDate()); log.setSlaCompliance(nodeInstance.getSlaCompliance()); log.setSlaDueDate(nodeInstance.getSlaDueDate()); return log;
public void retrigger(boolean remove) { if (remove) { cancel(); } triggerNode(getNodeId(), remove == false); }
public void triggerNode(long nodeId, boolean fireEvents) { org.jbpm.workflow.instance.NodeInstance nodeInstance = (org.jbpm.workflow.instance.NodeInstance) ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()) .getNodeInstance(getNode().getNodeContainer().getNode(nodeId)); triggerNodeInstance(nodeInstance, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, fireEvents); }
protected void triggerConnection(Connection connection) { triggerNodeInstance(followConnection(connection), connection.getToType()); }
@SuppressWarnings("unchecked") private void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, String> nodeMapping, NodeContainer nodeContainer, EntityManager em) { for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) { if (nodeInstance.getNode() == null) { continue; String oldNodeId = (String) ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getMetaData().get("UniqueId"); String newNodeId = nodeMapping.get(oldNodeId); if (newNodeId == null) { Boolean isHidden = (Boolean) ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getMetaData().get("hidden"); if (isHidden != null && isHidden.booleanValue()) { upgradedNodeId = upgradedNode.getId(); ((NodeInstanceImpl) nodeInstance).setNodeId(upgradedNodeId); nodeInstanceIdQuery .setParameter("oldNodeId", oldNodeId) .setParameter("processInstanceId", nodeInstance.getProcessInstance().getId()); "where nodeInstanceId in (:ids) and processInstanceId = :processInstanceId"); nodeLogQuery .setParameter("nodeId", (String) upgradedNode.getMetaData().get("UniqueId")) .setParameter("nodeName", VariableUtil.resolveVariable(upgradedNode.getName(), nodeInstance)) .setParameter("nodeType", upgradedNode.getClass().getSimpleName()) .setParameter("ids", nodeInstanceIds) .setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());
public NodeInstance getNodeInstance(Node node, WorkflowProcessInstance processInstance, NodeInstanceContainer nodeInstanceContainer) { try { NodeInstanceImpl nodeInstance = (NodeInstanceImpl) this.cls.newInstance(); nodeInstance.setNodeId(node.getId()); nodeInstance.setNodeInstanceContainer(nodeInstanceContainer); nodeInstance.setProcessInstance(processInstance); String uniqueId = (String) node.getMetaData().get("UniqueId"); assert uniqueId != null : node.getClass().getSimpleName() + " [" + node.getName() + "] does not have a unique id."; if (uniqueId == null) { uniqueId = node.getId()+""; } nodeInstance.setMetaData("UniqueId", uniqueId); int level = ((org.jbpm.workflow.instance.NodeInstanceContainer)nodeInstanceContainer).getLevelForNode(uniqueId); nodeInstance.setLevel(level); return nodeInstance; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Unable to instantiate node: '" + this.cls.getName() + "':" + e.getMessage()); } }
protected void triggerCompleted(String type, boolean remove) { getExecutionErrorHandler().processed(this); Node node = getNode(); if (node != null) { String uniqueId = (String) node.getMetaData().get("UniqueId"); if( uniqueId == null ) { uniqueId = ((NodeImpl) node).getUniqueId(); if ((getNodeInstanceContainer().getNodeInstance(getId()) == null) || (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE)) { return; ((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()) .removeNodeInstance(this); selectedConnection, selectedConstraint ) ) { nodeInstances.add(new NodeInstanceTrigger(followConnection(selectedConnection), selectedConnection.getToType())); found = true; if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) { return; triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType()); ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl)node).getConstraint( connection ); if ( constraint.isDefault() ) { triggerConnection(connection); found = true; break;
protected void triggerNodeInstance(org.jbpm.workflow.instance.NodeInstance nodeInstance, String type, boolean fireEvents) { boolean hidden = false; if (getNode().getMetaData().get("hidden") != null) { hidden = true; } InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); if (!hidden && fireEvents) { ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime); } // trigger next node nodeInstance.trigger(this, type); Collection<Connection> outgoing = getNode().getOutgoingConnections(type); for (Connection conn : outgoing) { if (conn.getTo().getId() == nodeInstance.getNodeId()) { this.metaData.put("OutgoingConnection", conn.getMetaData().get("UniqueId")); break; } } if (!hidden && fireEvents) { ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireAfterNodeLeft(this, kruntime); } }
Node node = nodeInstance.getNode(); String nodeId = null; String nodeType = null; String nodeContainerId = null; if (node != null) { nodeId = (String)node.getMetaData().get("UniqueId"); nodeType = node.getClass().getSimpleName(); nodeContainerId = getNodeContainerId(node.getNodeContainer()); } else { nodeId = Long.toString(nodeInstance.getNodeId()); nodeType = (String)nodeInstance.getMetaData("NodeType"); } else { logEvent = new NodeInstanceLog( NodeInstanceLog.TYPE_EXIT, pi.getId(), pi.getProcessId(), Long.toString(nodeInstance.getId()), nodeId, nodeInstance.getNodeName()); logEvent.setReferenceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId()); String connection = (String)nodeInstance.getMetaData().get("OutgoingConnection"); logEvent.setConnection(connection); logEvent.setExternalId(""+((KieSession) pnle.getKieRuntime()).getIdentifier()); logEvent.setNodeContainerId(nodeContainerId); logEvent.setDate(pnle.getEventDate()); logEvent.setSlaCompliance(nodeInstance.getSlaCompliance()); logEvent.setSlaDueDate(nodeInstance.getSlaDueDate()); return logEvent;
private static void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) { for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) { String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId(); Long newNodeId = nodeMapping.get(oldNodeId); if (newNodeId == null) { newNodeId = nodeInstance.getNodeId(); } // clean up iteration levels for removed (old) nodes Map<String, Integer> iterLevels = ((WorkflowProcessInstanceImpl) nodeInstance.getProcessInstance()).getIterationLevels(); String uniqueId = (String) ((NodeImpl) nodeInstance.getNode()).getMetaData("UniqueId"); iterLevels.remove(uniqueId); // and now set to new node id ((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId); if (nodeInstance instanceof NodeInstanceContainer) { updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping); } } }
@Override public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { // trigger this to record some of the data (like work item id) after activity was triggered NodeInstanceLog log = (NodeInstanceLog) ((NodeInstanceImpl) event.getNodeInstance()).getMetaData().get("NodeInstanceLog"); builder.buildEvent(event, log); }
private void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) { for (NodeInstance nodeInstance: nodeInstanceContainer.getNodeInstances()) { String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId(); Long newNodeId = nodeMapping.get(oldNodeId); if (newNodeId == null) { newNodeId = nodeInstance.getNodeId(); } ((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId); if (nodeInstance instanceof NodeInstanceContainer) { updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping); } } }
public void cancel() { boolean hidden = false; Node node = getNode(); if (node != null && node.getMetaData().get("hidden") != null) { hidden = true; } if (!hidden) { InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireBeforeNodeLeft(this, kruntime); } nodeInstanceContainer.removeNodeInstance(this); if (!hidden) { InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime(); ((InternalProcessRuntime) kruntime.getProcessRuntime()) .getProcessEventSupport().fireAfterNodeLeft(this, kruntime); } }
protected String nodeName(NodeInstance nodeInstance) { try { return nodeInstance.getNodeName(); } catch (IllegalStateException e) { NodeInstanceLog nodeInstanceLog = (NodeInstanceLog) ((NodeInstanceImpl) nodeInstance).getMetaData("NodeInstanceLog"); if (nodeInstanceLog != null) { return nodeInstanceLog.getNodeName(); } return ""; } }
@Override public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { logAndAdd("ant-" + ((NodeInstanceImpl) event.getNodeInstance()).getUniqueId()); }
processInstance); nodeInstance.setNodeId( _node.getNodeId() ); nodeInstance.setId( _node.getId() ); nodeInstance.setNodeInstanceContainer( nodeInstanceContainer ); nodeInstance.setProcessInstance( (org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance ); nodeInstance.setLevel(_node.getLevel()==0?1:_node.getLevel()); nodeInstance.internalSetSlaCompliance(_node.getSlaCompliance()); if (_node.getSlaDueDate() > 0) { nodeInstance.internalSetSlaDueDate(new Date(_node.getSlaDueDate())); nodeInstance.internalSetSlaTimerId(_node.getSlaTimerId()); ((CompositeContextNodeInstance) nodeInstance).addContextInstance( ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance ); for ( Long nodeInstanceId : _excl.getGroupNodeInstanceIdList() ) { NodeInstance groupNodeInstance = ((org.jbpm.workflow.instance.NodeInstanceContainer)processInstance).getNodeInstance( nodeInstanceId, true ); if ( groupNodeInstance == null ) { throw new IllegalArgumentException( "Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId );
if (event.getNodeInstance() != null) { long nodeInstanceId = event.getNodeInstance().getId(); long processInstanceId = event.getProcessInstance().getId(); NodeInstanceLog log = (NodeInstanceLog) ((NodeInstanceImpl) event.getNodeInstance()).getMetaData().get("NodeInstanceLog"); if (log == null) { List<NodeInstanceLog> result = em.createQuery( log.setSlaCompliance(((NodeInstance)event.getNodeInstance()).getSlaCompliance()); em.merge(log);