use of io.automatiko.engine.workflow.base.core.Context in project automatiko-engine by automatiko-io.
the class AbstractProtobufProcessInstanceMarshaller method readProcessInstance.
// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
AutomatikoMessages.ProcessInstance _instance = (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance) context.parameterObject;
if (_instance == null) {
// try to parse from the stream
ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null);
Header _header;
try {
_header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry);
} catch (ClassNotFoundException e) {
// Java 5 does not accept [new IOException(String, Throwable)]
IOException ioe = new IOException("Error deserializing process instance.");
ioe.initCause(e);
throw ioe;
}
_instance = AutomatikoMessages.ProcessInstance.parseFrom(_header.getPayload(), registry);
}
WorkflowProcessInstanceImpl processInstance = createProcessInstance();
processInstance.setId(_instance.getId());
String processId = _instance.getProcessId();
processInstance.setProcessId(processId);
String processXml = _instance.getProcessXml();
Process process = null;
if (processXml != null && processXml.trim().length() > 0) {
processInstance.setProcessXml(processXml);
process = processInstance.getProcess();
} else {
process = context.processes.get(processId);
if (process == null) {
throw new RuntimeException("Could not find process " + processId + " when restoring process instance " + processInstance.getId());
}
processInstance.setProcess(process);
}
processInstance.setDescription(_instance.getDescription());
processInstance.internalSetState(_instance.getState());
processInstance.setParentProcessInstanceId(_instance.getParentProcessInstanceId());
processInstance.setRootProcessInstanceId(_instance.getRootProcessInstanceId());
processInstance.setRootProcessId(_instance.getRootProcessId());
processInstance.setSignalCompletion(_instance.getSignalCompletion());
processInstance.setInitiator(_instance.getInitiator());
processInstance.setCorrelationKey(_instance.getCorrelationKey());
processInstance.setStartDate(new Date(_instance.getStartDate()));
processInstance.internalSetSlaCompliance(_instance.getSlaCompliance());
if (_instance.getSlaDueDate() > 0) {
processInstance.internalSetSlaDueDate(new Date(_instance.getSlaDueDate()));
}
processInstance.internalSetSlaTimerId(_instance.getSlaTimerId());
processInstance.setProcessRuntime(context.getProcessRuntime());
List<ExecutionsErrorInfo> errors = new ArrayList<>();
for (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance.Error error : _instance.getErrorsList()) {
errors.add(new ExecutionsErrorInfo(error.getErrorNodeId(), error.getErrorId(), error.getErrorMessage(), error.getErrorDetails()));
}
processInstance.internalSetExecutionErrors(errors);
processInstance.setReferenceId(_instance.getReferenceId());
processInstance.internalSetReferenceFromRoot(_instance.getReferenceFromRoot());
for (String completedNodeId : _instance.getCompletedNodeIdsList()) {
processInstance.addCompletedNodeId(completedNodeId);
}
if (_instance.getChildrenCount() > 0) {
_instance.getChildrenList().forEach(child -> processInstance.addChildren(child.getProcessId(), child.getIdsList()));
}
if (_instance.getTagsCount() > 0) {
_instance.getTagsList().forEach(tag -> processInstance.internalAddTag(tag.getId(), tag.getValue()));
}
if (_instance.getSwimlaneContextCount() > 0) {
Context swimlaneContext = ((io.automatiko.engine.workflow.base.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
for (AutomatikoMessages.ProcessInstance.SwimlaneContextInstance _swimlane : _instance.getSwimlaneContextList()) {
swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
}
}
for (AutomatikoMessages.ProcessInstance.NodeInstance _node : _instance.getNodeInstanceList()) {
context.parameterObject = _node;
readNodeInstance(context, processInstance, processInstance);
}
if (processInstance.getState() == ProcessInstance.STATE_ACTIVE || processInstance.getState() == ProcessInstance.STATE_ERROR) {
for (AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance _excl : _instance.getExclusiveGroupList()) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
for (String nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
NodeInstance nodeInstance = ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) processInstance).getNodeInstance(nodeInstanceId, true);
if (nodeInstance == null) {
throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
}
exclusiveGroupInstance.addNodeInstance(nodeInstance);
}
}
}
readVariableScope(context, process, processInstance, _instance);
if (_instance.getIterationLevelsCount() > 0) {
for (AutomatikoMessages.IterationLevel _level : _instance.getIterationLevelsList()) {
processInstance.getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
return processInstance;
}
use of io.automatiko.engine.workflow.base.core.Context 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.workflow.base.core.Context in project automatiko-engine by automatiko-io.
the class CompositeContextNodeInstance method getContextInstance.
public ContextInstance getContextInstance(String contextId) {
ContextInstance contextInstance = this.contextInstances.get(contextId);
if (contextInstance != null) {
return contextInstance;
}
Context context = getCompositeContextNode().getDefaultContext(contextId);
if (context != null) {
contextInstance = getContextInstance(context);
return contextInstance;
}
return null;
}
use of io.automatiko.engine.workflow.base.core.Context in project automatiko-engine by automatiko-io.
the class NodeInstanceImpl method resolveContextInstance.
public ContextInstance resolveContextInstance(String contextId, Object param) {
Context context = resolveContext(contextId, param);
if (context == null) {
return null;
}
ContextInstanceContainer contextInstanceContainer = getContextInstanceContainer(context.getContextContainer());
if (contextInstanceContainer == null) {
throw new IllegalArgumentException("Could not find context instance container for context");
}
return contextInstanceContainer.getContextInstance(context);
}
use of io.automatiko.engine.workflow.base.core.Context in project automatiko-engine by automatiko-io.
the class ProcessInstanceImpl method getContextInstance.
public ContextInstance getContextInstance(String contextId) {
ContextInstance contextInstance = this.contextInstances.get(contextId);
if (contextInstance != null) {
return contextInstance;
}
Context context = ((ContextContainer) getProcess()).getDefaultContext(contextId);
if (context != null) {
contextInstance = getContextInstance(context);
return contextInstance;
}
return null;
}
Aggregations