Search in sources :

Example 16 with WorkflowProcess

use of io.automatiko.engine.api.definition.process.WorkflowProcess in project automatiko-engine by automatiko-io.

the class XmlBPMNProcessDumper method visitHeader.

protected void visitHeader(WorkflowProcess process, StringBuilder xmlDump, int metaDataType) {
    Map<String, Object> metaData = getMetaData(process.getMetaData());
    Set<String> imports = ((io.automatiko.engine.workflow.base.core.Process) process).getImports();
    Map<String, String> globals = ((io.automatiko.engine.workflow.base.core.Process) process).getGlobals();
    if ((imports != null && !imports.isEmpty()) || (globals != null && globals.size() > 0) || !metaData.isEmpty()) {
        xmlDump.append("    <extensionElements>" + EOL);
        if (imports != null) {
            for (String s : imports) {
                xmlDump.append("     <tns:import name=\"" + s + "\" />" + EOL);
            }
        }
        if (globals != null) {
            for (Map.Entry<String, String> global : globals.entrySet()) {
                xmlDump.append("     <tns:global identifier=\"" + global.getKey() + "\" type=\"" + global.getValue() + "\" />" + EOL);
            }
        }
        writeMetaData(getMetaData(process.getMetaData()), xmlDump);
        xmlDump.append("    </extensionElements>" + EOL);
    }
    // TODO: function imports
    // TODO: exception handlers
    VariableScope variableScope = (VariableScope) ((io.automatiko.engine.workflow.base.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    if (variableScope != null) {
        visitVariables(variableScope.getVariables(), xmlDump);
    }
    visitLanes(process, xmlDump);
}
Also used : Process(io.automatiko.engine.api.definition.process.Process) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Map(java.util.Map) HashMap(java.util.HashMap) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 17 with WorkflowProcess

use of io.automatiko.engine.api.definition.process.WorkflowProcess in project automatiko-engine by automatiko-io.

the class FileSystemProcessInstancesTest method testFindByIdReadMode.

@Test
void testFindByIdReadMode() {
    BpmnProcess process = createProcess(null, "BPMN2-UserTask-Script.bpmn2");
    // workaround as BpmnProcess does not compile the scripts but just reads the xml
    for (io.automatiko.engine.api.definition.process.Node node : ((WorkflowProcess) process.process()).getNodes()) {
        if (node instanceof ActionNode) {
            ProcessAction a = ((ActionNode) node).getAction();
            a.removeMetaData("Action");
            a.setMetaData("Action", new Action() {

                @Override
                public void execute(ProcessContext kcontext) throws Exception {
                    System.out.println("The variable value is " + kcontext.getVariable("s") + " about to call toString on it");
                    kcontext.getVariable("s").toString();
                }
            });
        }
    }
    ProcessInstance<BpmnVariables> mutablePi = process.createInstance(BpmnVariables.create(Collections.singletonMap("var", "value")));
    mutablePi.start();
    assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
    assertThat(mutablePi.errors()).hasValueSatisfying(errors -> {
        assertThat(errors.errorMessages()).contains("null");
        assertThat(errors.failedNodeIds()).isEqualTo("ScriptTask_1");
    });
    assertThat(mutablePi.variables().toMap()).containsExactly(entry("var", "value"));
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isOne();
    ProcessInstance<BpmnVariables> pi = instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.READ_ONLY).get();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
    ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.READ_ONLY).get();
    assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
    assertThat(readOnlyPi.errors()).hasValueSatisfying(errors -> {
        assertThat(errors.failedNodeIds()).isEqualTo("ScriptTask_1");
    });
    assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> readOnlyPi.abort());
    instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.MUTABLE).get().abort();
    assertThat(instances.size()).isZero();
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) IOException(java.io.IOException) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Aggregations

WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)17 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 Process (io.automatiko.engine.api.definition.process.Process)6 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)6 ModelMetaData (io.automatiko.engine.workflow.compiler.canonical.ModelMetaData)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Optional (java.util.Optional)5 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)4 IOException (java.io.IOException)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)3 Functions (io.automatiko.engine.api.Functions)3 Node (io.automatiko.engine.api.definition.process.Node)3 Resource (io.automatiko.engine.api.io.Resource)3 ResourceType (io.automatiko.engine.api.io.ResourceType)3 ResourceType.determineResourceType (io.automatiko.engine.api.io.ResourceType.determineResourceType)3