Search in sources :

Example 86 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project carbon-business-process by wso2.

the class HumanTaskServerConfiguration method iniTaskCleanupConfig.

private void iniTaskCleanupConfig(TTaskCleanupConfig taskCleanupConfig) {
    if (taskCleanupConfig != null) {
        if (StringUtils.isNotEmpty(taskCleanupConfig.getCronExpression())) {
            if (CronExpression.isValidExpression(taskCleanupConfig.getCronExpression().trim())) {
                this.taskCleanupCronExpression = taskCleanupConfig.getCronExpression();
            } else {
                String warnMsg = String.format("The task clean up cron expression[%s] is invalid." + " Ignoring task clean up configurations! ", taskCleanupConfig.getCronExpression());
                log.warn(warnMsg);
                return;
            }
        }
        if (StringUtils.isNotEmpty(taskCleanupConfig.getStatuses())) {
            String[] removableStatusesArray = taskCleanupConfig.getStatuses().split(",");
            List<TaskStatus> removableTaskStatusList = new ArrayList<TaskStatus>();
            for (String removableStatus : removableStatusesArray) {
                for (TaskStatus taskStatusEnum : TaskStatus.values()) {
                    if (taskStatusEnum.toString().equals(removableStatus.trim())) {
                        removableTaskStatusList.add(taskStatusEnum);
                        break;
                    }
                }
            }
            this.removableTaskStatuses = removableTaskStatusList;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TaskStatus(org.wso2.carbon.humantask.core.dao.TaskStatus)

Example 87 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project carbon-business-process by wso2.

the class ExpressionBasedOrgEntityProvider method getOrganizationalEntities.

public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) {
    String expression = tFrom.newCursor().getTextValue().trim();
    log.debug("Evaluating expression " + expression + " for ExpressionBasedOrgEntityProvider");
    String expLang = (tFrom.getExpressionLanguage() == null) ? HumanTaskConstants.WSHT_EXP_LANG_XPATH20 : tFrom.getExpressionLanguage();
    ExpressionLanguageRuntime expLangRuntime = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getExpressionLanguageRuntime(expLang);
    List list = expLangRuntime.evaluate(expression, evaluationContext);
    List<OrganizationalEntityDAO> orgEntityList = new ArrayList<OrganizationalEntityDAO>();
    if (list.isEmpty() || list.size() > 1) {
        log.debug(" Organizational Entities evaluated to null or multiple list");
        return orgEntityList;
    }
    // Returned list should evaluate to an organizationalEntity or a user
    for (Object item : list) {
        if (item instanceof NodeList) {
            for (int i = 0; i < ((NodeList) item).getLength(); i++) {
                Node node = ((NodeList) item).item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    if (node.getLocalName().equals(HumanTaskConstants.userQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.userQname.getNamespaceURI())) {
                        CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals(HumanTaskConstants.groupQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.groupQname.getNamespaceURI())) {
                        CommonTaskUtil.addOrgEntityForGroupNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals("wrapper")) {
                        // Expression evaluator wraps the string with wrapper element name
                        CommonTaskUtil.addOrgEntityForUserNode(node, peopleQueryEvaluator, orgEntityList);
                    } else if (node.getLocalName().equals(HumanTaskConstants.organizationalEntityQname.getLocalPart()) && node.getNamespaceURI().equals(HumanTaskConstants.organizationalEntityQname.getNamespaceURI())) {
                        // This is an organizational Entity node, hence parse it as org entity
                        // Most probably this logic wont be required
                        CommonTaskUtil.addOrgEntitiesForOrganizationEntityNode(node, peopleQueryEvaluator, orgEntityList);
                    }
                } else if (node.getNodeType() == Node.TEXT_NODE) {
                    String nodeValue = node.getNodeValue().trim();
                    if (nodeValue.length() > 0) {
                        OrganizationalEntityDAO userOrgEntityForName = peopleQueryEvaluator.createUserOrgEntityForName(nodeValue);
                        if (userOrgEntityForName != null) {
                            orgEntityList.add(userOrgEntityForName);
                        }
                    }
                }
            }
        }
    }
    return orgEntityList;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionLanguageRuntime(org.wso2.carbon.humantask.core.engine.runtime.api.ExpressionLanguageRuntime)

Example 88 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.

the class TypeChecker method checkFunctionInvocationExpr.

private void checkFunctionInvocationExpr(BLangInvocation iExpr) {
    Name funcName = names.fromIdNode(iExpr.name);
    Name pkgAlias = names.fromIdNode(iExpr.pkgAlias);
    BSymbol funcSymbol = symResolver.lookupSymbolInPackage(iExpr.pos, env, pkgAlias, funcName, SymTag.VARIABLE);
    if (funcSymbol == symTable.notFoundSymbol || funcSymbol.type.tag != TypeTags.INVOKABLE) {
        dlog.error(iExpr.pos, DiagnosticCode.UNDEFINED_FUNCTION, funcName);
        resultTypes = getListWithErrorTypes(expTypes.size());
        return;
    }
    if (funcSymbol.tag == SymTag.VARIABLE) {
        // Check for function pointer.
        iExpr.functionPointerInvocation = true;
    }
    // Set the resolved function symbol in the invocation expression.
    // This is used in the code generation phase.
    iExpr.symbol = funcSymbol;
    checkInvocationParamAndReturnType(iExpr);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 89 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.

the class TypeChecker method visit.

public void visit(BLangUnaryExpr unaryExpr) {
    BType exprType = null;
    BType actualType = symTable.errType;
    if (OperatorKind.TYPEOF.equals(unaryExpr.operator)) {
        // Handle typeof operator separately
        if (unaryExpr.expr.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
            BLangSimpleVarRef varRef = (BLangSimpleVarRef) unaryExpr.expr;
            Name varRefName = names.fromIdNode((varRef).variableName);
            Name pkgAlias = names.fromIdNode((varRef).pkgAlias);
            // Resolve symbol for BLangSimpleVarRef
            BSymbol varRefSybmol = symResolver.lookupSymbolInPackage(unaryExpr.pos, env, pkgAlias, varRefName, SymTag.VARIABLE);
            if (varRefSybmol == symTable.notFoundSymbol) {
                // Resolve symbol for User Defined Type ( converted from BLangSimpleVarRef )
                BLangTypeofExpr typeAccessExpr = getTypeAccessExpression(varRef);
                unaryExpr.expr = typeAccessExpr;
                actualType = typeAccessExpr.type;
                resultTypes = types.checkTypes(unaryExpr, Lists.of(actualType), expTypes);
                return;
            } else {
                // Check type if resolved as BLangSimpleVarRef
                exprType = checkExpr(unaryExpr.expr, env).get(0);
            }
        } else {
            // Check type if resolved as non BLangSimpleVarRef Expression
            exprType = checkExpr(unaryExpr.expr, env).get(0);
        }
        if (exprType != symTable.errType) {
            unaryExpr.opSymbol = Symbols.createTypeofOperatorSymbol(exprType, types, symTable, names);
            actualType = unaryExpr.opSymbol.type.getReturnTypes().get(0);
        }
    } else {
        exprType = checkExpr(unaryExpr.expr, env).get(0);
        if (exprType != symTable.errType) {
            BSymbol symbol = symResolver.resolveUnaryOperator(unaryExpr.pos, unaryExpr.operator, exprType);
            if (symbol == symTable.notFoundSymbol) {
                dlog.error(unaryExpr.pos, DiagnosticCode.UNARY_OP_INCOMPATIBLE_TYPES, unaryExpr.operator, exprType);
            } else {
                unaryExpr.opSymbol = (BOperatorSymbol) symbol;
                actualType = symbol.type.getReturnTypes().get(0);
            }
        }
    }
    resultTypes = types.checkTypes(unaryExpr, Lists.of(actualType), expTypes);
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangTypeofExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeofExpr) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 90 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.

the class CodeAnalyzer method visit.

public void visit(BLangTransformer transformerNode) {
    List<BVarSymbol> inputs = new ArrayList<>();
    inputs.add(transformerNode.source.symbol);
    transformerNode.requiredParams.forEach(param -> inputs.add(param.symbol));
    List<BVarSymbol> outputs = new ArrayList<>();
    transformerNode.retParams.forEach(param -> outputs.add(param.symbol));
    for (BLangStatement stmt : transformerNode.body.stmts) {
        switch(stmt.getKind()) {
            case VARIABLE_DEF:
                BLangVariableDef variableDefStmt = (BLangVariableDef) stmt;
                variableDefStmt.var.expr.accept(new TransformerVarRefValidator(outputs, DiagnosticCode.TRANSFORMER_INVALID_OUTPUT_USAGE));
                inputs.add(variableDefStmt.var.symbol);
                break;
            case ASSIGNMENT:
                BLangAssignment assignStmt = (BLangAssignment) stmt;
                assignStmt.varRefs.forEach(varRef -> {
                    varRef.accept(new TransformerVarRefValidator(inputs, DiagnosticCode.TRANSFORMER_INVALID_INPUT_UPDATE));
                    // If the stmt is declared using var, all the variable refs on lhs should be treated as inputs
                    if (assignStmt.declaredWithVar && varRef.getKind() == NodeKind.SIMPLE_VARIABLE_REF && !inputs.contains(((BLangSimpleVarRef) varRef).symbol)) {
                        inputs.add(((BLangSimpleVarRef) varRef).symbol);
                    }
                });
                assignStmt.expr.accept(new TransformerVarRefValidator(outputs, DiagnosticCode.TRANSFORMER_INVALID_OUTPUT_USAGE));
                break;
            case EXPRESSION_STATEMENT:
                // Here we have assumed that the invocation expression is the only expression-statement available.
                // TODO: support other types, once they are implemented.
                dlog.error(stmt.pos, DiagnosticCode.INVALID_STATEMENT_IN_TRANSFORMER, "invocation");
                break;
            default:
                dlog.error(stmt.pos, DiagnosticCode.INVALID_STATEMENT_IN_TRANSFORMER, stmt.getKind().name().toLowerCase().replace('_', ' '));
                break;
        }
    }
}
Also used : BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) ArrayList(java.util.ArrayList) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)

Aggregations

Expression (org.wso2.siddhi.query.api.expression.Expression)32 ArrayList (java.util.ArrayList)20 Attribute (org.wso2.siddhi.query.api.definition.Attribute)16 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)15 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)15 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)13 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)13 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)13 Variable (org.wso2.siddhi.query.api.expression.Variable)11 Test (org.testng.annotations.Test)10 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)10 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)10 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)10 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)9 OutputAttribute (org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute)8 CompiledCondition (org.wso2.siddhi.core.util.collection.operator.CompiledCondition)7 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 MatchingMetaInfoHolder (org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)6 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)6