use of org.jbpm.workflow.instance.node.EventSubProcessNodeInstance in project jbpm by kiegroup.
the class WorkflowProcessInstanceImpl method start.
public void start(String trigger) {
synchronized (this) {
registerExternalEventNodeListeners();
// activate timer event sub processes
Node[] nodes = getNodeContainer().getNodes();
for (Node node : nodes) {
if (node instanceof EventSubProcessNode) {
Map<Timer, DroolsAction> timers = ((EventSubProcessNode) node).getTimers();
if (timers != null && !timers.isEmpty()) {
EventSubProcessNodeInstance eventSubprocess = (EventSubProcessNodeInstance) getNodeInstance(node);
eventSubprocess.trigger(null, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
}
}
}
super.start(trigger);
}
}
use of org.jbpm.workflow.instance.node.EventSubProcessNodeInstance in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method readNodeInstance.
public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer, WorkflowProcessInstance processInstance) throws IOException {
JBPMMessages.ProcessInstance.NodeInstance _node = (JBPMMessages.ProcessInstance.NodeInstance) context.parameterObject;
NodeInstanceImpl nodeInstance = readNodeInstanceContent(_node, context, 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());
switch(_node.getContent().getType()) {
case COMPOSITE_CONTEXT_NODE:
case DYNAMIC_NODE:
if (_node.getContent().getComposite().getVariableCount() > 0) {
Context variableScope = ((org.jbpm.process.core.Process) ((org.jbpm.process.instance.ProcessInstance) processInstance).getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
for (JBPMMessages.Variable _variable : _node.getContent().getComposite().getVariableList()) {
try {
Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
variableScopeInstance.internalSetVariable(_variable.getName(), _value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
}
}
}
if (_node.getContent().getComposite().getIterationLevelsCount() > 0) {
for (JBPMMessages.IterationLevel _level : _node.getContent().getComposite().getIterationLevelsList()) {
((CompositeContextNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
context.parameterObject = _instance;
readNodeInstance(context, (CompositeContextNodeInstance) nodeInstance, processInstance);
}
for (JBPMMessages.ProcessInstance.ExclusiveGroupInstance _excl : _node.getContent().getComposite().getExclusiveGroupList()) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
((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);
}
exclusiveGroupInstance.addNodeInstance(groupNodeInstance);
}
}
break;
case FOR_EACH_NODE:
for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getForEach().getNodeInstanceList()) {
context.parameterObject = _instance;
readNodeInstance(context, (ForEachNodeInstance) nodeInstance, processInstance);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ForEachNodeInstance) nodeInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
for (JBPMMessages.Variable _variable : _node.getContent().getForEach().getVariableList()) {
try {
Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
variableScopeInstance.internalSetVariable(_variable.getName(), _value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
}
}
if (_node.getContent().getForEach().getIterationLevelsCount() > 0) {
for (JBPMMessages.IterationLevel _level : _node.getContent().getForEach().getIterationLevelsList()) {
((ForEachNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
}
break;
case EVENT_SUBPROCESS_NODE:
for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
context.parameterObject = _instance;
readNodeInstance(context, (EventSubProcessNodeInstance) nodeInstance, processInstance);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((EventSubProcessNodeInstance) nodeInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
for (JBPMMessages.Variable _variable : _node.getContent().getComposite().getVariableList()) {
try {
Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
variableScopeInstance.internalSetVariable(_variable.getName(), _value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
}
}
}
break;
default:
}
return nodeInstance;
}
use of org.jbpm.workflow.instance.node.EventSubProcessNodeInstance in project jbpm by kiegroup.
the class CompensationScopeInstance method handleException.
public void handleException(ExceptionHandler handler, String compensationActivityRef, Object dunno) {
WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) getProcessInstance();
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getContextInstanceContainer();
if (handler instanceof CompensationHandler) {
CompensationHandler compensationHandler = (CompensationHandler) handler;
try {
Node handlerNode = compensationHandler.getnode();
if (handlerNode instanceof BoundaryEventNode) {
NodeInstance compensationHandlerNodeInstance = nodeInstanceContainer.getNodeInstance(handlerNode);
compensationInstances.add(compensationHandlerNodeInstance);
// The BoundaryEventNodeInstance.signalEvent() contains the necessary logic
// to check whether or not compensation may proceed (? : (not-active + completed))
EventNodeInstance eventNodeInstance = (EventNodeInstance) compensationHandlerNodeInstance;
eventNodeInstance.signalEvent("Compensation", compensationActivityRef);
} else if (handlerNode instanceof EventSubProcessNode) {
// Check that subprocess parent has completed.
List<String> completedIds = processInstance.getCompletedNodeIds();
if (completedIds.contains(((NodeImpl) handlerNode.getNodeContainer()).getMetaData("UniqueId"))) {
NodeInstance subProcessNodeInstance = ((NodeInstanceContainer) nodeInstanceContainer).getNodeInstance((Node) handlerNode.getNodeContainer());
compensationInstances.add(subProcessNodeInstance);
NodeInstance compensationHandlerNodeInstance = ((NodeInstanceContainer) subProcessNodeInstance).getNodeInstance(handlerNode);
compensationInstances.add(compensationHandlerNodeInstance);
EventSubProcessNodeInstance eventNodeInstance = (EventSubProcessNodeInstance) compensationHandlerNodeInstance;
eventNodeInstance.signalEvent("Compensation", compensationActivityRef);
}
}
assert handlerNode instanceof BoundaryEventNode || handlerNode instanceof EventSubProcessNode : "Unexpected compensation handler node type : " + handlerNode.getClass().getSimpleName();
} catch (Exception e) {
throwWorkflowRuntimeException(nodeInstanceContainer, processInstance, "Unable to execute compensation.", e);
}
} else {
Exception e = new IllegalArgumentException("Unsupported compensation handler: " + handler);
throwWorkflowRuntimeException(nodeInstanceContainer, processInstance, e.getMessage(), e);
}
}
use of org.jbpm.workflow.instance.node.EventSubProcessNodeInstance in project jbpm by kiegroup.
the class WorkflowProcessInstanceImpl method signalEvent.
@SuppressWarnings("unchecked")
public void signalEvent(String type, Object event) {
logger.debug("Signal {} received with data {} in process instance {}", type, event, getId());
synchronized (this) {
if (getState() != ProcessInstance.STATE_ACTIVE) {
return;
}
if ("timerTriggered".equals(type)) {
TimerInstance timer = (TimerInstance) event;
if (timer.getId() == slaTimerId) {
handleSLAViolation();
// no need to pass the event along as it was purely for SLA tracking
return;
}
}
if ("slaViolation".equals(type)) {
handleSLAViolation();
// no need to pass the event along as it was purely for SLA tracking
return;
}
List<NodeInstance> currentView = new ArrayList<NodeInstance>(this.nodeInstances);
try {
this.activatingNodeIds = new ArrayList<String>();
List<EventListener> listeners = eventListeners.get(type);
if (listeners != null) {
for (EventListener listener : listeners) {
listener.signalEvent(type, event);
}
}
listeners = externalEventListeners.get(type);
if (listeners != null) {
for (EventListener listener : listeners) {
listener.signalEvent(type, event);
}
}
for (Node node : getWorkflowProcess().getNodes()) {
if (node instanceof EventNodeInterface) {
if (((EventNodeInterface) node).acceptsEvent(type, event, (e) -> resolveVariable(e))) {
if (node instanceof EventNode && ((EventNode) node).getFrom() == null) {
EventNodeInstance eventNodeInstance = (EventNodeInstance) getNodeInstance(node);
eventNodeInstance.signalEvent(type, event);
} else {
if (node instanceof EventSubProcessNode && ((resolveVariables(((EventSubProcessNode) node).getEvents()).contains(type)))) {
EventSubProcessNodeInstance eventNodeInstance = (EventSubProcessNodeInstance) getNodeInstance(node);
eventNodeInstance.signalEvent(type, event);
}
if (node instanceof DynamicNode && type.equals(((DynamicNode) node).getActivationEventName())) {
DynamicNodeInstance dynamicNodeInstance = (DynamicNodeInstance) getNodeInstance(node);
dynamicNodeInstance.signalEvent(type, event);
} else {
List<NodeInstance> nodeInstances = getNodeInstances(node.getId(), currentView);
if (nodeInstances != null && !nodeInstances.isEmpty()) {
for (NodeInstance nodeInstance : nodeInstances) {
((EventNodeInstanceInterface) nodeInstance).signalEvent(type, event);
}
}
}
}
}
}
}
if (((org.jbpm.workflow.core.WorkflowProcess) getWorkflowProcess()).isDynamic()) {
for (Node node : getWorkflowProcess().getNodes()) {
if (type.equals(node.getName()) && node.getIncomingConnections().isEmpty()) {
NodeInstance nodeInstance = getNodeInstance(node);
if (event != null) {
Map<String, Object> dynamicParams = new HashMap<>();
if (event instanceof Map) {
dynamicParams.putAll((Map<String, Object>) event);
} else {
dynamicParams.put("Data", event);
}
((org.jbpm.workflow.instance.NodeInstance) nodeInstance).setDynamicParameters(dynamicParams);
}
((org.jbpm.workflow.instance.NodeInstance) nodeInstance).trigger(null, NodeImpl.CONNECTION_DEFAULT_TYPE);
}
}
}
} finally {
if (this.activatingNodeIds != null) {
this.activatingNodeIds.clear();
this.activatingNodeIds = null;
}
}
}
}
use of org.jbpm.workflow.instance.node.EventSubProcessNodeInstance in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method readNodeInstanceContent.
protected NodeInstanceImpl readNodeInstanceContent(JBPMMessages.ProcessInstance.NodeInstance _node, MarshallerReaderContext context, WorkflowProcessInstance processInstance) throws IOException {
NodeInstanceImpl nodeInstance = null;
NodeInstanceContent _content = _node.getContent();
switch(_content.getType()) {
case RULE_SET_NODE:
nodeInstance = new RuleSetNodeInstance();
((RuleSetNodeInstance) nodeInstance).setRuleFlowGroup(_content.getRuleSet().getRuleFlowGroup());
if (_content.getRuleSet().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getRuleSet().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((RuleSetNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
if (_content.getRuleSet().getMapEntryCount() > 0) {
Map<String, FactHandle> factInfo = new HashMap<String, FactHandle>();
for (TextMapEntry entry : _content.getRuleSet().getMapEntryList()) {
factInfo.put(entry.getName(), DefaultFactHandle.createFromExternalFormat(entry.getValue()));
}
((RuleSetNodeInstance) nodeInstance).setFactHandles(factInfo);
}
break;
case HUMAN_TASK_NODE:
nodeInstance = new HumanTaskNodeInstance();
((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId(_content.getHumanTask().getWorkItemId());
if (_content.getHumanTask().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getHumanTask().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((HumanTaskNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case WORK_ITEM_NODE:
nodeInstance = new WorkItemNodeInstance();
((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId(_content.getWorkItem().getWorkItemId());
if (_content.getWorkItem().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getWorkItem().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((WorkItemNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case SUBPROCESS_NODE:
nodeInstance = new SubProcessNodeInstance();
((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId(_content.getSubProcess().getProcessInstanceId());
if (_content.getSubProcess().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getSubProcess().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((SubProcessNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case MILESTONE_NODE:
nodeInstance = new MilestoneNodeInstance();
if (_content.getMilestone().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getMilestone().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case TIMER_NODE:
nodeInstance = new TimerNodeInstance();
((TimerNodeInstance) nodeInstance).internalSetTimerId(_content.getTimer().getTimerId());
break;
case ASYNC_EVENT_NODE:
nodeInstance = new AsyncEventNodeInstance();
((AsyncEventNodeInstance) nodeInstance).setEventType(_content.getAsyncEvent().getEventType());
break;
case EVENT_NODE:
nodeInstance = new EventNodeInstance();
break;
case JOIN_NODE:
nodeInstance = new JoinInstance();
if (_content.getJoin().getTriggerCount() > 0) {
Map<Long, Integer> triggers = new HashMap<Long, Integer>();
for (JBPMMessages.ProcessInstance.NodeInstanceContent.JoinNode.JoinTrigger _join : _content.getJoin().getTriggerList()) {
triggers.put(_join.getNodeId(), _join.getCounter());
}
((JoinInstance) nodeInstance).internalSetTriggers(triggers);
}
break;
case FOR_EACH_NODE:
nodeInstance = new ForEachNodeInstance();
break;
case COMPOSITE_CONTEXT_NODE:
nodeInstance = new CompositeContextNodeInstance();
if (_content.getComposite().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case DYNAMIC_NODE:
nodeInstance = new DynamicNodeInstance();
if (_content.getComposite().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case STATE_NODE:
nodeInstance = new StateNodeInstance();
if (_content.getState().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getState().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case EVENT_SUBPROCESS_NODE:
nodeInstance = new EventSubProcessNodeInstance();
if (_content.getComposite().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
default:
throw new IllegalArgumentException("Unknown node type: " + _content.getType());
}
return nodeInstance;
}
Aggregations