use of net.sf.json.JSON 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.JSON in project tdi-studio-se by Talend.
the class Test method main.
/**
* DOC wanghong Comment method "main".
*
* @param args
*/
public static void main(String[] args) {
try {
File file = new File("D:/CLOUD_BPM_EE_MPX_generated.json");
FileInputStream input = new FileInputStream(file);
String jsonData = IOUtils.toString(input);
XMLSerializer serializer = new XMLSerializer();
JSON json = JSONSerializer.toJSON(jsonData);
serializer.setRootName("JSONRoot");
serializer.setTypeHintsEnabled(false);
String xml = serializer.write(json);
// System.out.println(xml);
FileWriter writer = new FileWriter("D:/CLOUD.xml");
writer.write(xml);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of net.sf.json.JSON in project jmeter-plugins-manager by undera.
the class RepoTest method testAll.
public void testAll() throws IOException {
Map<String, String> env = System.getenv();
if (env.containsKey("TRAVIS")) {
System.out.println("Not running test inside Travis CI");
return;
}
List<String> problems = new ArrayList<>();
File[] files = getRepoFiles();
JSONArray merged = new JSONArray();
for (File repoFile : files) {
System.out.println("Checking repo: " + repoFile.getCanonicalPath());
String content = new String(Files.readAllBytes(Paths.get(repoFile.getAbsolutePath())), "UTF-8");
JSON json = JSONSerializer.toJSON(content, new JsonConfig());
JSONArray list = (JSONArray) json;
for (Object item : list) {
JSONObject spec = (JSONObject) item;
checkPlugin(problems, repoFile, spec);
merged.add(spec);
}
}
if (problems.size() > 0) {
throw new AssertionFailedError(problems.toString());
}
try (PrintWriter out = new PrintWriter(new File(repo.getAbsolutePath() + s + "all.json"))) {
out.print(merged.toString(1));
}
}
use of net.sf.json.JSON in project jmeter-plugins-manager by undera.
the class PluginManager method load.
public synchronized void load() throws Throwable {
detectJARConflicts();
if (hasPlugins()) {
return;
}
JSON json = jarSource.getRepo();
if (!(json instanceof JSONArray)) {
throw new RuntimeException("Result is not array");
}
for (Object elm : (JSONArray) json) {
if (elm instanceof JSONObject) {
Plugin plugin = Plugin.fromJSON((JSONObject) elm);
if (plugin.getName().isEmpty()) {
log.debug("Skip empty name: " + plugin);
continue;
}
if (!plugin.isVirtual()) {
plugin.detectInstalled(getInstalledPlugins());
}
allPlugins.put(plugin, plugin.isInstalled());
} else {
log.warn("Invalid array element: " + elm);
}
}
// after all usual plugins detected, detect virtual sets
for (Plugin plugin : allPlugins.keySet()) {
if (plugin.isVirtual()) {
plugin.detectInstalled(getInstalledPlugins());
allPlugins.put(plugin, plugin.isInstalled());
}
}
if (JMeterUtils.getPropDefault("jpgc.repo.sendstats", "true").equals("true")) {
try {
jarSource.reportStats(getUsageStats());
} catch (Exception e) {
log.debug("Failed to report usage stats", e);
}
}
log.info("Plugins Status: " + getAllPluginsStatusString());
}
use of net.sf.json.JSON in project selenium_java by sergueik.
the class Comment method update.
/**
* Updates the comment body with limited visibility.
*
* @param issue associated issue record
* @param body Comment text
* @param visType Target audience type (role or group)
* @param visName Name of the role or group to limit visibility to
*
* @throws JiraException when the comment update fails
*/
public void update(String body, String visType, String visName) throws JiraException {
JSONObject req = new JSONObject();
req.put("body", body);
if (visType != null && visName != null) {
JSONObject vis = new JSONObject();
vis.put("type", visType);
vis.put("value", visName);
req.put("visibility", vis);
}
JSON result = null;
try {
String issueUri = getBaseUri() + "issue/" + issueKey;
result = restclient.put(issueUri + "/comment/" + id, req);
} catch (Exception ex) {
throw new JiraException("Failed add update comment " + id, ex);
}
if (!(result instanceof JSONObject)) {
throw new JiraException("JSON payload is malformed");
}
deserialise((JSONObject) result);
}
Aggregations