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