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");
}
}
use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.
the class JenkinsJSExtensionsTest method test.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test() {
// Simple test of JenkinsJSExtensions. It should find the "blueocean-dashboard"
// and "blueocean-personalization" plugin ExtensionPoint contributions.
JSONArray extensionData = JenkinsJSExtensions.getExtensionsData();
Assert.assertTrue(extensionData.size() > 2);
Iterator pluginIterator = extensionData.iterator();
while (pluginIterator.hasNext()) {
JSONObject plugin = (JSONObject) pluginIterator.next();
JSONArray extensionPoints = (JSONArray) plugin.get("extensions");
String pluginId = plugin.getString("hpiPluginId");
Assert.assertNotNull(plugin.get("hpiPluginVer"));
Assert.assertNotNull(extensionPoints);
if ("blueocean-dashboard".equals(pluginId)) {
Assert.assertEquals(7, extensionPoints.size());
Assert.assertEquals("AdminNavLink", extensionPoints.getJSONObject(0).get("component"));
Assert.assertEquals("jenkins.logo.top", extensionPoints.getJSONObject(0).get("extensionPoint"));
} else if ("blueocean-personalization".equals(pluginId)) {
Assert.assertEquals(5, extensionPoints.size());
Assert.assertEquals("redux/FavoritesStore", extensionPoints.getJSONObject(0).get("component"));
Assert.assertEquals("jenkins.main.stores", extensionPoints.getJSONObject(0).get("extensionPoint"));
Assert.assertEquals("components/DashboardCards", extensionPoints.getJSONObject(1).get("component"));
Assert.assertEquals("jenkins.pipeline.list.top", extensionPoints.getJSONObject(1).get("extensionPoint"));
Assert.assertEquals("components/FavoritePipeline", extensionPoints.getJSONObject(2).get("component"));
Assert.assertEquals("jenkins.pipeline.list.action", extensionPoints.getJSONObject(2).get("extensionPoint"));
Assert.assertEquals("components/FavoritePipelineHeader", extensionPoints.getJSONObject(3).get("component"));
Assert.assertEquals("jenkins.pipeline.detail.header.action", extensionPoints.getJSONObject(3).get("extensionPoint"));
Assert.assertEquals("components/FavoritePipeline", extensionPoints.getJSONObject(4).get("component"));
Assert.assertEquals("jenkins.pipeline.branches.list.action", extensionPoints.getJSONObject(4).get("extensionPoint"));
}
}
// Calling JenkinsJSExtensions.getJenkinsJSExtensionData() multiple times should
// result in the same object instance being returned because the list of plugin
// has not changed i.e. we have a simple optimization in there where we only scan
// the classpath if the active plugin lust has changed.
Assert.assertEquals(JenkinsJSExtensions.getJenkinsJSExtensionData(), JenkinsJSExtensions.getJenkinsJSExtensionData());
}
use of net.sf.json.JSONArray in project summer-bean by cn-cerc.
the class RemoteService method exec.
@Override
public boolean exec(Object... args) {
if (args.length > 0) {
Record headIn = getDataIn().getHead();
if (args.length % 2 != 0)
throw new RuntimeException("传入的参数数量必须为偶数!");
for (int i = 0; i < args.length; i = i + 2) headIn.setField(args[i].toString(), args[i + 1]);
}
String postParam = getDataIn().getJSON();
String url = String.format("http://%s/services/%s", this.host, this.service);
if (token != null)
url = url + "?token=" + token;
try {
log.debug("datain: " + postParam);
// String rst = CURL.doPost(url, params, "UTF-8");
String rst = postData(url, postParam);
log.debug("datatout:" + rst);
if (rst == null)
return false;
JSONObject json = JSONObject.fromObject(rst);
if (json.get("message") != null) {
this.setMessage(json.getString("message"));
}
if (json.containsKey("data")) {
JSONArray datas = json.getJSONArray("data");
if (datas != null && datas.size() > 0) {
if (dataOut == null)
dataOut = new DataSet();
else
dataOut.close();
dataOut.setJSON(datas.getString(0));
}
}
return json.getBoolean("result");
} catch (Exception e) {
log.error(e.getMessage(), e);
if (e.getCause() != null)
setMessage(e.getCause().getMessage());
else
setMessage(e.getMessage());
return false;
}
}
use of net.sf.json.JSONArray in project compiler by boalang.
the class GetGitHubRepoNames method main.
public static void main(String[] args) {
File inDir = new File(Config.githubRepoListDir);
StringBuilder sb = new StringBuilder();
for (File file : inDir.listFiles()) {
if (file.getName().endsWith(".json")) {
String jsonTxt = "";
try {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[(int) file.length()];
in.read(bytes);
in.close();
jsonTxt = new String(bytes);
} catch (Exception e) {
System.err.println("Error reading file " + file.getAbsolutePath());
continue;
}
if (jsonTxt.isEmpty()) {
System.err.println("File is empty " + file.getAbsolutePath());
continue;
}
//System.out.println(jsonTxt);
JSONArray repos = null;
try {
repos = (JSONArray) JSONSerializer.toJSON(jsonTxt);
} catch (JSONException e) {
}
if (repos == null) {
System.err.println("Error parsing file " + file.getAbsolutePath());
continue;
}
for (int i = 0; i < repos.size(); i++) {
//System.out.println(repos.getJSONObject(i));
JSONObject repo = repos.getJSONObject(i);
String id = repo.getString("id");
String name = repo.getString("full_name");
System.out.println(id + ": " + name);
sb.append(id + "," + name + "\n");
//FileIO.writeFileContents(new File(Config.githubRepoMetadataDir + "/" + id + ".json"), repo.toString());
}
}
}
FileIO.writeFileContents(new File(inDir.getParentFile().getAbsolutePath() + "/list.csv"), sb.toString());
}
use of net.sf.json.JSONArray in project bamboobsc by billchen198318.
the class KpiReportCoffeeChartJsonDataCommand method setJsonData.
private void setJsonData(Context context, BscStructTreeObj treeObj) throws Exception {
if (treeObj == null || treeObj.getVisions() == null || treeObj.getVisions().size() != 1) {
return;
}
List<Map<String, Object>> rootList = new ArrayList<Map<String, Object>>();
Map<String, Object> rootDataMap = new HashMap<String, Object>();
List<Map<String, Object>> perspectivesDatas = new ArrayList<Map<String, Object>>();
List<VisionVO> visions = treeObj.getVisions();
VisionVO vision = visions.get(0);
for (PerspectiveVO perspective : vision.getPerspectives()) {
Map<String, Object> perspectiveDataMap = new HashMap<String, Object>();
List<Map<String, Object>> perspectiveChildren = new ArrayList<Map<String, Object>>();
perspectiveDataMap.put("name", this.getName(perspective.getName(), perspective.getScore()));
perspectiveDataMap.put("children", perspectiveChildren);
perspectiveDataMap.put("colour", perspective.getBgColor());
perspectiveDataMap.put("fontColor", perspective.getFontColor());
perspectiveDataMap.put("score", perspective.getScore());
perspectivesDatas.add(perspectiveDataMap);
for (ObjectiveVO objective : perspective.getObjectives()) {
Map<String, Object> objectiveDataMap = new HashMap<String, Object>();
List<Map<String, Object>> objectiveChildren = new ArrayList<Map<String, Object>>();
objectiveDataMap.put("name", this.getName(objective.getName(), objective.getScore()));
objectiveDataMap.put("children", objectiveChildren);
objectiveDataMap.put("colour", objective.getBgColor());
objectiveDataMap.put("fontColor", objective.getFontColor());
objectiveDataMap.put("score", objective.getScore());
perspectiveChildren.add(objectiveDataMap);
for (KpiVO kpi : objective.getKpis()) {
Map<String, Object> indicatorsDataMap = new HashMap<String, Object>();
indicatorsDataMap.put("name", this.getName(kpi.getName(), kpi.getScore()));
indicatorsDataMap.put("colour", kpi.getBgColor());
indicatorsDataMap.put("fontColor", kpi.getFontColor());
indicatorsDataMap.put("score", kpi.getScore());
objectiveChildren.add(indicatorsDataMap);
}
}
}
rootDataMap.put("name", this.getName(vision.getTitle(), vision.getScore()));
rootDataMap.put("children", perspectivesDatas);
rootDataMap.put("colour", vision.getBgColor());
rootDataMap.put("fontColor", vision.getFontColor());
rootDataMap.put("score", vision.getScore());
rootList.add(rootDataMap);
String jsonDataStr = ((JSONArray) JSONSerializer.toJSON(rootList)).toString();
this.setResult(context, jsonDataStr);
}
Aggregations