Search in sources :

Example 1 with JSONException

use of org.neo4j.shell.util.json.JSONException in project neo4j by neo4j.

the class AbstractApp method parseArray.

protected static Object[] parseArray(String string) {
    try {
        JSONArray array = new JSONArray(string);
        Object[] result = new Object[array.length()];
        for (int i = 0; i < result.length; i++) {
            result[i] = array.get(i);
        }
        return result;
    } catch (JSONException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
Also used : JSONArray(org.neo4j.shell.util.json.JSONArray) JSONException(org.neo4j.shell.util.json.JSONException) JSONObject(org.neo4j.shell.util.json.JSONObject)

Example 2 with JSONException

use of org.neo4j.shell.util.json.JSONException in project neo4j by neo4j.

the class TransactionProvidingApp method jsonToNeo4jPropertyValue.

private Object jsonToNeo4jPropertyValue(Object value) throws ShellException {
    try {
        if (value instanceof JSONArray) {
            JSONArray array = (JSONArray) value;
            Object firstItem = array.get(0);
            Object resultArray = Array.newInstance(firstItem.getClass(), array.length());
            for (int i = 0; i < array.length(); i++) {
                Array.set(resultArray, i, array.get(i));
            }
            return resultArray;
        }
        return value;
    } catch (JSONException e) {
        throw new ShellException(stackTraceAsString(e));
    }
}
Also used : JSONArray(org.neo4j.shell.util.json.JSONArray) JSONException(org.neo4j.shell.util.json.JSONException) ShellException(org.neo4j.shell.ShellException)

Example 3 with JSONException

use of org.neo4j.shell.util.json.JSONException in project neo4j by neo4j.

the class Dbinfo method printAttribute.

private void printAttribute(JSONObject json, Object value) throws RemoteException, ShellException {
    try {
        Attribute attribute = (Attribute) value;
        Object attributeValue = attribute.getValue();
        if (attributeValue != null && attributeValue.getClass().isArray()) {
            Object[] arrayValue = (Object[]) attributeValue;
            JSONArray array = new JSONArray();
            for (Object item : (Object[]) arrayValue) {
                if (item instanceof CompositeData) {
                    array.put(compositeDataAsMap((CompositeData) item));
                } else {
                    array.put(item.toString());
                }
            }
            json.put(attribute.getName(), array);
        } else {
            json.put(attribute.getName(), attributeValue);
        }
    } catch (JSONException e) {
        throw ShellException.wrapCause(e);
    }
}
Also used : Attribute(javax.management.Attribute) CompositeData(javax.management.openmbean.CompositeData) JSONArray(org.neo4j.shell.util.json.JSONArray) JSONException(org.neo4j.shell.util.json.JSONException) JSONObject(org.neo4j.shell.util.json.JSONObject)

Example 4 with JSONException

use of org.neo4j.shell.util.json.JSONException in project neo4j by neo4j.

the class IndexProviderShellApp method createIndex.

private void createIndex(AppCommandParser parser, Output out) throws RemoteException, ShellException {
    String indexName = getIndexName(parser);
    Class<? extends PropertyContainer> entityType = getEntityType(parser);
    if (getIndex(indexName, entityType, null) != null) {
        out.println(entityType.getClass().getSimpleName() + " index '" + indexName + "' already exists");
        return;
    }
    Map config;
    try {
        config = parser.arguments().size() >= 2 ? parseJSONMap(parser.arguments().get(1)) : null;
    } catch (JSONException e) {
        throw ShellException.wrapCause(e);
    }
    if (entityType.equals(Node.class)) {
        Index<Node> index = config != null ? getServer().getDb().index().forNodes(indexName, config) : getServer().getDb().index().forNodes(indexName);
    } else {
        Index<Relationship> index = config != null ? getServer().getDb().index().forRelationships(indexName, config) : getServer().getDb().index().forRelationships(indexName);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) JSONException(org.neo4j.shell.util.json.JSONException) Map(java.util.Map)

Aggregations

JSONException (org.neo4j.shell.util.json.JSONException)4 JSONArray (org.neo4j.shell.util.json.JSONArray)3 JSONObject (org.neo4j.shell.util.json.JSONObject)2 Map (java.util.Map)1 Attribute (javax.management.Attribute)1 CompositeData (javax.management.openmbean.CompositeData)1 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1 ShellException (org.neo4j.shell.ShellException)1