use of io.automatiko.engine.api.runtime.process.NodeInstanceContainer in project automatiko-engine by automatiko-io.
the class AbstractProtobufProcessInstanceMarshaller method readNodeInstance.
public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer, WorkflowProcessInstance processInstance) throws IOException {
AutomatikoMessages.ProcessInstance.NodeInstance _node = (AutomatikoMessages.ProcessInstance.NodeInstance) context.parameterObject;
NodeInstanceImpl nodeInstance = readNodeInstanceContent(_node, context, processInstance);
nodeInstance.setNodeId(_node.getNodeId());
nodeInstance.setId(_node.getId());
nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
nodeInstance.setProcessInstance((io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) processInstance);
nodeInstance.setLevel(_node.getLevel() == 0 ? 1 : _node.getLevel());
nodeInstance.internalSetTriggerTime(new Date(_node.getTriggerDate()));
nodeInstance.internalSetSlaCompliance(_node.getSlaCompliance());
if (_node.getSlaDueDate() > 0) {
nodeInstance.internalSetSlaDueDate(new Date(_node.getSlaDueDate()));
}
nodeInstance.internalSetSlaTimerId(_node.getSlaTimerId());
nodeInstance.internalSetRetryJobId(_node.getRetryJobId());
nodeInstance.internalSetRetryAttempts(_node.getRetryAttempts());
switch(_node.getContent().getType()) {
case COMPOSITE_CONTEXT_NODE:
case DYNAMIC_NODE:
if (_node.getContent().getComposite().getVariableCount() > 0) {
Context variableScope = ((io.automatiko.engine.workflow.base.core.Process) ((io.automatiko.engine.workflow.base.instance.ProcessInstance) processInstance).getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
for (AutomatikoMessages.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 (AutomatikoMessages.IterationLevel _level : _node.getContent().getComposite().getIterationLevelsList()) {
((CompositeContextNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
for (AutomatikoMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
context.parameterObject = _instance;
readNodeInstance(context, (CompositeContextNodeInstance) nodeInstance, processInstance);
}
for (AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance _excl : _node.getContent().getComposite().getExclusiveGroupList()) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
((CompositeContextNodeInstance) nodeInstance).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
for (String nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
NodeInstance groupNodeInstance = ((io.automatiko.engine.workflow.process.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 (AutomatikoMessages.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 (AutomatikoMessages.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 (AutomatikoMessages.IterationLevel _level : _node.getContent().getForEach().getIterationLevelsList()) {
((ForEachNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
}
break;
case EVENT_SUBPROCESS_NODE:
for (AutomatikoMessages.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 (AutomatikoMessages.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 io.automatiko.engine.api.runtime.process.NodeInstanceContainer in project automatiko-engine by automatiko-io.
the class NodeInstanceImpl method getUniqueId.
public String getUniqueId() {
String result = "" + getId();
NodeInstanceContainer parent = getNodeInstanceContainer();
while (parent instanceof CompositeNodeInstance) {
CompositeNodeInstance nodeInstance = (CompositeNodeInstance) parent;
result = nodeInstance.getId() + ":" + result;
parent = nodeInstance.getNodeInstanceContainer();
}
return result;
}
use of io.automatiko.engine.api.runtime.process.NodeInstanceContainer in project automatiko-engine by automatiko-io.
the class JoinInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("An ActionNode only accepts default incoming connections!");
}
triggerTime = new Date();
final Join join = getJoin();
switch(join.getType()) {
case Join.TYPE_XOR:
triggerCompleted();
break;
case Join.TYPE_AND:
Integer count = (Integer) this.triggers.get(from.getNodeId());
if (count == null) {
this.triggers.put(from.getNodeId(), 1);
} else {
this.triggers.put(from.getNodeId(), count.intValue() + 1);
}
if (checkAllActivated()) {
decreaseAllTriggers();
triggerCompleted();
}
break;
case Join.TYPE_DISCRIMINATOR:
boolean triggerCompleted = triggers.isEmpty();
triggers.put(from.getNodeId(), new Integer(1));
if (checkAllActivated()) {
resetAllTriggers();
}
if (triggerCompleted) {
triggerCompleted();
}
break;
case Join.TYPE_N_OF_M:
count = (Integer) this.triggers.get(from.getNodeId());
if (count == null) {
this.triggers.put(from.getNodeId(), 1);
} else {
this.triggers.put(from.getNodeId(), count.intValue() + 1);
}
int counter = 0;
for (final Connection connection : getJoin().getDefaultIncomingConnections()) {
if (this.triggers.get(connection.getFrom().getId()) != null) {
counter++;
}
}
String n = join.getN();
Integer number = null;
if (n.startsWith("#{") && n.endsWith("}")) {
n = n.substring(2, n.length() - 1);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, n);
if (variableScopeInstance == null) {
throw new IllegalArgumentException("Could not find variable " + n + " when executing join.");
}
Object value = variableScopeInstance.getVariable(n);
if (value instanceof Number) {
number = ((Number) value).intValue();
} else {
throw new IllegalArgumentException("Variable " + n + " did not return a number when executing join: " + value);
}
} else {
number = Integer.parseInt(n);
}
if (counter >= number) {
resetAllTriggers();
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
cancelRemainingDirectFlows(nodeInstanceContainer, getJoin());
triggerCompleted();
}
break;
case Join.TYPE_OR:
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
boolean activePathExists = existsActiveDirectFlow(nodeInstanceContainer, getJoin());
if (!activePathExists) {
triggerCompleted();
}
break;
default:
throw new IllegalArgumentException("Illegal join type " + join.getType());
}
}
Aggregations