Search in sources :

Example 1 with ParameterDefinitionImpl

use of io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowFactory method serviceNode.

public WorkItemNode serviceNode(long id, Action action, FunctionDefinition function, NodeContainer nodeContainer) {
    String actionName = action.getName();
    String[] operationParts = function.getOperation().split("#");
    String interfaceStr = operationParts[0];
    String operationStr = operationParts[1];
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setId(id);
    workItemNode.setName(actionName);
    workItemNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
    workItemNode.setMetaData("Type", SERVICE_TASK_TYPE);
    workItemNode.setMetaData("Implementation", "##WebService");
    Work work = new WorkImpl();
    workItemNode.setWork(work);
    work.setName(SERVICE_TASK_TYPE);
    work.setParameter("Interface", interfaceStr);
    work.setParameter("Operation", operationStr);
    work.setParameter("interfaceImplementationRef", interfaceStr);
    work.setParameter("implementation", "##WebService");
    JsonNode params = action.getFunctionRef().getArguments();
    String inputFilter = null;
    String outputFilter = null;
    String scopeFilter = null;
    if (action.getActionDataFilter() != null) {
        inputFilter = unwrapExpression(action.getActionDataFilter().getFromStateData());
        outputFilter = unwrapExpression(action.getActionDataFilter().getResults());
        scopeFilter = unwrapExpression(action.getActionDataFilter().getToStateData());
    }
    Set<String> paramNames = new LinkedHashSet<>();
    if (params != null) {
        Iterator<String> it = params.fieldNames();
        while (it.hasNext()) {
            String name = it.next();
            String value = params.get(name).toString();
            work.setParameter(name, unwrapExpression(value));
            paramNames.add(name);
            work.addParameterDefinition(new ParameterDefinitionImpl(name, new JsonNodeDataType()));
        }
    } else {
        work.setParameter("ParameterType", JSON_NODE);
    }
    Assignment assignment = new Assignment("jq", null, null);
    assignment.setMetaData("Action", new TaskInputJqAssignmentAction(inputFilter, paramNames));
    workItemNode.addInAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(assignment), null));
    Assignment outAssignment = new Assignment("jq", null, null);
    outAssignment.setMetaData("Action", new TaskOutputJqAssignmentAction(outputFilter, scopeFilter));
    workItemNode.addOutAssociation(new DataAssociation(Collections.emptyList(), "", Arrays.asList(outAssignment), null));
    nodeContainer.addNode(workItemNode);
    return workItemNode;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) JsonNodeDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType) TaskInputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) TaskOutputJqAssignmentAction(io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Work(io.automatiko.engine.workflow.base.core.Work) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl)

Example 2 with ParameterDefinitionImpl

use of io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl in project automatiko-engine by automatiko-io.

the class WorkItemTest method getWorkItemProcess.

private ExecutableProcess getWorkItemProcess(String processId, String workName) {
    ExecutableProcess process = new ExecutableProcess();
    process.setId(processId);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("UserName");
    variable.setType(new StringDataType());
    variables.add(variable);
    variable = new Variable();
    variable.setName("Person");
    variable.setType(new ObjectDataType(Person.class));
    variables.add(variable);
    variable = new Variable();
    variable.setName("MyObject");
    variable.setType(new ObjectDataType());
    variables.add(variable);
    variable = new Variable();
    variable.setName("Number");
    variable.setType(new IntegerDataType());
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setName("workItemNode");
    workItemNode.setId(2);
    workItemNode.addInMapping("Comment", "Person.name");
    workItemNode.addInMapping("Attachment", "MyObject");
    workItemNode.addOutMapping("Result", "MyObject");
    workItemNode.addOutMapping("Result.length()", "Number");
    Work work = new WorkImpl();
    work.setName(workName);
    Set<ParameterDefinition> parameterDefinitions = new HashSet<ParameterDefinition>();
    ParameterDefinition parameterDefinition = new ParameterDefinitionImpl("ActorId", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Content", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Comment", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    work.setParameterDefinitions(parameterDefinitions);
    work.setParameter("ActorId", "#{UserName}");
    work.setParameter("Content", "#{Person.name}");
    workItemNode.setWork(work);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    connect(startNode, workItemNode);
    connect(workItemNode, endNode);
    process.addNode(startNode);
    process.addNode(workItemNode);
    process.addNode(endNode);
    return process;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Work(io.automatiko.engine.workflow.base.core.Work) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Person(io.automatiko.engine.workflow.process.test.Person) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition) HashSet(java.util.HashSet)

Example 3 with ParameterDefinitionImpl

use of io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl in project automatiko-engine by automatiko-io.

the class ParameterHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String name = attrs.getValue("name");
    emptyAttributeCheck(localName, "name", name, parser);
    Work work = (Work) parser.getParent();
    ParameterDefinition parameterDefinition = new ParameterDefinitionImpl();
    parameterDefinition.setName(name);
    work.addParameterDefinition(parameterDefinition);
    return new ParameterWrapper(parameterDefinition, work);
}
Also used : Work(io.automatiko.engine.workflow.base.core.Work) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition)

Example 4 with ParameterDefinitionImpl

use of io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl in project automatiko-engine by automatiko-io.

the class TaskHandler method handleNode.

protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
    dataTypeInputs.clear();
    dataTypeOutputs.clear();
    WorkItemNode workItemNode = (WorkItemNode) node;
    String name = getTaskName(element);
    Work work = new WorkImpl();
    work.setName(name);
    workItemNode.setWork(work);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("ioSpecification".equals(nodeName)) {
            readIoSpecification(xmlNode, dataInputs, dataOutputs, dataInputTypes);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readDataInputAssociation(xmlNode, workItemNode, dataInputs);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, workItemNode, dataOutputs);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    workItemNode.setMetaData("DataInputs", new LinkedHashMap<String, String>(dataTypeInputs));
    workItemNode.setMetaData("DataOutputs", new LinkedHashMap<String, String>(dataTypeOutputs));
    handleScript(workItemNode, element, "onEntry");
    handleScript(workItemNode, element, "onExit");
    String compensation = element.getAttribute("isForCompensation");
    if (compensation != null) {
        boolean isForCompensation = Boolean.parseBoolean(compensation);
        if (isForCompensation) {
            workItemNode.setMetaData("isForCompensation", isForCompensation);
        }
    }
    for (Entry<String, String> entryInputTypes : dataTypeInputs.entrySet()) {
        ParameterDefinition parameterDefinition = new ParameterDefinitionImpl();
        parameterDefinition.setName(entryInputTypes.getKey());
        parameterDefinition.setType(new ObjectDataType(constructClass(entryInputTypes.getValue()), entryInputTypes.getValue()));
        work.addParameterDefinition(parameterDefinition);
    }
}
Also used : ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Work(io.automatiko.engine.workflow.base.core.Work) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition)

Example 5 with ParameterDefinitionImpl

use of io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl in project automatiko-engine by automatiko-io.

the class WorkItemNodeFactory method workParameterDefinition.

public WorkItemNodeFactory workParameterDefinition(String name, DataType dataType) {
    Work work = getWorkItemNode().getWork();
    if (work == null) {
        work = new WorkImpl();
        getWorkItemNode().setWork(work);
    }
    Set<ParameterDefinition> parameterDefinitions = work.getParameterDefinitions();
    parameterDefinitions.add(new ParameterDefinitionImpl(name, dataType));
    work.setParameterDefinitions(parameterDefinitions);
    return this;
}
Also used : Work(io.automatiko.engine.workflow.base.core.Work) WorkImpl(io.automatiko.engine.workflow.base.core.impl.WorkImpl) ParameterDefinitionImpl(io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl) ParameterDefinition(io.automatiko.engine.workflow.base.core.ParameterDefinition)

Aggregations

Work (io.automatiko.engine.workflow.base.core.Work)5 ParameterDefinitionImpl (io.automatiko.engine.workflow.base.core.impl.ParameterDefinitionImpl)5 ParameterDefinition (io.automatiko.engine.workflow.base.core.ParameterDefinition)4 WorkImpl (io.automatiko.engine.workflow.base.core.impl.WorkImpl)4 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)3 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1 IntegerDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType)1 JsonNodeDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.JsonNodeDataType)1 StringDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType)1 TaskInputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.TaskInputJqAssignmentAction)1 TaskOutputJqAssignmentAction (io.automatiko.engine.workflow.base.instance.impl.jq.TaskOutputJqAssignmentAction)1 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)1 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)1 Assignment (io.automatiko.engine.workflow.process.core.node.Assignment)1 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)1 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)1 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)1 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)1