use of org.apache.geode.management.internal.cli.json.GfJsonArray in project geode by apache.
the class JsonUtil method getList.
public static List<CliJsonSerializable> getList(GfJsonObject jsonObject, String byName) {
List<CliJsonSerializable> cliJsonSerializables = Collections.emptyList();
try {
GfJsonArray cliJsonSerializableArray = jsonObject.getJSONArray(byName);
int size = cliJsonSerializableArray.size();
if (size > 0) {
cliJsonSerializables = new ArrayList<CliJsonSerializable>();
}
for (int i = 0; i < size; i++) {
GfJsonObject cliJsonSerializableState = cliJsonSerializableArray.getJSONObject(i);
int jsId = cliJsonSerializableState.getInt(CliJsonSerializable.JSID);
CliJsonSerializable cliJsonSerializable = CliJsonSerializableFactory.getCliJsonSerializable(jsId);
cliJsonSerializable.fromJson(cliJsonSerializableState);
cliJsonSerializables.add(cliJsonSerializable);
}
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
return cliJsonSerializables;
}
use of org.apache.geode.management.internal.cli.json.GfJsonArray in project geode by apache.
the class JsonUtil method getSet.
public static Set<CliJsonSerializable> getSet(GfJsonObject jsonObject, String byName) {
Set<CliJsonSerializable> cliJsonSerializables = Collections.emptySet();
try {
GfJsonArray cliJsonSerializableArray = jsonObject.getJSONArray(byName);
int size = cliJsonSerializableArray.size();
if (size > 0) {
cliJsonSerializables = new HashSet<CliJsonSerializable>();
}
for (int i = 0; i < size; i++) {
GfJsonObject cliJsonSerializableState = cliJsonSerializableArray.getJSONObject(i);
int jsId = cliJsonSerializableState.getInt(CliJsonSerializable.JSID);
CliJsonSerializable cliJsonSerializable = CliJsonSerializableFactory.getCliJsonSerializable(jsId);
cliJsonSerializable.fromJson(cliJsonSerializableState);
cliJsonSerializables.add(cliJsonSerializable);
}
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
return cliJsonSerializables;
}
use of org.apache.geode.management.internal.cli.json.GfJsonArray in project geode by apache.
the class ObjectResultData method getAllObjects.
public List<CliJsonSerializable> getAllObjects() {
List<CliJsonSerializable> list = new ArrayList<CliJsonSerializable>();
try {
GfJsonArray rootJsonArray = contentObject.getJSONArray(OBJECTS_ACCESSOR);
int size = rootJsonArray.size();
GfJsonObject jsonObject = null;
CliJsonSerializable cliJsonSerializable = null;
for (int i = 0; i < size; i++) {
jsonObject = rootJsonArray.getJSONObject(i);
cliJsonSerializable = CliJsonSerializableFactory.getCliJsonSerializable(jsonObject.getInt(CliJsonSerializable.JSID));
cliJsonSerializable.fromJson(jsonObject);
list.add(cliJsonSerializable);
}
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
return list;
}
use of org.apache.geode.management.internal.cli.json.GfJsonArray in project geode by apache.
the class CommandResult method buildTable.
/**
* @param rowGroup
* @param content
* @throws GfJsonException
*/
private void buildTable(RowGroup rowGroup, GfJsonObject content) throws GfJsonException {
GfJsonArray columnNames = content.names();
int numOfColumns = columnNames.size();
Row headerRow = rowGroup.newRow();
rowGroup.setColumnSeparator(" | ");
rowGroup.newRowSeparator('-', false);
// build Table Header first
for (int i = 0; i < numOfColumns; i++) {
Object object = columnNames.get(i);
if (AbstractResultData.BYTE_DATA_ACCESSOR.equals(object)) {
// skip file data if any //TODO - make response format better
continue;
}
headerRow.newCenterCol((String) object);
}
// Build remaining rows by extracting data column-wise from JSON object
Row[] dataRows = null;
for (int i = 0; i < numOfColumns; i++) {
Object object = columnNames.get(i);
if (AbstractResultData.BYTE_DATA_ACCESSOR.equals(object)) {
// skip file data if any //TODO - make response format better
continue;
}
GfJsonArray accumulatedData = content.getJSONArray((String) object);
dataRows = buildRows(rowGroup, dataRows, accumulatedData);
}
}
use of org.apache.geode.management.internal.cli.json.GfJsonArray in project geode by apache.
the class CommandResult method buildObjectSection.
private void buildObjectSection(Table table, RowGroup parentRowGroup, GfJsonObject object, int depth) throws GfJsonException {
Iterator<String> keys = object.keys();
RowGroup rowGroup = null;
if (parentRowGroup != null) {
rowGroup = parentRowGroup;
} else {
rowGroup = table.newRowGroup();
}
GfJsonArray nestedCollection = null;
GfJsonObject nestedObject = null;
GfJsonObject fieldDisplayNames = object.getJSONObject(CliJsonSerializable.FIELDS_TO_DISPLAYNAME_MAPPING);
List<String> fieldsToSkipOnUI = null;
if (object.has(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI)) {
GfJsonArray jsonArray = object.getJSONArray(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI);
;
fieldsToSkipOnUI = new ArrayList<String>();
for (int i = 0; i < jsonArray.size(); i++) {
fieldsToSkipOnUI.add(String.valueOf(jsonArray.get(i)));
}
}
while (keys.hasNext()) {
String key = keys.next();
if (CliJsonSerializable.FIELDS_TO_SKIP.contains(key) || (fieldsToSkipOnUI != null && fieldsToSkipOnUI.contains(key))) {
continue;
}
try {
nestedCollection = object.getJSONArray(key);
} catch (GfJsonException e) {
/* next check if it's a nested object */
}
Object field = null;
if (nestedCollection == null) {
field = object.get(key);
if (!isPrimitiveOrStringOrWrapper(field)) {
nestedObject = object.getJSONObject(key);
}
}
if (nestedCollection != null && isPrimitiveOrStringOrWrapperArray(nestedCollection)) {
String str = nestedCollection.toString();
field = str.substring(1, str.length() - 1);
nestedCollection = null;
}
Row newRow = rowGroup.newRow();
String prefix = "";
/* if (nestedCollection != null) */
{
for (int i = 0; i < depth; i++) {
prefix += " . ";
}
}
String fieldNameToDisplay = fieldDisplayNames.getString(key);
if (nestedCollection == null) {
newRow.newLeftCol(prefix + fieldNameToDisplay);
}
if (nestedCollection != null) {
Map<String, Integer> columnsMap = new HashMap<String, Integer>();
GfJsonArray rowsArray = nestedCollection;
RowGroup newRowGroup = table.newRowGroup();
newRowGroup.setColumnSeparator(" | ");
newRowGroup.newBlankRow();
newRowGroup.newRow().newLeftCol(fieldNameToDisplay);
Row headerRow = newRowGroup.newRow();
int numOfRows = rowsArray.size();
List<String> tableFieldsToSkipOnUI = null;
for (int j = 0; j < numOfRows; j++) {
GfJsonObject content = rowsArray.getJSONObject(j);
if (content.has(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI)) {
GfJsonArray jsonArray = content.getJSONArray(CliJsonSerializable.FIELDS_TO_SKIP_ON_UI);
tableFieldsToSkipOnUI = new ArrayList<String>();
for (int i = 0; i < jsonArray.size(); i++) {
tableFieldsToSkipOnUI.add(String.valueOf(jsonArray.get(i)));
}
}
GfJsonArray columnNames = content.names();
int numOfColumns = columnNames.size();
if (headerRow.isEmpty()) {
GfJsonObject innerFieldDisplayNames = content.getJSONObject(CliJsonSerializable.FIELDS_TO_DISPLAYNAME_MAPPING);
for (int i = 0; i < numOfColumns; i++) {
Object columnName = columnNames.get(i);
if (CliJsonSerializable.FIELDS_TO_SKIP.contains((String) columnName) || (tableFieldsToSkipOnUI != null && tableFieldsToSkipOnUI.contains(columnName))) {
// skip file data if any //TODO - make response format better
continue;
}
headerRow.newCenterCol(innerFieldDisplayNames.getString((String) columnName));
columnsMap.put((String) columnName, i);
}
newRowGroup.newRowSeparator('-', false);
}
newRow = newRowGroup.newRow();
for (int i = 0; i < numOfColumns; i++) {
Object columnName = columnNames.get(i);
if (CliJsonSerializable.FIELDS_TO_SKIP.contains((String) columnName) || (tableFieldsToSkipOnUI != null && tableFieldsToSkipOnUI.contains(columnName))) {
// skip file data if any //TODO - make response format better
continue;
}
newRow.newLeftCol(String.valueOf(content.get((String) columnName)));
}
}
} else if (nestedObject != null) {
buildObjectSection(table, rowGroup, nestedObject, depth + 1);
} else {
// Row newRow = rowGroup.newRow();
// String prefix = "";
// for (int i = 0; i < depth; i++) {
// prefix += " . ";
// }
// newRow.newLeftCol(prefix+fieldDisplayNames.getString(key)).newLeftCol(field);
Object value = field;
/*
* if (isPrimitiveOrStringOrWrapperArray(value)) { value = Arrays.toString((String[])value);
* }
*/
newRow.newLeftCol(value);
}
nestedCollection = null;
nestedObject = null;
}
}
Aggregations