use of org.talend.utils.json.JSONObject in project tbd-studio-se by Talend.
the class DefaultConfigurationManagerTest method testGetValue_NotExisted.
@Test
public void testGetValue_NotExisted() throws JSONException {
JSONObject json = new JSONObject();
json.put("key1", "123");
assertNull(DefaultConfigurationManager.getValue(json, "abc"));
}
use of org.talend.utils.json.JSONObject in project tbd-studio-se by Talend.
the class DefaultConfigurationManagerTest method testGetValue_Whole.
@Test
public void testGetValue_Whole() throws JSONException {
JSONObject json = new JSONObject();
json.put("key1", "123");
String value = DefaultConfigurationManager.getValue(json, "");
assertNotNull(value);
JSONObject getJson = null;
try {
getJson = new JSONObject(value);
} catch (JSONException e) {
//
}
assertNotNull("Can't get the whole JSON", getJson);
assertTrue(getJson.has("key1"));
assertEquals("123", getJson.getString("key1"));
}
use of org.talend.utils.json.JSONObject in project tbd-studio-se by Talend.
the class AbstractTest4DefaultConfiguration method testDefaultConfiguration_Existed.
// @Test
public void testDefaultConfiguration_Existed() throws JSONException {
HadoopComponent hadoopComponent = getHadoopComponent();
final String distribution = hadoopComponent.getDistribution();
String version = hadoopComponent.getVersion();
if (version == null) {
version = "";
}
String notFoundMessages = MessageFormat.format("The default configuration of the version \"{0}\" for \"{1}\" is not found", version, distribution);
// get all
String wholeConfig = hadoopComponent.getDefaultConfig(distribution, "");
assertNotNull(notFoundMessages, wholeConfig);
JSONObject wholeJson = new JSONObject(wholeConfig);
// should existed one key at least.
assertTrue(notFoundMessages, wholeJson.length() > 0);
}
use of org.talend.utils.json.JSONObject in project tdi-studio-se by Talend.
the class JsonTableHandler method getDataRowList.
private List<List<Object>> getDataRowList(JSONObject rootObj, AtomicInteger columnsCount) throws JSONException {
List<List<Object>> rows = new ArrayList<>();
AtomicInteger count = columnsCount;
if (count == null) {
count = new AtomicInteger();
}
JSONArray jsonArr = rootObj.getJSONArray(DATA_KEY);
for (int i = 0; i < jsonArr.length(); i++) {
List<Object> row = new ArrayList<>();
JSONArray rowArray = jsonArr.getJSONArray(i);
for (int j = 0; j < rowArray.length(); j++) {
row.add(rowArray.get(j));
}
if (row.size() > count.get()) {
count.set(row.size());
}
rows.add(row);
}
return rows;
}
use of org.talend.utils.json.JSONObject in project tdi-studio-se by Talend.
the class JsonTableHandler method parse.
public JsonTableVO parse(String jsonStr) {
JsonTableVO vo = null;
try {
JSONObject rootObj = new JSONObject(jsonStr);
List<String> columnTitles = getColumnNames(rootObj);
AtomicInteger maxColumnsCount = new AtomicInteger();
List<List<Object>> dataRowList = getDataRowList(rootObj, maxColumnsCount);
if (columnTitles.size() == 0) {
columnTitles = getColumnTitles(maxColumnsCount.get());
}
vo = buildVO(columnTitles, dataRowList);
} catch (Exception e) {
//$NON-NLS-1$
log.warn(Messages.getString("JsonTableHandler.parse.warnMsg", jsonStr), e);
}
return vo;
}
Aggregations