Java Code Examples for net.sf.json.JSONObject#optInt()

The following examples show how to use net.sf.json.JSONObject#optInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalConfigurationService.java    From sonar-quality-gates-plugin with MIT License 6 votes vote down vote up
protected void addGlobalConfigDataForSonarInstance(JSONObject globalConfigData) {

        String name = globalConfigData.optString("name");
        int timeToWait = globalConfigData.optInt("timeToWait");
		int maxWaitTime = globalConfigData.optInt("maxWaitTime");
        String url = globalConfigData.optString("url");

        if (!"".equals(name)) {

            GlobalConfigDataForSonarInstance globalConfigDataForSonarInstance;
            String token = globalConfigData.optString("token");
            if (StringUtils.isNotEmpty(token)) {
                globalConfigDataForSonarInstance = new GlobalConfigDataForSonarInstance(name, url, globalConfigData.optString("token"), timeToWait, maxWaitTime);
            } else {
                globalConfigDataForSonarInstance = new GlobalConfigDataForSonarInstance(name, url, globalConfigData.optString("account"), Secret.fromString(Util.fixEmptyAndTrim(globalConfigData.optString("password"))), timeToWait, maxWaitTime);
            }

            if (!containsGlobalConfigWithName(name)) {
                listOfGlobalConfigInstances.add(globalConfigDataForSonarInstance);
            }
        }
    }
 
Example 2
Source File: JsonSecurityRule.java    From ipst with Mozilla Public License 2.0 6 votes vote down vote up
private static void processTreeNode(JSONObject node, JSONArray inputs, double purityThreshold, SecondLevelNode currentCondition, List<SecondLevelNode> trueConditions, JSONObject stats, int trueIdx) {
    if ("thresholdTest".equals(node.optString("type"))) {
        // conditional node
        int inputIdx = node.optInt("inputIndex");
        HistoDbAttributeId attrId = HistoDbAttributeIdParser.parse(inputs.opt(inputIdx).toString());
        double threshold = node.optDouble("threshold");
        ComparisonOperator trueCondition = new ComparisonOperator(new Attribute(attrId), new Litteral(threshold), ComparisonOperator.Type.LESS);
        ComparisonOperator falseCondition = new ComparisonOperator(new Attribute(attrId), new Litteral(threshold), ComparisonOperator.Type.GREATER_EQUAL);
        processTreeNode(node.optJSONObject("trueChild"), inputs, purityThreshold,
                        currentCondition == null ? trueCondition : new AndOperator(currentCondition.clone(), trueCondition),
                        trueConditions, stats, trueIdx);
        processTreeNode(node.optJSONObject("falseChild"), inputs, purityThreshold,
                        currentCondition == null ? falseCondition : new AndOperator(currentCondition.clone(), falseCondition),
                        trueConditions, stats, trueIdx);
    } else {
        if (currentCondition != null && isTrueCondition(stats, node, purityThreshold, trueIdx)) {
            trueConditions.add(currentCondition);
        }
    }
}
 
Example 3
Source File: Skype.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Retrieves access token for bot
 */
protected void getAccessToken() throws Exception {
	String url = "https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token";

	String type = "application/x-www-form-urlencoded";
	String data = "grant_type=client_credentials&client_id=" + appId + "&client_secret=" + appPassword + "&scope=https%3A%2F%2Fapi.botframework.com%2F.default";
	String json = Utils.httpPOST(url, type, data);
	
	JSONObject root = (JSONObject)JSONSerializer.toJSON(json);
	
	if(root.optString("token_type").equals("Bearer")) {
		int tokenExpiresIn = root.optInt("expires_in");
		String accessToken = root.optString("access_token");
		
		setToken(accessToken);
		this.tokenExpiry = new Date(System.currentTimeMillis() + (tokenExpiresIn * 1000));
		
		log("Skype access token retrieved.", Level.INFO);
	} else {
		log("Skype get access token failed:", Level.INFO);
	}
	
	saveProperties();
}
 
Example 4
Source File: CodeBuilder.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
    req.bindJSON(this, formData);
    this.minSleepTime = formData.optInt("minSleepTime", 0);
    this.maxSleepTime = formData.optInt("maxSleepTime", 0);
    this.sleepJitter = formData.optInt("sleepJitter", 0);
    save();
    return super.configure(req, formData);
}
 
Example 5
Source File: WeChat.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Retrieves access token for bot.
 * Access token must be obtained before calling APIs
 */
protected void getAccessToken() throws Exception {
	String url = "https://";
	url = url.concat( this.international ? INTERNATIONAL_API : CHINA_API );
	url = url.concat("/cgi-bin/token");
	
	String data = "?grant_type=client_credential&appid=" + appId + "&secret=" + appPassword;
	url = url.concat(data);
	
	String json = Utils.httpGET(url);
	
	JSONObject root = (JSONObject)JSONSerializer.toJSON(json);
	
	if(root.optString("access_token") != null) {
		int tokenExpiresIn = root.optInt("expires_in");
		String accessToken = root.optString("access_token");
		
		setToken(accessToken);
		this.tokenExpiry = new Date(System.currentTimeMillis() + (tokenExpiresIn * 1000));
		
		log("WeChat access token retrieved - token: " + accessToken + ", expires in " + tokenExpiresIn, Level.INFO);
	} else if (root.optString("errmsg") != null) {
		String errMsg = root.optString("errmsg");
		int errCode = root.optInt("errcode");
		log("WeChat get access token failed - Error code:" + errCode + ", Error Msg: " + errMsg, Level.INFO);
	} else {
		log("WeChat get access token failed.", Level.INFO);
	}
	
	saveProperties();
}
 
Example 6
Source File: SMABuilder.java    From salesforce-migration-assistant with MIT License 5 votes vote down vote up
public boolean configure(StaplerRequest request, JSONObject formData) throws FormException
{
    maxPoll = formData.getString("maxPoll");
    pollWait = formData.getString("pollWait");
    proxyServer = formData.getString("proxyServer");
    proxyUser = formData.getString("proxyUser");
    proxyPass = formData.getString("proxyPass");
    proxyPort = formData.optInt("proxyPort");

    save();
    return false;
}