Search in sources :

Example 16 with ObjectDataType

use of io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType in project automatiko-engine by automatiko-io.

the class AbstractNodeHandler method getDataType.

protected DataType getDataType(String itemSubjectRef, Map<String, ItemDefinition> itemDefinitions, ClassLoader cl) {
    DataType dataType = new ObjectDataType();
    if (itemDefinitions == null) {
        return dataType;
    }
    ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
    if (itemDefinition != null) {
        String structureRef = itemDefinition.getStructureRef();
        if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
            dataType = new BooleanDataType();
        } else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
            dataType = new IntegerDataType();
        } else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
            dataType = new FloatDataType();
        } else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
            dataType = new StringDataType();
        } else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
            dataType = new ObjectDataType(constructClass(structureRef), structureRef);
        } else {
            dataType = new ObjectDataType(constructClass(structureRef, cl), structureRef);
        }
    }
    return dataType;
}
Also used : StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) DataType(io.automatiko.engine.api.workflow.datatype.DataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType)

Example 17 with ObjectDataType

use of io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowFactory method processVar.

public void processVar(String varName, Class<?> varType, ExecutableProcess process) {
    Variable variable = new Variable();
    variable.setName(varName);
    variable.setType(new ObjectDataType(varType));
    process.getVariableScope().getVariables().add(variable);
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)

Example 18 with ObjectDataType

use of io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType in project automatiko-engine by automatiko-io.

the class CompensationTest method createNestedCompensationBoundaryEventProcess.

private ExecutableProcess createNestedCompensationBoundaryEventProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setAutoComplete(true);
    process.setId(processId);
    process.setName("CESP Process");
    process.setMetaData("Compensation", true);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType(java.lang.String.class);
    variable.setType(personDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
    // process level
    CompositeContextNode compositeNode = compNodeCreator.createNode("sub0");
    {
        StartNode startNode = startNodeCreator.createNode("start0");
        connect(startNode, compositeNode);
        EndNode endNode = endNodeCreator.createNode("end0");
        connect(compositeNode, endNode);
    }
    // 1rst level nested subprocess (contains compensation visibility scope)
    {
        startNodeCreator.setNodeContainer(compositeNode);
        compNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start1");
        CompositeContextNode subCompNode = compNodeCreator.createNode("sub1");
        connect(startNode, subCompNode);
        EndNode endNode = endNodeCreator.createNode("end1");
        connect(subCompNode, endNode);
        compositeNode = subCompNode;
    }
    // 2nd level nested subprocess (contains compensation visibility scope)
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(compositeNode, WorkItemNode.class);
    {
        startNodeCreator.setNodeContainer(compositeNode);
        compNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start2");
        CompositeContextNode subCompNode = compNodeCreator.createNode("sub2");
        connect(startNode, subCompNode);
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work2");
        workItemNode.getWork().setName(workItemNames[2]);
        connect(subCompNode, workItemNode);
        EndNode endNode = endNodeCreator.createNode("end2");
        connect(workItemNode, endNode);
        createBoundaryEventCompensationHandler(compositeNode, workItemNode, eventList, "2");
        compositeNode = subCompNode;
    }
    // Fill 3rd level with process with compensation
    {
        startNodeCreator.setNodeContainer(compositeNode);
        workItemNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start");
        Node lastNode = startNode;
        WorkItemNode[] workItemNodes = new WorkItemNode[3];
        for (int i = 0; i < 2; ++i) {
            workItemNodes[i] = workItemNodeCreator.createNode("work-comp-" + (i + 1));
            workItemNodes[i].getWork().setName(workItemNames[i]);
            connect(lastNode, workItemNodes[i]);
            lastNode = workItemNodes[i];
        }
        EndNode endNode = endNodeCreator.createNode("end");
        connect(workItemNodes[1], endNode);
        // Compensation (boundary event) handlers
        for (int i = 0; i < 2; ++i) {
            createBoundaryEventCompensationHandler(compositeNode, workItemNodes[i], eventList, "" + i + 1);
        }
    }
    return process;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Node(io.automatiko.engine.workflow.process.core.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeCreator(io.automatiko.engine.workflow.process.test.NodeCreator) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Example 19 with ObjectDataType

use of io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType in project automatiko-engine by automatiko-io.

the class FactoryTest method test.

@Test
public void test() {
    ExecutableProcessFactory factory = ExecutableProcessFactory.createProcess("ExampleProcess");
    factory.variable("x", new ObjectDataType(java.lang.String.class));
    factory.variable("y", new ObjectDataType(java.lang.String.class));
    factory.variable("list", new ObjectDataType(java.util.List.class, "java.util.List<String>"));
    factory.variable("listOut", new ObjectDataType(java.util.List.class, "java.util.List<String>"));
    factory.name("Example Process");
    factory.packageName("org.company.bpmn2");
    factory.dynamic(false);
    factory.version("1.0");
    factory.visibility("Private");
    factory.metaData("TargetNamespace", "http://www.example.org/MinimalExample");
    factory.startNode(1).name("StartProcess").done();
    factory.dynamicNode(2).metaData("UniqueId", "_2").metaData("MICollectionOutput", "_2_listOutOutput").metaData("x", 96).metaData("y", 16).activationExpression(kcontext -> Objects.equals(kcontext.getVariable("x"), kcontext.getVariable("oldValue"))).variable("x", new ObjectDataType(java.lang.String.class)).exceptionHandler(RuntimeException.class.getName(), "java", "System.out.println(\"Error\");").autoComplete(true).language("java").done();
    factory.humanTaskNode(3).name("Task").taskName("Task Name").actorId("Actor").comment("Hey").content("Some content").workParameter("x", "Parameter").inMapping("x", "y").outMapping("y", "x").waitForCompletion(true).timer("1s", null, "java", "").onEntryAction("java", "").onExitAction("java", "").done();
    factory.faultNode(4).name("Fault").faultName("Fault Name").faultVariable("x").done();
    factory.connection(1, 2, "_1-_2").connection(2, 3, "_2-_3").connection(3, 4, "_3-_4");
    factory.validate();
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "oldValue");
    parameters.put("list", list);
    InternalProcessRuntime ksession = createProcessRuntime(factory.getProcess());
    ksession.startProcess("ExampleProcess", parameters);
}
Also used : Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) List(java.util.List) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) List(java.util.List) ArrayList(java.util.ArrayList) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 20 with ObjectDataType

use of io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType in project automatiko-engine by automatiko-io.

the class ForEachTest method test.

@Test
public void test() {
    ExecutableProcessFactory factory = ExecutableProcessFactory.createProcess("ParentProcess");
    factory.variable("x", new ObjectDataType(java.lang.String.class));
    factory.variable("y", new ObjectDataType(java.lang.String.class));
    factory.variable("list", new ObjectDataType(java.util.List.class, "java.util.List<String>"));
    factory.variable("listOut", new ObjectDataType(java.util.List.class, "java.util.List<String>"));
    factory.name("Parent Process");
    factory.packageName("org.company.bpmn2");
    factory.dynamic(false);
    factory.version("1.0");
    factory.visibility("Private");
    factory.metaData("TargetNamespace", "http://www.example.org/MinimalExample");
    io.automatiko.engine.workflow.process.executable.core.factory.StartNodeFactory startNode1 = factory.startNode(1);
    startNode1.name("StartProcess");
    startNode1.done();
    io.automatiko.engine.workflow.process.executable.core.factory.ForEachNodeFactory forEachNode2 = factory.forEachNode(2);
    forEachNode2.metaData("UniqueId", "_2");
    forEachNode2.metaData("MICollectionOutput", "_2_listOutOutput");
    forEachNode2.metaData("x", 96);
    forEachNode2.metaData("width", 110);
    forEachNode2.metaData("y", 16);
    forEachNode2.metaData("MICollectionInput", "_2_input");
    forEachNode2.metaData("height", 48);
    forEachNode2.collectionExpression("list");
    forEachNode2.variable("x", new ObjectDataType(java.lang.String.class));
    forEachNode2.outputCollectionExpression("listOut");
    forEachNode2.outputVariable("y", new ObjectDataType(java.lang.String.class));
    forEachNode2.actionNode(5).action((kcontext) -> System.out.println(kcontext.getVariable("x"))).done();
    forEachNode2.linkIncomingConnections(5);
    forEachNode2.linkOutgoingConnections(5);
    forEachNode2.done();
    io.automatiko.engine.workflow.process.executable.core.factory.EndNodeFactory endNode3 = factory.endNode(3);
    endNode3.name("EndProcess");
    endNode3.terminate(true);
    endNode3.done();
    factory.connection(1, 2, "_1-_2");
    factory.connection(2, 3, "_2-_3");
    factory.validate();
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "oldValue");
    parameters.put("list", list);
    parameters.put("listOut", listOut);
    InternalProcessRuntime ksession = createProcessRuntime(factory.getProcess());
    ksession.startProcess("ParentProcess", parameters);
}
Also used : Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) List(java.util.List) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) List(java.util.List) ArrayList(java.util.ArrayList) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Aggregations

ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)24 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)11 ArrayList (java.util.ArrayList)8 Map (java.util.Map)7 Test (org.junit.jupiter.api.Test)7 DataType (io.automatiko.engine.api.workflow.datatype.DataType)5 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)5 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)5 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)4 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)4 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)4 HashMap (java.util.HashMap)4 List (java.util.List)4 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)3 NameExpr (com.github.javaparser.ast.expr.NameExpr)3 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)3 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)3 Work (io.automatiko.engine.workflow.base.core.Work)3 BooleanDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType)3 IntegerDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType)3