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);
}
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();
}
Aggregations