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