Search in sources :

Example 6 with JSONArray

use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.

the class JenkinsJSExtensions method getExtensionsData.

/**
     * Return the actual data, from /js-extensions
     */
public static JSONArray getExtensionsData() {
    Object jsExtensionData = getJenkinsJSExtensionData();
    JSONArray jsExtensionDataJson = JSONArray.fromObject(jsExtensionData);
    return jsExtensionDataJson;
}
Also used : JSONArray(net.sf.json.JSONArray)

Example 7 with JSONArray

use of net.sf.json.JSONArray in project promoted-builds-plugin by jenkinsci.

the class Status method doBuild.

/**
     * Schedules a new build.
     * @param req Request
     * @param rsp Response
     * @throws IOException Functional error
     * @throws ServletException Request handling error
     */
public void doBuild(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
    final PromotionProcess process = getProcess();
    if (process == null) {
        throw new AbortException("Cannot retrieve the promotion process");
    }
    AbstractBuild<?, ?> target = getTarget();
    if (target == null) {
        throw new AbortException("Cannot get the target build to be promoted");
    }
    ManualCondition manualCondition = (ManualCondition) process.getPromotionCondition(ManualCondition.class.getName());
    if (!target.hasPermission(Promotion.PROMOTE)) {
        if (manualCondition == null || (!manualCondition.getUsersAsSet().isEmpty() && !manualCondition.isInUsersList() && !manualCondition.isInGroupList()))
            return;
    }
    JSONObject formData = req.getSubmittedForm();
    List<ParameterValue> paramValues = null;
    if (formData != null) {
        paramValues = new ArrayList<ParameterValue>();
        if (manualCondition != null) {
            List<ParameterDefinition> parameterDefinitions = manualCondition.getParameterDefinitions();
            if (parameterDefinitions != null && !parameterDefinitions.isEmpty()) {
                JSONArray a = JSONArray.fromObject(formData.get("parameter"));
                for (Object o : a) {
                    JSONObject jo = (JSONObject) o;
                    String name = jo.getString("name");
                    ParameterDefinition d = manualCondition.getParameterDefinition(name);
                    if (d == null)
                        throw new IllegalArgumentException("No such parameter definition: " + name);
                    paramValues.add(d.createValue(req, jo));
                }
            }
        }
    }
    if (paramValues == null) {
        paramValues = new ArrayList<ParameterValue>();
    }
    Future<Promotion> f = process.scheduleBuild2(target, new UserCause(), paramValues);
    if (f == null)
        LOGGER.warning("Failing to schedule the promotion of " + target);
    // TODO: we need better visual feed back so that the user knows that the build happened.
    rsp.forwardToPreviousPage(req);
}
Also used : ParameterValue(hudson.model.ParameterValue) UserCause(hudson.model.Cause.UserCause) JSONArray(net.sf.json.JSONArray) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) JSONObject(net.sf.json.JSONObject) JSONObject(net.sf.json.JSONObject) AbortException(hudson.AbortException) ParameterDefinition(hudson.model.ParameterDefinition)

Example 8 with JSONArray

use of net.sf.json.JSONArray in project hudson-2.x by hudson.

the class JSONTest method testCanonicalWriter.

public void testCanonicalWriter() throws IOException {
    JSONArray jsonArray = new JSONArray();
    jsonArray.add(true);
    jsonArray.add(1);
    jsonArray.add(5.3);
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("key1", "1");
    jsonObject.put("key2", "2");
    jsonObject.put("key3", "3");
    jsonObject.put("string", "123\r\n\b\t\f\\\\u65E5\\u672C\\u8A9E");
    jsonArray.add(jsonObject);
    Writer writer = new StringWriter();
    JSONCanonicalUtils.write(jsonArray, writer);
    assertEquals(writer.toString(), "[true,1,5.3,{\"key1\":\"1\",\"key2\":\"2\",\"key3\":\"3\",\"string\":\"123\\u000d\\u000a\\u0008\\u0009\\u000c\\\\\\\\u65E5\\\\u672C\\\\u8A9E\"}]");
}
Also used : JSONObject(net.sf.json.JSONObject) StringWriter(java.io.StringWriter) JSONArray(net.sf.json.JSONArray) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 9 with JSONArray

use of net.sf.json.JSONArray in project head by mifos.

the class DatabaseConfiguration method readVCAPConfiguration.

private void readVCAPConfiguration() throws ConfigurationException {
    final String vcapServicesVar = System.getenv(VCAP_SERVICES_VAR);
    if (vcapServicesVar != null) {
        // use database configuration from the system variable to replace the default config
        final JSONObject json = (JSONObject) JSONSerializer.toJSON(vcapServicesVar);
        String mysqlKey = null;
        @SuppressWarnings("rawtypes") final Iterator iterator = json.keys();
        while (iterator.hasNext()) {
            final String key = (String) iterator.next();
            if (key.startsWith("mysql")) {
                mysqlKey = key;
                break;
            }
        }
        if (mysqlKey == null) {
            throw new ConfigurationException(INVALID_STRUCTURE);
        }
        final JSON mysqlJson = (JSON) json.get(mysqlKey);
        JSONObject dbJson;
        if (mysqlJson.isArray()) {
            final JSONArray mysqlJsonArray = (JSONArray) mysqlJson;
            if (mysqlJsonArray.size() < 1) {
                throw new ConfigurationException(INVALID_STRUCTURE);
            }
            dbJson = (JSONObject) mysqlJsonArray.get(0);
        } else {
            dbJson = (JSONObject) mysqlJson;
        }
        final JSONObject credentialsJson = (JSONObject) dbJson.get("credentials");
        this.dbName = credentialsJson.getString("name");
        this.host = credentialsJson.getString("host");
        this.port = credentialsJson.getString("port");
        this.user = credentialsJson.getString("user");
        this.password = credentialsJson.getString("password");
        this.dbPentahoDW = credentialsJson.getString("dbPentahoDW");
    }
}
Also used : JSONObject(net.sf.json.JSONObject) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) Iterator(java.util.Iterator) JSONArray(net.sf.json.JSONArray) JSON(net.sf.json.JSON)

Example 10 with JSONArray

use of net.sf.json.JSONArray in project pinpoint by naver.

the class JsonLibJSONArrayIT method jsonToArrayTest.

@SuppressWarnings("deprecation")
@Test
public void jsonToArrayTest() throws Exception {
    Method fromObject = JSONArray.class.getMethod("fromObject", Object.class);
    Method toArray = JSONArray.class.getMethod("toArray", JSONArray.class);
    Method toList = JSONArray.class.getMethod("toList", JSONArray.class);
    // JSONArray.toCollection() is added in json-lib 2.2. so check toCollection in JSONArray
    Method toCollection = null;
    try {
        toCollection = JSONArray.class.getMethod("toCollection", JSONArray.class);
    } catch (NoSuchMethodException ignored) {
    }
    String json = "[{'string':'JSON'}]";
    JSONArray jsonArray = JSONArray.fromObject(json);
    // JSONArray.toArray() of json-lib 2.0 and below have different return type. so we invoke it by reflection to avoid NoSuchMethodError
    toArray.invoke(null, jsonArray);
    JSONArray.toList(jsonArray);
    if (toCollection != null) {
        JSONArray.toCollection(jsonArray);
    }
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.verifyTrace(event(SERVICE_TYPE, fromObject, annotation(ANNOTATION_KEY, json.length())));
    verifier.verifyTrace(event(SERVICE_TYPE, toArray));
    verifier.verifyTrace(event(SERVICE_TYPE, toList));
    if (toCollection != null) {
        verifier.verifyTrace(event(SERVICE_TYPE, toCollection));
    }
    verifier.verifyTraceCount(0);
}
Also used : JSONArray(net.sf.json.JSONArray) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) Test(org.junit.Test)

Aggregations

JSONArray (net.sf.json.JSONArray)31 JSONObject (net.sf.json.JSONObject)19 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)4 Test (org.junit.Test)4 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)3 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)3 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)3 ParameterDefinition (hudson.model.ParameterDefinition)3 ParameterValue (hudson.model.ParameterValue)3 OutputStream (java.io.OutputStream)3 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)2 Pair (com.alibaba.cobar.manager.util.Pair)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 Method (java.lang.reflect.Method)2 ParseException (java.text.ParseException)2 Iterator (java.util.Iterator)2