use of org.neo4j.shell.ShellException in project neo4j by neo4j.
the class Rmnode method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
NodeOrRelationship node = null;
if (parser.arguments().isEmpty()) {
node = getCurrent(session);
} else {
long id = parseInt(parser.arguments().get(0));
try {
node = wrap(getNodeById(id));
} catch (NotFoundException e) {
throw new ShellException("No node " + id + " found");
}
}
if (!node.isNode()) {
out.println("Please select a node to delete");
return Continuation.INPUT_COMPLETE;
}
boolean forceDeletion = parser.options().containsKey("f");
if (forceDeletion) {
for (Relationship relationship : node.asNode().getRelationships()) {
out.println("Relationship " + getDisplayName(getServer(), session, relationship, true, false) + " deleted");
relationship.delete();
}
}
if (node.asNode().hasRelationship()) {
throw new ShellException(getDisplayName(getServer(), session, node.asNode(), false) + " cannot be deleted because it still has relationships. Use -f to force deletion of its relationships");
}
node.asNode().delete();
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.shell.ShellException in project neo4j by neo4j.
the class Rmrel method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
assertCurrentIsNode(session);
if (parser.arguments().isEmpty()) {
throw new ShellException("Must supply relationship id to delete as the first argument");
}
Node currentNode = this.getCurrent(session).asNode();
Relationship rel = findRel(currentNode, Long.parseLong(parser.arguments().get(0)));
rel.delete();
Node otherNode = rel.getOtherNode(currentNode);
boolean deleteOtherNodeIfEmpty = parser.options().containsKey("d");
if (deleteOtherNodeIfEmpty && !otherNode.hasRelationship()) {
out.println("Also deleted " + getDisplayName(getServer(), session, otherNode, false) + " due to it not having any relationships left");
otherNode.delete();
}
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.shell.ShellException 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.ShellException in project neo4j by neo4j.
the class IndexProviderShellApp method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
boolean doCd = parser.options().containsKey("cd");
boolean doLs = parser.options().containsKey("ls");
boolean query = parser.options().containsKey("q");
boolean get = parser.options().containsKey("g") || query || doCd || doLs;
boolean index = parser.options().containsKey("i");
boolean remove = parser.options().containsKey("r");
boolean getConfig = parser.options().containsKey("get-config");
boolean create = parser.options().containsKey("create");
boolean setConfig = parser.options().containsKey("set-config");
boolean delete = parser.options().containsKey("delete");
boolean indexes = parser.options().containsKey("indexes");
int count = boolCount(get, index, remove, getConfig, create, setConfig, delete, indexes);
if (count != 1) {
throw new ShellException("Supply one of: -g, -i, -r, --get-config, --set-config, --create, --delete, --indexes");
}
if (get) {
String commandToRun = parser.options().get("c");
Collection<String> commandsToRun = new ArrayList<String>();
boolean specialCommand = false;
if (doCd || doLs) {
specialCommand = true;
if (doCd) {
commandsToRun.add("cd -a $i");
} else if (doLs) {
commandsToRun.add("ls $i");
}
} else if (commandToRun != null) {
commandsToRun.addAll(Arrays.asList(commandToRun.split(Pattern.quote("&&"))));
}
if (getIndex(getIndexName(parser), getEntityType(parser), out) == null) {
return Continuation.INPUT_COMPLETE;
}
IndexHits<PropertyContainer> result = query ? query(parser, out) : get(parser, out);
try {
for (PropertyContainer hit : result) {
printAndInterpretTemplateLines(commandsToRun, false, !specialCommand, NodeOrRelationship.wrap(hit), getServer(), session, out);
}
} finally {
result.close();
}
} else if (index) {
index(parser, session, out);
} else if (remove) {
if (getIndex(getIndexName(parser), Node.class, out) == null) {
return null;
}
remove(parser, session, out);
} else if (getConfig) {
displayConfig(parser, out);
} else if (create) {
createIndex(parser, out);
} else if (setConfig) {
setConfig(parser, out);
} else if (delete) {
deleteIndex(parser, out);
}
if (indexes) {
listIndexes(out);
}
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.shell.ShellException in project neo4j by neo4j.
the class Rm method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws Exception {
NodeOrRelationship thing = getCurrent(session);
boolean forProperty = parser.options().containsKey("p");
boolean forLabel = parser.options().containsKey("l");
if (forProperty || !forLabel) {
// Property
if (parser.arguments().isEmpty()) {
throw new ShellException("Must supply the property key or label name to " + "remove, like: rm title");
}
String key = parser.arguments().get(0);
if (thing.removeProperty(key) == null) {
out.println("Property '" + key + "' not found");
}
} else {
Node node = thing.asNode();
for (Label label : parseLabels(parser)) {
node.removeLabel(label);
}
}
return Continuation.INPUT_COMPLETE;
}
Aggregations