use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class DataCommandFunction method select_NonSelectResults.
private void select_NonSelectResults(Object results, List<SelectResultRow> list) {
if (logger.isDebugEnabled()) {
logger.debug("BeanResults : Bean Results class is {}", results.getClass());
}
String str = toJson(results);
GfJsonObject jsonBean;
try {
jsonBean = new GfJsonObject(str);
} catch (GfJsonException e) {
logger.info("Exception occurred:", e);
jsonBean = new GfJsonObject();
try {
jsonBean.put("msg", e.getMessage());
} catch (GfJsonException e1) {
logger.warn("Ignored GfJsonException:", e1);
}
}
if (logger.isDebugEnabled()) {
logger.debug("BeanResults : Adding bean json string : {}", jsonBean);
}
list.add(new SelectResultRow(DataCommandResult.ROW_TYPE_BEAN, jsonBean.toString()));
}
use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class DataCommandFunction method getJSONForNonPrimitiveObject.
@SuppressWarnings({ "rawtypes" })
public static Object[] getJSONForNonPrimitiveObject(Object obj) {
Object[] array = new Object[2];
if (obj == null) {
array[0] = null;
array[1] = "<NULL>";
return array;
} else {
array[0] = obj.getClass().getCanonicalName();
Class klass = obj.getClass();
if (JsonUtil.isPrimitiveOrWrapper(klass)) {
array[1] = obj;
} else if (obj instanceof PdxInstance) {
String str = pdxToJson((PdxInstance) obj);
array[1] = str;
} else {
GfJsonObject object = new GfJsonObject(obj, true);
Iterator keysIterator = object.keys();
while (keysIterator.hasNext()) {
String key = (String) keysIterator.next();
Object value = object.get(key);
if (GfJsonObject.isJSONKind(value)) {
GfJsonObject jsonVal = new GfJsonObject(value);
// System.out.println("Re-wrote inner object");
try {
if (jsonVal.has("type-class")) {
object.put(key, jsonVal.get("type-class"));
} else {
// Its Map Value
object.put(key, "a Map");
}
} catch (GfJsonException e) {
throw new RuntimeException(e);
}
} else if (value instanceof JSONArray) {
// Its a collection either a set or list
try {
object.put(key, "a Collection");
} catch (GfJsonException e) {
throw new RuntimeException(e);
}
}
}
String str = object.toString();
array[1] = str;
}
return array;
}
}
use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class DataCommandFunctionWithPDXJUnitTest method testVerifyDataDoesNotShift.
@Test
public void testVerifyDataDoesNotShift() throws Exception {
TabularResultData rawTable = getTableFromQuery("select * from /" + PARTITIONED_REGION + " order by id");
// Verify any table built
assertThat(rawTable.getGfJsonObject()).isNotNull();
assertThat(rawTable.getGfJsonObject().getJSONObject("content")).isNotNull();
GfJsonObject tableJson = rawTable.getGfJsonObject().getJSONObject("content");
// Table only contains correct keys
assertThat(tableJson.getJSONArray("missingKey")).isNull();
// Table contains correct data
assertThatRowIsBuiltCorrectly(tableJson, 0, alice);
assertThatRowIsBuiltCorrectly(tableJson, 1, bob);
assertThatRowIsBuiltCorrectly(tableJson, 2, charlie);
assertThatRowIsBuiltCorrectly(tableJson, 3, dan);
}
use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class DataCommandFunctionWithPDXJUnitTest method testFilteredQueryWithoutPhone.
@Test
public void testFilteredQueryWithoutPhone() throws Exception {
TabularResultData rawTable = getTableFromQuery("select * from /" + PARTITIONED_REGION + " c where IS_UNDEFINED ( c.phone ) order by id");
assertThat(rawTable.getGfJsonObject()).isNotNull();
assertThat(rawTable.getGfJsonObject().getJSONObject("content")).isNotNull();
GfJsonObject tableJson = rawTable.getGfJsonObject().getJSONObject("content");
for (String k : new String[] { "id", "firstName", "lastName" }) {
assertThat(tableJson.getJSONArray(k).size()).isEqualTo(2);
}
assertThatRowIsBuiltCorrectly(tableJson, 0, alice);
assertThatRowIsBuiltCorrectly(tableJson, 1, bob);
}
Aggregations