Search in sources :

Example 16 with WorkflowProcessInstance

use of io.automatiko.engine.api.runtime.process.WorkflowProcessInstance in project automatiko-engine by automatiko-io.

the class ProcessInstanceEventBatch method create.

protected ProcessInstanceEventBody create(ProcessEvent event) {
    WorkflowProcessInstance pi = (WorkflowProcessInstance) event.getProcessInstance();
    ProcessInstanceEventBody.Builder eventBuilder = ProcessInstanceEventBody.create().id(pi.getId()).parentInstanceId(pi.getParentProcessInstanceId()).rootInstanceId(pi.getRootProcessInstanceId()).processId(pi.getProcessId()).rootProcessId(pi.getRootProcessId()).processName(pi.getProcessName()).startDate(pi.getStartDate()).endDate(pi.getEndDate()).state(pi.getState()).businessKey(pi.getCorrelationKey()).variables(pi.getPublicVariables()).milestones(createMilestones(pi));
    if (pi.getState() == ProcessInstance.STATE_ERROR) {
        for (ExecutionsErrorInfo error : pi.errors()) {
            eventBuilder.error(ProcessErrorEventBody.create().nodeDefinitionId(error.getFailedNodeId()).errorMessage(error.getErrorMessage()).build());
        }
    }
    String securityRoles = (String) pi.getProcess().getMetaData().get("securityRoles");
    if (securityRoles != null) {
        eventBuilder.roles(securityRoles.split(","));
    }
    Collection<Tag> tags = pi.getTags();
    if (tags != null) {
        eventBuilder.tags(tags.stream().map(t -> t.getValue()).toArray(String[]::new));
    }
    io.automatiko.engine.api.workflow.ProcessInstance<?> instance = (io.automatiko.engine.api.workflow.ProcessInstance<?>) pi.getMetaData("AutomatikProcessInstance");
    if (instance != null) {
        Set<String> visibleTo = instance.process().accessPolicy().visibleTo(instance);
        if (visibleTo != null) {
            eventBuilder.visibleTo(visibleTo.toArray(String[]::new));
        }
        eventBuilder.instance(instance);
    }
    return eventBuilder.build();
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) Tag(io.automatiko.engine.api.workflow.Tag) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Example 17 with WorkflowProcessInstance

use of io.automatiko.engine.api.runtime.process.WorkflowProcessInstance in project automatiko-engine by automatiko-io.

the class DatabaseProcessInstances method unmarshallInstance.

@SuppressWarnings("unchecked")
protected ProcessInstance<ProcessInstanceEntity> unmarshallInstance(ProcessInstanceReadMode mode, ProcessInstanceEntity entity) {
    ProcessInstance<ProcessInstanceEntity> pi;
    if (mode == MUTABLE) {
        WorkflowProcessInstance wpi = marshaller.unmarshallWorkflowProcessInstance(codec.decode(entity.content), process);
        entity.toMap().forEach((k, v) -> {
            if (v != null) {
                v.toString();
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ProcessInstanceImpl) wpi).getContextInstance(VariableScope.VARIABLE_SCOPE);
                variableScopeInstance.internalSetVariable(k, v);
            }
        });
        pi = ((AbstractProcess<ProcessInstanceEntity>) process).createInstance(wpi, entity, entity.version);
    } else {
        WorkflowProcessInstance wpi = marshaller.unmarshallWorkflowProcessInstance(codec.decode(entity.content), process);
        entity.toMap().forEach((k, v) -> {
            if (v != null) {
                v.toString();
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ProcessInstanceImpl) wpi).getContextInstance(VariableScope.VARIABLE_SCOPE);
                variableScopeInstance.internalSetVariable(k, v);
            }
        });
        pi = ((AbstractProcess<ProcessInstanceEntity>) process).createReadOnlyInstance(wpi, entity);
    }
    return pi;
}
Also used : ProcessInstanceEntity(io.automatiko.engine.addons.persistence.db.model.ProcessInstanceEntity) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Example 18 with WorkflowProcessInstance

use of io.automatiko.engine.api.runtime.process.WorkflowProcessInstance in project automatiko-engine by automatiko-io.

the class JbpmBpmn2TestCase method assertNodeActive.

public void assertNodeActive(String processInstanceId, InternalProcessRuntime processRuntime, String... name) {
    List<String> names = new ArrayList<String>();
    for (String n : name) {
        names.add(n);
    }
    ProcessInstance processInstance = processRuntime.getProcessInstance(processInstanceId);
    if (processInstance instanceof WorkflowProcessInstance) {
        assertNodeActive((WorkflowProcessInstance) processInstance, names);
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Node(s) not active: " + s);
    }
}
Also used : ArrayList(java.util.ArrayList) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Aggregations

WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)18 Model (io.automatiko.engine.api.Model)5 AbstractProcess (io.automatiko.engine.workflow.AbstractProcess)5 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)5 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)5 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)3 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)3 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)3 NodeInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl)3 TimerNodeInstance (io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 ProcessInstanceEntity (io.automatiko.engine.addons.persistence.db.model.ProcessInstanceEntity)2 Process (io.automatiko.engine.api.definition.process.Process)2 Process (io.automatiko.engine.api.workflow.Process)2 StringExportedProcessInstance (io.automatiko.engine.workflow.StringExportedProcessInstance)2 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)2