public void nodeInstanceCompleted(org.jbpm.workflow.instance.NodeInstance nodeInstance, String outType) { Node nodeInstanceNode = nodeInstance.getNode(); if( nodeInstanceNode != null ) { Object compensationBoolObj = nodeInstanceNode.getMetaData().get("isForCompensation"); boolean isForCompensation = compensationBoolObj == null ? false : ((Boolean) compensationBoolObj); if( isForCompensation ) { return; } } String completionCondition = getDynamicNode().getCompletionExpression(); // TODO what if we reach the end of one branch but others might still need to be created ? // TODO are we sure there will always be node instances left if we are not done yet? if (isTerminated(nodeInstance)) { triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } else if (getDynamicNode().isAutoComplete() && getNodeInstances(false).isEmpty()) { triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } else if (completionCondition != null && "mvel".equals(getDynamicNode().getLanguage())) { Object value = MVELSafeHelper.getEvaluator().eval(completionCondition, new NodeInstanceResolverFactory(this)); if ( !(value instanceof Boolean) ) { throw new RuntimeException( "Completion condition expression must return boolean values: " + value + " for expression " + completionCondition); } if (((Boolean) value).booleanValue()) { triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } } }
public void internalTrigger(NodeInstance from, String type) { triggerEvent(ExtendedNodeImpl.EVENT_NODE_ENTER); if (getNodeInstanceContainer().getNodeInstance(getId()) == null) { return; InternalAgenda agenda = (InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda(); String ruleFlowGroup = getRuleFlowGroupName(); if (ruleFlowGroup != null && !agenda.getRuleFlowGroup(ruleFlowGroup).isActive()) { agenda.getRuleFlowGroup(ruleFlowGroup).setAutoDeactivate(false); agenda.activateRuleFlowGroup(ruleFlowGroup, getProcessInstance().getId(), getUniqueId()); String rule = "RuleFlow-AdHocComplete-" + getProcessInstance().getProcessId() + "-" + getDynamicNode().getUniqueId(); boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()) .isRuleActiveInRuleFlowGroup(getRuleFlowGroupName(), rule, getProcessInstance().getId()); if (isActive) { triggerCompleted(); } else { addActivationListener(); List<Node> autoStartNodes = getDynamicNode().getAutoStartNodes(); autoStartNodes .forEach(austoStartNode -> triggerSelectedNode(austoStartNode, null));
public void matchCreated(MatchCreatedEvent event) { // check whether this activation is from the DROOLS_SYSTEM agenda group String ruleFlowGroup = ((RuleImpl) event.getMatch().getRule()).getRuleFlowGroup(); if ("DROOLS_SYSTEM".equals(ruleFlowGroup)) { // new activations of the rule associate with a milestone node // trigger node instances of that milestone node String ruleName = event.getMatch().getRule().getName(); String milestoneName = "RuleFlow-AdHocComplete-" + getProcessInstance().getProcessId() + "-" + getNodeId(); if (milestoneName.equals(ruleName) && checkProcessInstance((Activation) event.getMatch()) && checkDeclarationMatch(event.getMatch(), (String) getVariable("MatchVariable"))) { synchronized(getProcessInstance()) { DynamicNodeInstance.this.removeEventListeners(); DynamicNodeInstance.this.triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } } } }
private void addActivationListener() { getProcessInstance().getKnowledgeRuntime().addEventListener(this); getProcessInstance().addEventListener(getActivationEventType(), this, true); }
private String getActivationEventType() { return "RuleFlow-AdHocComplete-" + getProcessInstance().getProcessId() + "-" + getDynamicNode().getUniqueId(); }
@Override public void signalEvent(String type, Object event) { if (type.startsWith("RuleFlow-AdHocActivate")) { if (event instanceof MatchCreatedEvent) { Match match = ((MatchCreatedEvent) event).getMatch(); match.getDeclarationIds().forEach(s -> this.setVariable(s.replaceFirst("\\$", ""), match.getDeclarationValue(s))); } trigger(null, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE); } else if (getActivationEventType().equals(type)) { if (event instanceof MatchCreatedEvent) { matchCreated((MatchCreatedEvent) event); } } else { super.signalEvent(type, event); for (Node node: getCompositeNode().getNodes()) { if (type.equals(resolveVariable(node.getName())) && node.getIncomingConnections().isEmpty()) { triggerSelectedNode(node, event); } } } }
parameters.put("TaskName", "Dynamic Task"); assertNull(handler.getWorkItem()); assertEquals(0, dynamicContext.getNodeInstances().size()); DynamicUtils.addDynamicWorkItem(dynamicContext, ksession, "Human Task", parameters); assertNotNull(handler.getWorkItem()); assertEquals(1, dynamicContext.getNodeInstances().size()); logger.close();
break; case PersisterEnums.DYNAMIC_NODE_INSTANCE: nodeInstance = new DynamicNodeInstance(); nbTimerInstances = stream.readInt(); if (nbTimerInstances > 0) {
public void addEventListeners() { super.addEventListeners(); addActivationListener(); }
protected DynamicNode getDynamicNode() { return (DynamicNode) getNode(); }
@Override public void signalEvent(String type, Object event) { if (type.startsWith("RuleFlow-AdHocActivate")) { if (event instanceof MatchCreatedEvent) { Match match = ((MatchCreatedEvent) event).getMatch(); match.getDeclarationIds().forEach(s -> this.setVariable(s.replaceFirst("\\$", ""), match.getDeclarationValue(s))); } trigger(null, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE); } else if (getActivationEventType().equals(type)) { if (event instanceof MatchCreatedEvent) { matchCreated((MatchCreatedEvent) event); } } else { super.signalEvent(type, event); for (Node node: getCompositeNode().getNodes()) { if (type.equals(resolveVariable(node.getName())) && node.getIncomingConnections().isEmpty()) { triggerSelectedNode(node, event); } } } }
public void removeEventListeners() { super.removeEventListeners(); getProcessInstance().getKnowledgeRuntime().removeEventListener(this); getProcessInstance().removeEventListener(getActivationEventType(), this, true); }
private String getActivationEventType() { return "RuleFlow-AdHocComplete-" + getProcessInstance().getProcessId() + "-" + getDynamicNode().getUniqueId(); }
parameters.put("x", "NewValue"); assertNull(handler.getWorkItem()); assertEquals(0, dynamicContext.getNodeInstances().size()); DynamicUtils.addDynamicSubProcess(dynamicContext, ksession, "org.drools.subflow", parameters); assertNotNull(handler.getWorkItem()); assertEquals(1, dynamicContext.getNodeInstances().size()); logger.close();
nodeInstance = new DynamicNodeInstance(); if ( _content.getComposite().getTimerInstanceIdCount() > 0 ) { List<Long> timerInstances = new ArrayList<Long>();
public void addEventListeners() { super.addEventListeners(); addActivationListener(); }
protected DynamicNode getDynamicNode() { return (DynamicNode) getNode(); }
public void internalTrigger(NodeInstance from, String type) { triggerEvent(ExtendedNodeImpl.EVENT_NODE_ENTER); if (getNodeInstanceContainer().getNodeInstance(getId()) == null) { return; InternalAgenda agenda = (InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda(); String ruleFlowGroup = getRuleFlowGroupName(); if (ruleFlowGroup != null && !agenda.getRuleFlowGroup(ruleFlowGroup).isActive()) { agenda.getRuleFlowGroup(ruleFlowGroup).setAutoDeactivate(false); agenda.activateRuleFlowGroup(ruleFlowGroup, getProcessInstance().getId(), getUniqueId()); String rule = "RuleFlow-AdHocComplete-" + getProcessInstance().getProcessId() + "-" + getDynamicNode().getUniqueId(); boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()) .isRuleActiveInRuleFlowGroup(getRuleFlowGroupName(), rule, getProcessInstance().getId()); if (isActive) { triggerCompleted(); } else { addActivationListener(); List<Node> autoStartNodes = getDynamicNode().getAutoStartNodes(); autoStartNodes .forEach(austoStartNode -> triggerSelectedNode(austoStartNode, null));
public void matchCreated(MatchCreatedEvent event) { // check whether this activation is from the DROOLS_SYSTEM agenda group String ruleFlowGroup = ((RuleImpl) event.getMatch().getRule()).getRuleFlowGroup(); if ("DROOLS_SYSTEM".equals(ruleFlowGroup)) { // new activations of the rule associate with a milestone node // trigger node instances of that milestone node String ruleName = event.getMatch().getRule().getName(); String milestoneName = "RuleFlow-AdHocComplete-" + getProcessInstance().getProcessId() + "-" + getNodeId(); if (milestoneName.equals(ruleName) && checkProcessInstance((Activation) event.getMatch()) && checkDeclarationMatch(event.getMatch(), (String) getVariable("MatchVariable"))) { synchronized(getProcessInstance()) { DynamicNodeInstance.this.removeEventListeners(); DynamicNodeInstance.this.triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } } } }
public void nodeInstanceCompleted(org.jbpm.workflow.instance.NodeInstance nodeInstance, String outType) { Node nodeInstanceNode = nodeInstance.getNode(); if( nodeInstanceNode != null ) { Object compensationBoolObj = nodeInstanceNode.getMetaData().get("isForCompensation"); boolean isForCompensation = compensationBoolObj == null ? false : ((Boolean) compensationBoolObj); if( isForCompensation ) { return; } } String completionCondition = getDynamicNode().getCompletionExpression(); // TODO what if we reach the end of one branch but others might still need to be created ? // TODO are we sure there will always be node instances left if we are not done yet? if (isTerminated(nodeInstance)) { triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } else if (getDynamicNode().isAutoComplete() && getNodeInstances(false).isEmpty()) { triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } else if (completionCondition != null && "mvel".equals(getDynamicNode().getLanguage())) { Object value = MVELSafeHelper.getEvaluator().eval(completionCondition, new NodeInstanceResolverFactory(this)); if ( !(value instanceof Boolean) ) { throw new RuntimeException( "Completion condition expression must return boolean values: " + value + " for expression " + completionCondition); } if (((Boolean) value).booleanValue()) { triggerCompleted(NodeImpl.CONNECTION_DEFAULT_TYPE); } } }