Search in sources :

Example 96 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project carbon-business-process by wso2.

the class IfImpl method isSimpleLayout.

/**
 * @return false- if the subActivities are instances of ElseIf or Else
 * true - otherwise
 */
private boolean isSimpleLayout() {
    boolean simple = true;
    ActivityInterface activity = null;
    // Iterates through the subActivities
    Iterator<ActivityInterface> itr = getSubActivities().iterator();
    while (itr.hasNext()) {
        activity = itr.next();
        // if the activity is an instance of ElseIf or Else, break the if condition
        if (activity instanceof ElseIfImpl || activity instanceof ElseImpl) {
            simple = false;
            break;
        }
    }
    return simple;
}
Also used : ActivityInterface(org.wso2.carbon.bpel.ui.bpel2svg.ActivityInterface)

Example 97 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project ballerina by ballerina-lang.

the class CodeGenerator method generateURILookupInstructions.

private void generateURILookupInstructions(Map<Name, BXMLNSSymbol> namespaces, RegIndex localNameRegIndex, RegIndex uriRegIndex, RegIndex targetQNameRegIndex, DiagnosticPos pos, SymbolEnv symbolEnv) {
    if (namespaces.isEmpty()) {
        createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
        return;
    }
    Stack<Operand> endJumpInstrStack = new Stack<>();
    String prefix;
    for (Entry<Name, BXMLNSSymbol> keyValues : namespaces.entrySet()) {
        prefix = keyValues.getKey().getValue();
        // skip the default namespace
        if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
            continue;
        }
        // Below section creates the condition to compare the namespace URIs
        // store the comparing uri as string
        BXMLNSSymbol nsSymbol = keyValues.getValue();
        int opcode = getOpcode(TypeTags.STRING, InstructionCodes.IEQ);
        RegIndex conditionExprIndex = getRegIndex(TypeTags.BOOLEAN);
        emit(opcode, uriRegIndex, getNamespaceURIIndex(nsSymbol, symbolEnv), conditionExprIndex);
        Operand ifCondJumpAddr = getOperand(-1);
        emit(InstructionCodes.BR_FALSE, conditionExprIndex, ifCondJumpAddr);
        // Below section creates instructions to be executed, if the above condition succeeds (then body)
        // create the prefix literal
        RegIndex prefixIndex = createStringLiteral(prefix, null, env);
        // create a qname
        emit(InstructionCodes.NEWQNAME, localNameRegIndex, uriRegIndex, prefixIndex, targetQNameRegIndex);
        Operand endJumpAddr = getOperand(-1);
        emit(InstructionCodes.GOTO, endJumpAddr);
        endJumpInstrStack.add(endJumpAddr);
        ifCondJumpAddr.value = nextIP();
    }
    // else part. create a qname with empty prefix
    createQNameWithoutPrefix(localNameRegIndex, uriRegIndex, targetQNameRegIndex);
    while (!endJumpInstrStack.isEmpty()) {
        endJumpInstrStack.pop().value = nextIP();
    }
}
Also used : BXMLNSSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BXMLNSSymbol) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) Stack(java.util.Stack) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.ballerinalang.model.Name) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 98 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangIf ifNode) {
    addLineNumberInfo(ifNode.pos);
    // Generate code for the if condition evaluation
    genNode(ifNode.expr, this.env);
    Operand ifCondJumpAddr = getOperand(-1);
    emit(InstructionCodes.BR_FALSE, ifNode.expr.regIndex, ifCondJumpAddr);
    // Generate code for the then body
    genNode(ifNode.body, this.env);
    Operand endJumpAddr = getOperand(-1);
    emit(InstructionCodes.GOTO, endJumpAddr);
    ifCondJumpAddr.value = nextIP();
    // Visit else statement if any
    if (ifNode.elseStmt != null) {
        genNode(ifNode.elseStmt, this.env);
    }
    endJumpAddr.value = nextIP();
}
Also used : Operand(org.wso2.ballerinalang.programfile.Instruction.Operand)

Example 99 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project ballerina by ballerina-lang.

the class ParserRuleTypeNameContextResolver method resolveItems.

@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
    ArrayList<CompletionItem> completionItems = new ArrayList<>();
    TokenStream tokenStream = completionContext.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
    ParserRuleContext parserRuleContext = completionContext.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY);
    CompletionItemSorter itemSorter = ItemSorters.getSorterByClass(DefaultItemSorter.class);
    if (parserRuleContext.getParent() instanceof BallerinaParser.CatchClauseContext && CommonUtil.isWithinBrackets(completionContext, Collections.singletonList(CATCH_KEY_WORD))) {
        this.populateCompletionItemList(filterCatchConditionSymbolInfo(completionContext), completionItems);
    } else if (tokenStream.get(completionContext.get(DocumentServiceKeys.TOKEN_INDEX_KEY)).getText().equals(":")) {
        /*
            TODO: ATM, this particular condition becomes true only when try to access packages' items in the 
            endpoint definition context
             */
        this.populateCompletionItemList(filterEndpointContextSymbolInfo(completionContext), completionItems);
    } else {
        StatementTemplateFilter statementTemplateFilter = new StatementTemplateFilter();
        // Add the statement templates
        completionItems.addAll(statementTemplateFilter.filterItems(completionContext));
        this.populateBasicTypes(completionItems, completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY));
        itemSorter = ItemSorters.getSorterByClass(completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY).getClass());
    }
    itemSorter.sortItems(completionContext, completionItems);
    return completionItems;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) TokenStream(org.antlr.v4.runtime.TokenStream) CompletionItem(org.eclipse.lsp4j.CompletionItem) ArrayList(java.util.ArrayList) CompletionItemSorter(org.ballerinalang.langserver.completions.util.sorters.CompletionItemSorter) StatementTemplateFilter(org.ballerinalang.langserver.completions.util.filters.StatementTemplateFilter) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser)

Example 100 with Condition

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.Condition in project carbon-apimgt by wso2.

the class PolicyDAOImpl method isBlockConditionExist.

/**
 * Check if a blocking condition already exists.
 *
 * @param blockConditions BlockConditions object to be added
 * @return true/false depending on the success
 * @throws APIMgtDAOException If failed to check if block condition exist
 */
private boolean isBlockConditionExist(BlockConditions blockConditions) throws APIMgtDAOException {
    boolean status = false;
    if (blockConditions.getConditionType().equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE)) {
        String isExistQuery = "SELECT STARTING_IP, ENDING_IP FROM AM_IP_RANGE_CONDITION WHERE STARTING_IP =? " + "AND ENDING_IP =?";
        try (Connection connection = DAOUtil.getConnection();
            PreparedStatement checkIsExistPreparedStatement = connection.prepareStatement(isExistQuery)) {
            checkIsExistPreparedStatement.setString(1, blockConditions.getStartingIP());
            checkIsExistPreparedStatement.setString(2, blockConditions.getEndingIP());
            try (ResultSet checkIsResultSet = checkIsExistPreparedStatement.executeQuery()) {
                if (checkIsResultSet.next()) {
                    status = true;
                }
            }
        } catch (SQLException e) {
            String msg = DAOUtil.DAO_ERROR_PREFIX + "checking if the IP range blacklist condition exists with starting IP: " + blockConditions.getStartingIP() + ", ending IP: " + blockConditions.getEndingIP();
            throw new APIMgtDAOException(msg, e);
        }
    } else {
        String isExistQuery = "SELECT CONDITION_ID,TYPE,VALUE,ENABLED,UUID FROM AM_BLOCK_CONDITIONS WHERE TYPE =? " + "AND VALUE =?";
        try (Connection connection = DAOUtil.getConnection();
            PreparedStatement checkIsExistPreparedStatement = connection.prepareStatement(isExistQuery)) {
            connection.setAutoCommit(false);
            checkIsExistPreparedStatement.setString(1, blockConditions.getConditionType());
            checkIsExistPreparedStatement.setString(2, blockConditions.getConditionValue());
            try (ResultSet checkIsResultSet = checkIsExistPreparedStatement.executeQuery()) {
                if (checkIsResultSet.next()) {
                    status = true;
                }
            }
        } catch (SQLException e) {
            String msg = DAOUtil.DAO_ERROR_PREFIX + "checking if the Block Condition Exist with condition type: " + blockConditions.getConditionType() + ", condition value: " + blockConditions.getConditionValue();
            throw new APIMgtDAOException(msg, e);
        }
    }
    return status;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

HashMap (java.util.HashMap)39 Test (org.junit.Test)32 Test (org.testng.annotations.Test)31 ArrayList (java.util.ArrayList)30 List (java.util.List)26 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)26 ConditionDto (org.wso2.carbon.apimgt.impl.dto.ConditionDto)26 MessageContext (org.apache.synapse.MessageContext)25 PreparedStatement (java.sql.PreparedStatement)23 Map (java.util.Map)22 ResultSet (java.sql.ResultSet)20 BlockConditions (org.wso2.carbon.apimgt.core.models.BlockConditions)18 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)18 Connection (java.sql.Connection)16 SQLException (java.sql.SQLException)16 TreeMap (java.util.TreeMap)16 HeaderCondition (org.wso2.carbon.apimgt.api.model.policy.HeaderCondition)15 JWTClaimsCondition (org.wso2.carbon.apimgt.api.model.policy.JWTClaimsCondition)15 QueryParameterCondition (org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)15 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)15