Search in sources :

Example 1 with GfJsonException

use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.

the class CommandResult method buildObjectResultOutput.

/* private */
void buildObjectResultOutput() {
    try {
        Table resultTable = TableBuilder.newTable();
        resultTable.setColumnSeparator(" : ");
        addHeaderInTable(resultTable, getGfJsonObject());
        GfJsonObject content = getContent();
        GfJsonArray objectsArray = content.getJSONArray(ObjectResultData.OBJECTS_ACCESSOR);
        if (objectsArray != null) {
            int numOfObjects = objectsArray.size();
            for (int i = 0; i < numOfObjects; i++) {
                GfJsonObject object = objectsArray.getJSONObject(i);
                buildObjectSection(resultTable, null, object, 0);
            }
        }
        /*
         * else { // GfJsonObject jsonObject =
         * content.getJSONObject(ObjectResultData.ROOT_OBJECT_ACCESSOR); //
         * buildObjectSection(resultTable, null, jsonObject, 0); }
         */
        addFooterInTable(resultTable, getGfJsonObject());
        resultLines.addAll(resultTable.buildTableList());
    } catch (GfJsonException e) {
        resultLines.add("Error occurred while processing Command Result. Internal Error - Invalid Result.");
    // TODO - Abhishek. Add stack trace when 'debug' is enabled. Log to LogWrapper always
    } finally {
        isDataBuilt = true;
    }
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) Table(org.apache.geode.management.internal.cli.result.TableBuilder.Table) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Example 2 with GfJsonException

use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.

the class TabularResultData method retrieveAllValues.

public List<String> retrieveAllValues(String columnName) {
    List<String> values = new ArrayList<>();
    try {
        GfJsonArray jsonArray = contentObject.getJSONArray(columnName);
        int size = jsonArray.size();
        for (int i = 0; i < size; i++) {
            values.add(String.valueOf(jsonArray.get(i)));
        }
    } catch (GfJsonException e) {
        throw new ResultDataException(e.getMessage());
    }
    return values;
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) ArrayList(java.util.ArrayList) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Example 3 with GfJsonException

use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.

the class JsonUtil method getStringArray.

public static String[] getStringArray(GfJsonObject jsonObject, String byName) {
    String[] stringArray = null;
    try {
        GfJsonArray jsonArray = jsonObject.getJSONArray(byName);
        stringArray = GfJsonArray.toStringArray(jsonArray);
    } catch (GfJsonException e) {
        throw new ResultDataException(e.getMessage());
    }
    return stringArray;
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

Example 4 with GfJsonException

use of org.apache.geode.management.internal.cli.json.GfJsonException 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;
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) CliJsonSerializable(org.apache.geode.management.internal.cli.result.CliJsonSerializable)

Example 5 with GfJsonException

use of org.apache.geode.management.internal.cli.json.GfJsonException in project geode by apache.

the class JsonUtil method objectToJsonNestedChkCDep.

private static String objectToJsonNestedChkCDep(Object object, int length, boolean checkCyclicDep) {
    GfJsonObject jsonObject = new GfJsonObject(object, checkCyclicDep);
    Iterator<String> iterator = jsonObject.keys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value = jsonObject.get(key);
        if (value != null && !isPrimitiveOrWrapper(value.getClass())) {
            GfJsonObject jsonified = new GfJsonObject(value);
            String stringified = jsonified.toString();
            try {
                if (stringified.length() > length) {
                    jsonObject.put(key, jsonified.getType());
                } else {
                    jsonObject.put(key, stringified);
                }
            } catch (GfJsonException e) {
                e.printStackTrace();
            }
        }
    }
    return jsonObject.toString();
}
Also used : GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) JSONObject(org.json.JSONObject) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject)

Aggregations

GfJsonException (org.apache.geode.management.internal.cli.json.GfJsonException)34 GfJsonObject (org.apache.geode.management.internal.cli.json.GfJsonObject)27 GfJsonArray (org.apache.geode.management.internal.cli.json.GfJsonArray)14 JSONObject (org.json.JSONObject)9 ArrayList (java.util.ArrayList)6 ResultDataException (org.apache.geode.management.internal.cli.result.ResultDataException)4 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 HashMap (java.util.HashMap)3 SelectResultRow (org.apache.geode.management.internal.cli.domain.DataCommandResult.SelectResultRow)3 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)3 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CliJsonSerializable (org.apache.geode.management.internal.cli.result.CliJsonSerializable)2 Table (org.apache.geode.management.internal.cli.result.TableBuilder.Table)2