private boolean isAttachedToNodeActive(Collection<NodeInstance> nodeInstances, String attachedTo, String type, Object event) { if (nodeInstances != null && !nodeInstances.isEmpty()) { for (NodeInstance nInstance : nodeInstances) { String nodeUniqueId = (String) nInstance.getNode().getMetaData().get("UniqueId"); boolean isActivating = ((WorkflowProcessInstanceImpl)nInstance.getProcessInstance()).getActivatingNodeIds().contains(nodeUniqueId); if (attachedTo.equals(nodeUniqueId) && !isActivating) { // in case this is timer event make sure it corresponds to the proper node instance if (type.startsWith("Timer-")) { if (Long.valueOf(nInstance.getId()).equals(event)) { return true; } } else { return true; } } if (nInstance instanceof CompositeNodeInstance) { boolean hasActive = isAttachedToNodeActive(((CompositeNodeInstance) nInstance).getNodeInstances(), attachedTo, type, event); if (hasActive) { return true; } } } } return false; }
public void execute(ProcessContext context) throws Exception { WorkflowProcessInstance pi = context.getNodeInstance().getProcessInstance(); NodeInstance nodeInstance = findNodeByUniqueId(pi.getNodeInstances(), attachedToNodeId); if (nodeInstance != null) { ((org.jbpm.workflow.instance.NodeInstance)nodeInstance).cancel(); } }
nodeInstanceIdQuery .setParameter("oldNodeId", oldNodeId) .setParameter("processInstanceId", nodeInstance.getProcessInstance().getId()); .setParameter("nodeType", upgradedNode.getClass().getSimpleName()) .setParameter("ids", nodeInstanceIds) .setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());
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); } } }
logger.debug("Last executed node instance {} will be used to populate error details", nodeInstance); errorBuilder .deploymentId(((ProcessInstanceImpl)nodeInstance.getProcessInstance()).getDeploymentId()) .processInstanceId(nodeInstance.getProcessInstance().getId()) .processId(nodeInstance.getProcessInstance().getProcessId()) .activityId(nodeInstance.getId()) .activityName(nodeName(nodeInstance));
public WorkflowProcessInstance getProcessInstance() { return new WorkflowProcessInstanceAdapter(delegate.getProcessInstance()); }
private boolean isAttachedToNodeActive(Collection<NodeInstance> nodeInstances, String attachedTo, String type, Object event) { if (nodeInstances != null && !nodeInstances.isEmpty()) { for (NodeInstance nInstance : nodeInstances) { String nodeUniqueId = (String) nInstance.getNode().getMetaData().get("UniqueId"); boolean isActivating = ((WorkflowProcessInstanceImpl)nInstance.getProcessInstance()).getActivatingNodeIds().contains(nodeUniqueId); if (attachedTo.equals(nodeUniqueId) && !isActivating) { // in case this is timer event make sure it corresponds to the proper node instance if (type.startsWith("Timer-")) { if (Long.valueOf(nInstance.getId()).equals(event)) { return true; } } else { return true; } } if (nInstance instanceof CompositeNodeInstance) { boolean hasActive = isAttachedToNodeActive(((CompositeNodeInstance) nInstance).getNodeInstances(), attachedTo, type, event); if (hasActive) { return true; } } } } return false; }
public void execute(ProcessContext context) throws Exception { WorkflowProcessInstance pi = context.getNodeInstance().getProcessInstance(); NodeInstance nodeInstance = findNodeByUniqueId(pi.getNodeInstances(), attachedToNodeId); if (nodeInstance != null) { ((org.jbpm.workflow.instance.NodeInstance)nodeInstance).cancel(); } }
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 ExecutionError filter(ExecutionErrorContext errorContext) { AsyncJobException exception = extract(errorContext.getCause(), AsyncJobException.class); String stacktrace = getStackTrace(exception); NodeInstance nodeInstance = errorContext.getLastExecutedNode(); return ExecutionError.builder() .type(TYPE) .initActivityId(getInitActivityId(errorContext)) .deploymentId(((ProcessInstanceImpl)nodeInstance.getProcessInstance()).getDeploymentId()) .processInstanceId(nodeInstance.getProcessInstance().getId()) .processId(nodeInstance.getProcessInstance().getProcessId()) .activityId(nodeInstance.getId()) .activityName(nodeName(nodeInstance)) .jobId(exception.getJobId()) .message(exception.getMessage()) .error(stacktrace) .errorDate(new Date()) .build(); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance gateway = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); Map<String, Object> metadata = gateway.getNode().getMetaData(); ProcessInstance pi = gateway.getProcessInstance(); Node node = gateway.getNode(); String bpmn2NodeId = (String) metadata.get("UniqueId"); // todo long duration = 0; long endTime = startTime + duration; context.getClock().advanceTime(duration, TimeUnit.MILLISECONDS); // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); SimulationDataProvider provider = context.getDataProvider(); String type = (String) provider.getProcessDataForNode(node).get("node.type"); return new GatewaySimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), startTime, endTime, bpmn2NodeId, node.getName(), type); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance gateway = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); Map<String, Object> metadata = gateway.getNode().getMetaData(); ProcessInstance pi = gateway.getProcessInstance(); Node node = gateway.getNode(); String bpmn2NodeId = (String) metadata.get("UniqueId"); // todo long duration = 0; long endTime = startTime + duration; context.getClock().advanceTime(duration, TimeUnit.MILLISECONDS); // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); SimulationDataProvider provider = context.getDataProvider(); String type = (String) provider.getProcessDataForNode(node).get("node.type"); return new GatewaySimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), startTime, endTime, bpmn2NodeId, node.getName(), type); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance nodeInstance = (NodeInstance) activity; ProcessInstance pi = nodeInstance.getProcessInstance(); context.setStartTime(context.getClock().getCurrentTime()); Node node = nodeInstance.getNode(); String bpmn2NodeId = (String) node.getMetaData().get("UniqueId"); // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); return new StartSimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), context.getStartTime(), context.getClock().getCurrentTime(), bpmn2NodeId, node.getName()); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance nodeInstance = (NodeInstance) activity; ProcessInstance pi = nodeInstance.getProcessInstance(); context.setStartTime(context.getClock().getCurrentTime()); Node node = nodeInstance.getNode(); String bpmn2NodeId = (String) node.getMetaData().get("UniqueId"); // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); return new StartSimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), context.getStartTime(), context.getClock().getCurrentTime(), bpmn2NodeId, node.getName()); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance eventNodeInstance = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); Map<String, Object> metadata = eventNodeInstance.getNode().getMetaData(); ProcessInstance pi = eventNodeInstance.getProcessInstance(); Node node = eventNodeInstance.getNode(); String bpmn2NodeId = (String) metadata.get("UniqueId"); SimulationDataProvider provider = context.getDataProvider(); TimeGenerator timeGenerator=TimeGeneratorFactory.newTimeGenerator(provider.getSimulationDataForNode(node)); long duration = timeGenerator.generateTime(); context.getClock().advanceTime(duration, TimeUnit.MILLISECONDS); // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); String type = (String) provider.getProcessDataForNode(node).get("node.type"); return new ActivitySimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), node.getName(), bpmn2NodeId, duration, startTime, context.getClock().getCurrentTime(), type); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance eventNodeInstance = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); Map<String, Object> metadata = eventNodeInstance.getNode().getMetaData(); ProcessInstance pi = eventNodeInstance.getProcessInstance(); Node node = eventNodeInstance.getNode(); String bpmn2NodeId = (String) metadata.get("UniqueId"); SimulationDataProvider provider = context.getDataProvider(); TimeGenerator timeGenerator=TimeGeneratorFactory.newTimeGenerator(provider.getSimulationDataForNode(node)); long duration = timeGenerator.generateTime(); context.getClock().advanceTime(duration, TimeUnit.MILLISECONDS); // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); String type = (String) provider.getProcessDataForNode(node).get("node.type"); return new ActivitySimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), node.getName(), bpmn2NodeId, duration, startTime, context.getClock().getCurrentTime(), type); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance nodeInstance = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); ProcessInstance pi = nodeInstance.getProcessInstance(); Node node = nodeInstance.getNode(); String bpmn2NodeId = (String) node.getMetaData().get("UniqueId"); String processName = pi.getProcessName(); String processVer = pi.getProcess().getVersion(); if (processVer == null) { processVer = ""; } // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); return new EndSimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), startTime, context.getClock().getCurrentTime(), context.getStartTime(), bpmn2NodeId, node.getName(), processName, processVer); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance stateNode = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); Map<String, Object> metadata = stateNode.getNode().getMetaData(); ProcessInstance pi = stateNode.getProcessInstance(); Node node = stateNode.getNode(); String bpmn2NodeId = (String) metadata.get("UniqueId"); SimulationDataProvider provider = context.getDataProvider(); TimeGenerator timeGenerator=TimeGeneratorFactory.newTimeGenerator(provider.getSimulationDataForNode(node)); long duration = timeGenerator.generateTime(); context.getClock().advanceTime(duration, TimeUnit.MILLISECONDS); // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); String type = (String) provider.getProcessDataForNode(node).get("node.type"); return new ActivitySimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), node.getName(), bpmn2NodeId, duration, startTime, context.getClock().getCurrentTime(), type); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance stateNode = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); Map<String, Object> metadata = stateNode.getNode().getMetaData(); ProcessInstance pi = stateNode.getProcessInstance(); Node node = stateNode.getNode(); String bpmn2NodeId = (String) metadata.get("UniqueId"); SimulationDataProvider provider = context.getDataProvider(); TimeGenerator timeGenerator=TimeGeneratorFactory.newTimeGenerator(provider.getSimulationDataForNode(node)); long duration = timeGenerator.generateTime(); context.getClock().advanceTime(duration, TimeUnit.MILLISECONDS); // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); String type = (String) provider.getProcessDataForNode(node).get("node.type"); return new ActivitySimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), node.getName(), bpmn2NodeId, duration, startTime, context.getClock().getCurrentTime(), type); }
public SimulationEvent simulate(Object activity, SimulationContext context) { NodeInstance nodeInstance = (NodeInstance) activity; long startTime = context.getClock().getCurrentTime(); ProcessInstance pi = nodeInstance.getProcessInstance(); Node node = nodeInstance.getNode(); String bpmn2NodeId = (String) node.getMetaData().get("UniqueId"); String processName = pi.getProcessName(); String processVer = pi.getProcess().getVersion(); if (processVer == null) { processVer = ""; } // set end time for processinstance end time context.setMaxEndTime(context.getClock().getCurrentTime()); return new EndSimulationEvent(pi.getProcessId(), context.getProcessInstanceId(), startTime, context.getClock().getCurrentTime(), context.getStartTime(), bpmn2NodeId, node.getName(), processName, processVer); }