Source:
public StringBuilder setParent() throws OrmException { final StringBuilder err = new StringBuilder(); final Set<Project.NameKey> grandParents = new HashSet<Project.NameKey>(); Project.NameKey newParentKey; grandParents.add(wildProject); if (parentName != null && !parentName.isEmpty() && !parentName.equals(wildProject.get())) { newParentKey = new Project.NameKey(parentName); final ProjectState state = projectCache.get(newParentKey); Project.NameKey grandParent = null; if (state != null) { grandParent = state.getProject().getParent(); } while (grandParent != null && !grandParent.equals(wildProject)) { grandParents.add(grandParent); final ProjectState s = projectCache.get(grandParent); if (s != null) { grandParent = s.getProject().getParent(); } else { break; } } } else { newParentKey = null; } int numberOfFailedProjects = 0; for (final Project.NameKey pc : childProjects) { final String name = pc.get(); if (wildProject.equals(pc)) { err.append("error: Cannot set parent of '" + name + "'\n"); numberOfFailedProjects++; continue; } if (grandParents.contains(pc) || pc.equals(newParentKey)) { err.append("error: Cycle exists between '" + name + "' and '" + (newParentKey != null ? newParentKey.get() : wildProject.get()) + "'\n"); numberOfFailedProjects++; continue; } final Project child = db.projects().get(pc); if (child == null) { err.append("error: Project '" + name + "' not found\n"); numberOfFailedProjects++; continue; } child.setParent(newParentKey); db.projects().update(Collections.singleton(child)); } projectCache.evictAll(); if (numberOfFailedProjects == childProjects.size()) { err.append("All:"); } return err; }

Target:
public void setParent() throws OrmException, NoSuchProjectException, OperationNotExecutedException { final StringBuilder err = new StringBuilder(); final Set<Project.NameKey> grandParents = new HashSet<Project.NameKey>(); if (parentNameKey.equals(wildProject)) { parentNameKey = null; } grandParents.add(wildProject); if (parentNameKey != null) { final ProjectState state = projectCache.get(parentNameKey); Project.NameKey grandParent = null; if (state != null) { grandParent = state.getProject().getParent(); } else { throw new NoSuchProjectException(parentNameKey); } while (grandParent != null && !grandParent.equals(wildProject)) { grandParents.add(grandParent); final ProjectState s = projectCache.get(grandParent); if (s != null) { grandParent = s.getProject().getParent(); } else { break; } } } int numberOfFailedProjects = 0; for (final Project.NameKey pc : childProjects) { final String name = pc.get(); if (wildProject.equals(pc)) { err.append("error: Cannot set parent of '" + name + "'\n"); numberOfFailedProjects++; continue; } if (grandParents.contains(pc) || pc.equals(parentNameKey)) { err.append("error: Cycle exists between '" + name + "' and '" + (parentNameKey != null ? parentNameKey.get() : wildProject.get()) + "'\n"); numberOfFailedProjects++; continue; } final Project child = db.projects().get(pc); if (child == null) { err.append("error: Project '" + name + "' not found\n"); numberOfFailedProjects++; continue; } child.setParent(parentNameKey); db.projects().update(Collections.singleton(child)); } projectCache.evictAll(); if (numberOfFailedProjects == childProjects.size() && childProjects.size() > 1) { err.append("Set parent failed for all projects."); } if (err.length() > 0) { throw new OperationNotExecutedException(err.toString()); } }