Search in sources :

Example 6 with Constraint

use of io.automatiko.engine.workflow.process.core.Constraint in project automatiko-engine by automatiko-io.

the class StateNodeInstance method signalEvent.

public void signalEvent(String type, Object event) {
    if ("signal".equals(type)) {
        if (event instanceof String) {
            for (Connection connection : getStateNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
                boolean selected = false;
                Constraint constraint = getStateNode().getConstraint(connection);
                if (constraint == null) {
                    if (((String) event).equals(connection.getTo().getName())) {
                        selected = true;
                    }
                } else if (((String) event).equals(constraint.getName())) {
                    selected = true;
                }
                if (selected) {
                    triggerEvent(ExtendedNodeImpl.EVENT_NODE_EXIT);
                    removeEventListeners();
                    ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
                    triggerConnection(connection);
                    return;
                }
            }
        }
    } else if ("variableChanged".equals(type)) {
        if (isCompleted()) {
            triggerCompleted();
        }
    } else {
        super.signalEvent(type, event);
    }
}
Also used : Constraint(io.automatiko.engine.workflow.process.core.Constraint) Connection(io.automatiko.engine.api.definition.process.Connection)

Example 7 with Constraint

use of io.automatiko.engine.workflow.process.core.Constraint in project automatiko-engine by automatiko-io.

the class SplitNodeVisitor method visitNode.

@Override
public void visitNode(WorkflowProcess process, String factoryField, Split node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    body.addStatement(getAssignedFactoryMethod(factoryField, SplitFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Split")).addStatement(getFactoryMethod(getNodeId(node), METHOD_TYPE, new IntegerLiteralExpr(node.getType())));
    visitMetaData(node.getMetaData(), body, getNodeId(node));
    if (node.getType() == Split.TYPE_OR || node.getType() == Split.TYPE_XOR) {
        for (Entry<ConnectionRef, Constraint> entry : node.getConstraints().entrySet()) {
            if (entry.getValue() != null) {
                String dialect = entry.getValue().getDialect();
                if ("jq".equals(dialect)) {
                    body.addStatement(getFactoryMethod(getNodeId(node), METHOD_CONSTRAINT, new LongLiteralExpr(entry.getKey().getNodeId()), new StringLiteralExpr(getOrDefault(entry.getKey().getConnectionId(), "")), new StringLiteralExpr(entry.getKey().getToType()), new StringLiteralExpr(entry.getValue().getDialect()), new StringLiteralExpr(entry.getValue().getConstraint()), new IntegerLiteralExpr(entry.getValue().getPriority())));
                } else {
                    BlockStmt actionBody = new BlockStmt();
                    LambdaExpr lambda = new // (kcontext) ->
                    LambdaExpr(// (kcontext) ->
                    new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
                    for (Variable v : variableScope.getVariables()) {
                        actionBody.addStatement(makeAssignment(v));
                    }
                    variableScope.getVariables().stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(ActionNodeVisitor::makeAssignmentVersions).forEach(actionBody::addStatement);
                    if (entry.getValue().getConstraint().contains(System.getProperty("line.separator"))) {
                        BlockStmt constraintBody = new BlockStmt();
                        constraintBody.addStatement(entry.getValue().getConstraint());
                        actionBody.addStatement(constraintBody);
                    } else {
                        actionBody.addStatement(new ReturnStmt(new EnclosedExpr(new NameExpr(entry.getValue().getConstraint()))));
                    }
                    body.addStatement(getFactoryMethod(getNodeId(node), METHOD_CONSTRAINT, new LongLiteralExpr(entry.getKey().getNodeId()), new StringLiteralExpr(getOrDefault(entry.getKey().getConnectionId(), "")), new StringLiteralExpr(entry.getKey().getToType()), new StringLiteralExpr(entry.getValue().getDialect()), lambda, new IntegerLiteralExpr(entry.getValue().getPriority())));
                }
            }
        }
    }
    body.addStatement(getDoneMethod(getNodeId(node)));
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Constraint(io.automatiko.engine.workflow.process.core.Constraint) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) SplitFactory(io.automatiko.engine.workflow.process.executable.core.factory.SplitFactory) UnknownType(com.github.javaparser.ast.type.UnknownType) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) Parameter(com.github.javaparser.ast.body.Parameter) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) ConnectionRef(io.automatiko.engine.workflow.process.core.impl.ConnectionRef) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt)

Example 8 with Constraint

use of io.automatiko.engine.workflow.process.core.Constraint in project automatiko-engine by automatiko-io.

the class SplitNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    Split splitNode = (Split) node;
    writeNode("split", splitNode, xmlDump, includeMeta);
    int type = splitNode.getType();
    if (type != 0) {
        xmlDump.append("type=\"" + type + "\" ");
    }
    if (splitNode.getConstraints().isEmpty()) {
        endNode(xmlDump);
    } else {
        xmlDump.append(">" + EOL);
        if (includeMeta) {
            writeMetaData(splitNode, xmlDump);
        }
        xmlDump.append("      <constraints>" + EOL);
        for (Map.Entry<ConnectionRef, Constraint> entry : splitNode.getConstraints().entrySet()) {
            ConnectionRef connection = entry.getKey();
            Constraint constraint = entry.getValue();
            xmlDump.append("        <constraint " + "toNodeId=\"" + connection.getNodeId() + "\" " + "toType=\"" + connection.getToType() + "\" ");
            String name = constraint.getName();
            if (name != null && !"".equals(name)) {
                xmlDump.append("name=\"" + XmlDumper.replaceIllegalChars(constraint.getName()) + "\" ");
            }
            int priority = constraint.getPriority();
            if (priority != 0) {
                xmlDump.append("priority=\"" + constraint.getPriority() + "\" ");
            }
            xmlDump.append("type=\"" + constraint.getType() + "\" ");
            String dialect = constraint.getDialect();
            if (dialect != null && !"".equals(dialect)) {
                xmlDump.append("dialect=\"" + dialect + "\" ");
            }
            String constraintString = constraint.getConstraint();
            if (constraintString != null) {
                xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</constraint>" + EOL);
            } else {
                xmlDump.append("/>" + EOL);
            }
        }
        xmlDump.append("      </constraints>" + EOL);
        endNode("split", xmlDump);
    }
}
Also used : Constraint(io.automatiko.engine.workflow.process.core.Constraint) Split(io.automatiko.engine.workflow.process.core.node.Split) Map(java.util.Map) ConnectionRef(io.automatiko.engine.workflow.process.core.impl.ConnectionRef) Constraint(io.automatiko.engine.workflow.process.core.Constraint)

Example 9 with Constraint

use of io.automatiko.engine.workflow.process.core.Constraint in project automatiko-engine by automatiko-io.

the class XmlBPMNProcessDumper method visitConnection.

public void visitConnection(Connection connection, StringBuilder xmlDump, int metaDataType) {
    // if the connection was generated by a link event, don't dump.
    if (isConnectionRepresentingLinkEvent(connection)) {
        return;
    }
    // if the connection is a hidden one (compensations), don't dump
    Object hidden = ((ConnectionImpl) connection).getMetaData("hidden");
    if (hidden != null && ((Boolean) hidden)) {
        return;
    }
    xmlDump.append("    <sequenceFlow id=\"" + getUniqueNodeId(connection.getFrom()) + "-" + getUniqueNodeId(connection.getTo()) + "\" sourceRef=\"" + getUniqueNodeId(connection.getFrom()) + "\" ");
    // TODO fromType, toType
    xmlDump.append("targetRef=\"" + getUniqueNodeId(connection.getTo()) + "\" ");
    if (metaDataType == META_DATA_AS_NODE_PROPERTY) {
        String bendpoints = (String) connection.getMetaData().get("bendpoints");
        if (bendpoints != null) {
            xmlDump.append("g:bendpoints=\"" + bendpoints + "\" ");
        }
    }
    if (connection.getFrom() instanceof Split) {
        Split split = (Split) connection.getFrom();
        if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
            Constraint constraint = split.getConstraint(connection);
            if (constraint == null) {
                xmlDump.append(">" + EOL + "      <conditionExpression xsi:type=\"tFormalExpression\" />");
            } else {
                if (constraint.getName() != null && constraint.getName().trim().length() > 0) {
                    xmlDump.append("name=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(constraint.getName()) + "\" ");
                }
                if (constraint.getPriority() != 0) {
                    xmlDump.append("tns:priority=\"" + constraint.getPriority() + "\" ");
                }
                xmlDump.append(">" + EOL + "      <conditionExpression xsi:type=\"tFormalExpression\" ");
                if ("code".equals(constraint.getType())) {
                    if ("java".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + JAVA_LANGUAGE + "\" ");
                    } else if ("XPath".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + XPATH_LANGUAGE + "\" ");
                    } else if ("JavaScript".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + JAVASCRIPT_LANGUAGE + "\" ");
                    } else if ("FEEL".equals(constraint.getDialect())) {
                        xmlDump.append("language=\"" + FEEL_LANGUAGE + "\" ");
                    }
                } else {
                    xmlDump.append("language=\"" + RULE_LANGUAGE + "\" ");
                }
                String constraintString = constraint.getConstraint();
                if (constraintString == null) {
                    constraintString = "";
                }
                xmlDump.append(">" + XmlDumper.replaceIllegalChars(constraintString) + "</conditionExpression>");
            }
            xmlDump.append(EOL + "    </sequenceFlow>" + EOL);
        } else {
            xmlDump.append("/>" + EOL);
        }
    } else {
        xmlDump.append("/>" + EOL);
    }
}
Also used : Constraint(io.automatiko.engine.workflow.process.core.Constraint) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) Split(io.automatiko.engine.workflow.process.core.node.Split)

Example 10 with Constraint

use of io.automatiko.engine.workflow.process.core.Constraint in project automatiko-engine by automatiko-io.

the class SplitHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    Split split = (Split) node;
    String type = null;
    switch(split.getType()) {
        case Split.TYPE_AND:
            type = "parallelGateway";
            writeNode(type, node, xmlDump, metaDataType);
            break;
        case Split.TYPE_XOR:
            type = "exclusiveGateway";
            writeNode(type, node, xmlDump, metaDataType);
            for (Map.Entry<ConnectionRef, Constraint> entry : split.getConstraints().entrySet()) {
                if (entry.getValue() != null && entry.getValue().isDefault()) {
                    xmlDump.append("default=\"" + XmlBPMNProcessDumper.getUniqueNodeId(split) + "-" + XmlBPMNProcessDumper.getUniqueNodeId(node.getParentContainer().getNode(entry.getKey().getNodeId())) + "\" ");
                    break;
                }
            }
            break;
        case Split.TYPE_OR:
            type = "inclusiveGateway";
            writeNode(type, node, xmlDump, metaDataType);
            for (Map.Entry<ConnectionRef, Constraint> entry : split.getConstraints().entrySet()) {
                if (entry.getValue() != null && entry.getValue().isDefault()) {
                    xmlDump.append("default=\"" + XmlBPMNProcessDumper.getUniqueNodeId(split) + "-" + XmlBPMNProcessDumper.getUniqueNodeId(node.getParentContainer().getNode(entry.getKey().getNodeId())) + "\" ");
                    break;
                }
            }
            break;
        case Split.TYPE_XAND:
            type = "eventBasedGateway";
            writeNode(type, node, xmlDump, metaDataType);
            break;
        default:
            type = "complexGateway";
            writeNode(type, node, xmlDump, metaDataType);
    }
    xmlDump.append("gatewayDirection=\"Diverging\" >" + EOL);
    writeExtensionElements(node, xmlDump);
    endNode(type, xmlDump);
}
Also used : Constraint(io.automatiko.engine.workflow.process.core.Constraint) Split(io.automatiko.engine.workflow.process.core.node.Split) Map(java.util.Map) ConnectionRef(io.automatiko.engine.workflow.process.core.impl.ConnectionRef)

Aggregations

Constraint (io.automatiko.engine.workflow.process.core.Constraint)10 ConnectionRef (io.automatiko.engine.workflow.process.core.impl.ConnectionRef)7 Split (io.automatiko.engine.workflow.process.core.node.Split)4 Map (java.util.Map)3 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)2 ConstraintImpl (io.automatiko.engine.workflow.process.core.impl.ConstraintImpl)2 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)2 Parameter (com.github.javaparser.ast.body.Parameter)1 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)1 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)1 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)1 LongLiteralExpr (com.github.javaparser.ast.expr.LongLiteralExpr)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)1 UnknownType (com.github.javaparser.ast.type.UnknownType)1 Connection (io.automatiko.engine.api.definition.process.Connection)1 Node (io.automatiko.engine.api.definition.process.Node)1 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1