Search in sources :

Example 1 with Header

use of io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header 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;
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) Process(io.automatiko.engine.api.definition.process.Process) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) Context(io.automatiko.engine.workflow.base.core.Context) SwimlaneContext(io.automatiko.engine.workflow.base.core.context.swimlane.SwimlaneContext) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) IOException(java.io.IOException) Date(java.util.Date) Header(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) StateNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateNodeInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) SubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) DynamicNodeInstance(io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Example 2 with Header

use of io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header in project automatiko-engine by automatiko-io.

the class ProtobufProcessMarshaller method readWorkItem.

@Override
public WorkItemImpl readWorkItem(MarshallerReaderContext context) {
    try {
        ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null);
        Header _header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry);
        AutomatikoMessages.WorkItem _workItem = AutomatikoMessages.WorkItem.parseFrom(_header.getPayload(), registry);
        return (WorkItemImpl) readWorkItem(context, _workItem, persistWorkItemVars);
    } catch (IOException e) {
        throw new IllegalArgumentException("IOException while fetching work item instance : " + e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("ClassNotFoundException while fetching work item instance : " + e.getMessage(), e);
    }
}
Also used : Header(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) IOException(java.io.IOException) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Aggregations

ExtensionRegistry (com.google.protobuf.ExtensionRegistry)2 Header (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header)2 IOException (java.io.IOException)2 Process (io.automatiko.engine.api.definition.process.Process)1 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)1 NodeInstanceContainer (io.automatiko.engine.api.runtime.process.NodeInstanceContainer)1 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)1 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 ExecutionsErrorInfo (io.automatiko.engine.api.workflow.ExecutionsErrorInfo)1 Context (io.automatiko.engine.workflow.base.core.Context)1 SwimlaneContext (io.automatiko.engine.workflow.base.core.context.swimlane.SwimlaneContext)1 ExclusiveGroupInstance (io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance)1 SwimlaneContextInstance (io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance)1 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)1 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)1 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)1 DynamicNodeInstance (io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance)1 EventNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)1 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)1 ForEachNodeInstance (io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance)1