Search in sources :

Example 91 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class AssignmentStmtContextSorter method getVariableType.

/**
 * Get the variable type.
 *
 * @param ctx Document Service context (Completion context)
 * @return {@link String} type of the variable
 */
@Override
String getVariableType(TextDocumentServiceContext ctx) {
    String variableName = ctx.get(DocumentServiceKeys.PARSER_RULE_CONTEXT_KEY).getStart().getText();
    List<SymbolInfo> visibleSymbols = ctx.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
    SymbolInfo filteredSymbol = visibleSymbols.stream().filter(symbolInfo -> {
        BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
        String symbolName = symbolInfo.getSymbolName();
        return bSymbol instanceof BVarSymbol && symbolName.equals(variableName);
    }).findFirst().orElse(null);
    if (filteredSymbol != null) {
        return filteredSymbol.getScopeEntry().symbol.type.toString();
    }
    return "";
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) SymbolInfo(org.ballerinalang.langserver.completions.SymbolInfo)

Example 92 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class MatchStatementScopeResolver method isCursorBeforeNode.

/**
 * Check whether the cursor is positioned before the given node start.
 *
 * @param nodePosition          Position of the node
 * @param node                  Node
 * @param treeVisitor           {@link TreeVisitor} current tree visitor instance
 * @param completionContext     Completion operation context
 * @return {@link Boolean}      Whether the cursor is before the node start or not
 */
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
    if (!(treeVisitor.getBlockOwnerStack().peek() instanceof BLangMatch)) {
        // In the ideal case, this will not get triggered
        return false;
    }
    BLangMatch matchNode = (BLangMatch) treeVisitor.getBlockOwnerStack().peek();
    DiagnosticPos matchNodePos = CommonUtil.toZeroBasedPosition(matchNode.getPosition());
    DiagnosticPos nodePos = CommonUtil.toZeroBasedPosition((DiagnosticPos) node.getPosition());
    List<BLangMatch.BLangMatchStmtPatternClause> patternClauseList = matchNode.getPatternClauses();
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    int nodeLine = nodePos.getStartLine();
    int nodeCol = nodePos.getStartColumn();
    boolean isBeforeNode = false;
    if ((line < nodeLine) || (line == nodeLine && col < nodeCol)) {
        isBeforeNode = true;
    } else if (patternClauseList.indexOf(node) == patternClauseList.size() - 1) {
        isBeforeNode = (line < matchNodePos.getEndLine()) || (line == matchNodePos.getEndLine() && col < matchNodePos.getEndColumn());
    }
    if (isBeforeNode) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
        SymbolEnv matchEnv = createMatchEnv(matchNode, treeVisitor.getSymbolEnv());
        treeVisitor.populateSymbols(visibleSymbolEntries, matchEnv);
        treeVisitor.setTerminateVisitor(true);
    }
    return isBeforeNode;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 93 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class ObjectTypeScopeResolver method isCursorBeforeNode.

/**
 * Check whether the cursor is positioned before the given node start.
 *
 * @param nodePosition      Position of the node
 * @param node              Node
 * @param treeVisitor       {@link TreeVisitor} current tree visitor instance
 * @param completionContext Completion operation context
 * @return {@link Boolean}      Whether the cursor is before the node start or not
 */
@Override
public boolean isCursorBeforeNode(DiagnosticPos nodePosition, Node node, TreeVisitor treeVisitor, TextDocumentServiceContext completionContext) {
    if (!(treeVisitor.getBlockOwnerStack().peek() instanceof BLangObject)) {
        return false;
    }
    BLangObject ownerObject = (BLangObject) treeVisitor.getBlockOwnerStack().peek();
    DiagnosticPos zeroBasedPos = CommonUtil.toZeroBasedPosition(nodePosition);
    DiagnosticPos blockOwnerPos = CommonUtil.toZeroBasedPosition((DiagnosticPos) treeVisitor.getBlockOwnerStack().peek().getPosition());
    int line = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getLine();
    int col = completionContext.get(DocumentServiceKeys.POSITION_KEY).getPosition().getCharacter();
    boolean isLastField = false;
    if ((!ownerObject.fields.isEmpty() && node instanceof BLangVariable && ownerObject.fields.indexOf(node) == ownerObject.fields.size() - 1 && ownerObject.functions.isEmpty()) || (!ownerObject.functions.isEmpty() && node instanceof BLangFunction && ownerObject.functions.indexOf(node) == ownerObject.functions.size() - 1)) {
        isLastField = true;
    }
    if ((line < zeroBasedPos.getStartLine() || (line == zeroBasedPos.getStartLine() && col < zeroBasedPos.getStartColumn())) || (isLastField && ((blockOwnerPos.getEndLine() > line && zeroBasedPos.getEndLine() < line) || (blockOwnerPos.getEndLine() == line && blockOwnerPos.getEndColumn() > col)))) {
        Map<Name, Scope.ScopeEntry> visibleSymbolEntries = treeVisitor.resolveAllVisibleSymbols(treeVisitor.getSymbolEnv());
        treeVisitor.populateSymbols(visibleSymbolEntries, null);
        treeVisitor.setTerminateVisitor(true);
        return true;
    }
    return false;
}
Also used : DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 94 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.

the class BallerinaWebSubConnectionListener method autoRespondToIntentVerification.

/**
 * Method to automatically respond to intent verification requests for subscriptions/unsubscriptions if a resource
 * named {@link WebSubSubscriberConstants#RESOURCE_NAME_VERIFY_INTENT} is not specified.
 *
 * @param httpCarbonMessage the message/request received
 */
private void autoRespondToIntentVerification(HTTPCarbonMessage httpCarbonMessage) {
    String annotatedTopic = httpCarbonMessage.getProperty(WebSubSubscriberConstants.ANNOTATED_TOPIC).toString();
    PrintStream console = System.out;
    if (httpCarbonMessage.getProperty(HttpConstants.QUERY_STR) != null) {
        String queryString = (String) httpCarbonMessage.getProperty(HttpConstants.QUERY_STR);
        BMap<String, BString> params = new BMap<>();
        try {
            HTTPCarbonMessage response = HttpUtil.createHttpCarbonMessage(false);
            response.waitAndReleaseAllEntities();
            URIUtil.populateQueryParamMap(queryString, params);
            String mode = params.get(WebSubSubscriberConstants.PARAM_HUB_MODE).stringValue();
            if ((WebSubSubscriberConstants.SUBSCRIBE.equals(mode) || WebSubSubscriberConstants.UNSUBSCRIBE.equals(mode)) && annotatedTopic.equals(params.get(WebSubSubscriberConstants.PARAM_HUB_TOPIC).stringValue())) {
                String challenge = params.get(WebSubSubscriberConstants.PARAM_HUB_CHALLENGE).stringValue();
                response.addHttpContent(new DefaultLastHttpContent(Unpooled.wrappedBuffer(challenge.getBytes(StandardCharsets.UTF_8))));
                response.setProperty(HttpConstants.HTTP_STATUS_CODE, 202);
                console.println("ballerina: Intent Verification agreed - Mode [" + mode + "], Topic [" + annotatedTopic + "], Lease Seconds [" + params.get(WebSubSubscriberConstants.PARAM_HUB_LEASE_SECONDS) + "]");
            } else {
                console.println("ballerina: Intent Verification denied - Mode [" + mode + "] for Incorrect Topic [" + annotatedTopic + "]");
                response.setProperty(HttpConstants.HTTP_STATUS_CODE, 404);
            }
            HttpUtil.sendOutboundResponse(httpCarbonMessage, response);
        } catch (UnsupportedEncodingException e) {
            throw new BallerinaException("Error responding to intent verification request: " + e.getMessage());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) BMap(org.ballerinalang.model.values.BMap) BString(org.ballerinalang.model.values.BString) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BString(org.ballerinalang.model.values.BString) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 95 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class AbstractAPIManager method getTiers.

/**
 * Returns a list of pre-defined # {@link org.wso2.carbon.apimgt.api.model.Tier} in the system.
 *
 * @return Set<Tier>
 */
public Set<Tier> getTiers(String tenantDomain) throws APIManagementException {
    Set<Tier> tiers = new TreeSet<Tier>(new TierNameComparator());
    Map<String, Tier> tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_SUB, tenantId);
    tiers.addAll(tierMap.values());
    return tiers;
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) TreeSet(java.util.TreeSet) TierNameComparator(org.wso2.carbon.apimgt.impl.utils.TierNameComparator)

Aggregations

PreparedStatement (java.sql.PreparedStatement)47 ArrayList (java.util.ArrayList)47 Connection (java.sql.Connection)43 SQLException (java.sql.SQLException)41 ResultSet (java.sql.ResultSet)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)26 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 HashSet (java.util.HashSet)16 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 IOException (java.io.IOException)14 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 Expression (org.wso2.siddhi.query.api.expression.Expression)13 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)12 TimeConstant (org.wso2.siddhi.query.api.expression.constant.TimeConstant)12 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 API (org.wso2.carbon.apimgt.core.models.API)11 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SiddhiQLParser (org.wso2.siddhi.query.compiler.SiddhiQLParser)10