/** * Get a writable JsonObject for the parent of the indicated ID. * * This method will ensure that the identified node exists and that the * object returned is writable and has the ID'd node as a child. * * @param id : The node ID to find the parent of. * @return JsonObject : A writable JsonObject */ private JsonObject getWritableParent(String id) { // Find this node ManifestNode node = getNode(id); if (node == null) { return null; } // Find the parent String pId = node.getParentKey(); JsonObject target = getWritableNode(pId); // Confirm our data if (target == null || !target.containsKey(id)) { return null; } return target; }
public boolean move(String id, String destination) { // Find our nodes JsonObject toRemove = getWritableParent(id); JsonObject toMove = getWritableNode(destination); // Confirm validity of request if (toRemove == null || toMove == null) { return false; } // Now actually move it toMove.put(id, toRemove.get(id)); toRemove.remove(id); // Update metadata getNode(id).setParentKey(destination); return true; }