Search in sources :

Example 1 with GfJsonArray

use of org.apache.geode.management.internal.cli.json.GfJsonArray 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 GfJsonArray

use of org.apache.geode.management.internal.cli.json.GfJsonArray 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 GfJsonArray

use of org.apache.geode.management.internal.cli.json.GfJsonArray 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 GfJsonArray

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;
}
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 GfJsonArray

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;
}
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)

Aggregations

GfJsonArray (org.apache.geode.management.internal.cli.json.GfJsonArray)17 GfJsonException (org.apache.geode.management.internal.cli.json.GfJsonException)14 GfJsonObject (org.apache.geode.management.internal.cli.json.GfJsonObject)10 ResultDataException (org.apache.geode.management.internal.cli.result.ResultDataException)4 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)4 ArrayList (java.util.ArrayList)3 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)3 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)3 CliJsonSerializable (org.apache.geode.management.internal.cli.result.CliJsonSerializable)2 Row (org.apache.geode.management.internal.cli.result.TableBuilder.Row)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DataFormatException (java.util.zip.DataFormatException)1 DeflaterInflaterData (org.apache.geode.management.internal.cli.CliUtil.DeflaterInflaterData)1