use of org.talend.utils.json.JSONArray in project tbd-studio-se by Talend.
the class NoSQLRepositoryContextHandlerTest method validateResult.
private void validateResult() throws Exception {
String dbName = noSqlConnection.getAttributes().get(INoSQLCommonAttributes.DATABASE);
assertEquals("context.Mongo_Database", dbName);
String replicaSet = noSqlConnection.getAttributes().get(IMongoDBAttributes.REPLICA_SET);
assertNotNull(replicaSet);
JSONArray jsa = new JSONArray(replicaSet);
assertTrue(jsa.length() > 0);
JSONObject jso = jsa.getJSONObject(0);
String contextHostName = jso.getString(IMongoConstants.REPLICA_HOST_KEY);
String contextPortName = jso.getString(IMongoConstants.REPLICA_PORT_KEY);
assertEquals("context.Mongo_ReplicaHost_1", contextHostName);
assertEquals("context.Mongo_ReplicaPort_1", contextPortName);
}
use of org.talend.utils.json.JSONArray in project tbd-studio-se by Talend.
the class HCatalogForm method initHadoopProperties.
// private void addHadoopPropertiesFields() {
// // table view
// Composite compositeTable = Form.startNewDimensionnedGridLayout(this, 1, this.getBorderWidth(), 150);
// GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
// gridData.horizontalSpan = 4;
// compositeTable.setLayoutData(gridData);
// CommandStackForComposite commandStack = new CommandStackForComposite(compositeTable);
// properties = new ArrayList<HashMap<String, Object>>();
// initHadoopProperties();
// HadoopPropertiesFieldModel model = new HadoopPropertiesFieldModel(properties, "Hadoop Properties");
// propertiesTableView = new HadoopPropertiesTableView(model, compositeTable);
// propertiesTableView.getExtendedTableViewer().setCommandStack(commandStack);
// final Composite fieldTableEditorComposite = propertiesTableView.getMainComposite();
// gridData = new GridData(GridData.FILL_HORIZONTAL);
// gridData.heightHint = 180;
// fieldTableEditorComposite.setLayoutData(gridData);
// fieldTableEditorComposite.setBackground(null);
// }
private void initHadoopProperties() {
String hadoopProperties = getConnection().getHadoopProperties();
try {
if (StringUtils.isNotEmpty(hadoopProperties)) {
JSONArray jsonArr = new JSONArray(hadoopProperties);
for (int i = 0; i < jsonArr.length(); i++) {
HashMap<String, Object> map = new HashMap();
JSONObject object = jsonArr.getJSONObject(i);
Iterator it = object.keys();
while (it.hasNext()) {
String key = (String) it.next();
map.put(key, object.get(key));
}
properties.add(map);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
use of org.talend.utils.json.JSONArray in project tbd-studio-se by Talend.
the class HDFSForm method initHadoopProperties.
private void initHadoopProperties() {
String hadoopProperties = getConnection().getHadoopProperties();
try {
if (StringUtils.isNotEmpty(hadoopProperties)) {
JSONArray jsonArr = new JSONArray(hadoopProperties);
for (int i = 0; i < jsonArr.length(); i++) {
HashMap<String, Object> map = new HashMap();
JSONObject object = jsonArr.getJSONObject(i);
Iterator it = object.keys();
while (it.hasNext()) {
String key = (String) it.next();
map.put(key, object.get(key));
}
properties.add(map);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
use of org.talend.utils.json.JSONArray in project tbd-studio-se by Talend.
the class MongoDBConnectionUtil method getReplicaSetList.
public static List<HashMap<String, Object>> getReplicaSetList(String replicaSetJsonStr, boolean includeQuotes) throws JSONException {
List<HashMap<String, Object>> replicaSet = new ArrayList<HashMap<String, Object>>();
if (StringUtils.isNotEmpty(replicaSetJsonStr)) {
JSONArray jsonArr = new JSONArray(replicaSetJsonStr);
for (int i = 0; i < jsonArr.length(); i++) {
HashMap<String, Object> map = new HashMap<String, Object>();
JSONObject object = jsonArr.getJSONObject(i);
Iterator<String> it = object.keys();
while (it.hasNext()) {
String key = StringUtils.trimToNull(it.next());
String value = StringUtils.trimToNull(String.valueOf(object.get(key)));
if (includeQuotes) {
value = TalendQuoteUtils.addQuotesIfNotExist(value);
} else {
value = TalendQuoteUtils.removeQuotesIfExist(value);
}
if (IMongoConstants.REPLICA_PORT_KEY.equals(key)) {
value = TalendQuoteUtils.removeQuotesIfExist(value);
}
map.put(key, value);
}
replicaSet.add(map);
}
}
return replicaSet;
}
use of org.talend.utils.json.JSONArray in project tbd-studio-se by Talend.
the class MongoDBReplicaFieldModel method getBeanListString.
public String getBeanListString() throws JSONException {
JSONArray jsonArr = new JSONArray();
for (HashMap<String, Object> map : getBeansList()) {
JSONObject object = new JSONObject();
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
object.put(key, map.get(key));
}
jsonArr.put(object);
}
return jsonArr.toString();
}
Aggregations