- public UUID delete(PolytomousKeyNode node, boolean deleteChildren){\r
- UUID uuid = node.getUuid();\r
- node = (PolytomousKeyNode)HibernateProxyHelper.deproxy(node);\r
- List<PolytomousKeyNode> children = node.getChildren();\r
- \r
- if(!deleteChildren){\r
- PolytomousKeyNode parent = node.getParent();\r
- for (PolytomousKeyNode child: children){\r
- parent.addChild(child);\r
- parent.removeChild(node);\r
- dao.update(child);\r
- }\r
- \r
- dao.update(node);\r
- }\r
- if (node.getParent()!= null){\r
- node.getParent().removeChild(node);\r
- }\r
- if (node.getKey().getRoot().equals(node)){\r
- node.getKey().setRoot(null);\r
- }\r
- dao.delete(node);\r
- return uuid;\r
- \r
- }\r
+ public DeleteResult delete(UUID nodeUUID, boolean deleteChildren){\r
+ DeleteResult result = new DeleteResult();\r
+ PolytomousKeyNode node = dao.findByUuid(nodeUUID);\r
+ node = (PolytomousKeyNode)HibernateProxyHelper.deproxy(node);\r
+ if(node == null) {\r
+ return null;\r
+ }\r
+ List<PolytomousKeyNode> children = new ArrayList<PolytomousKeyNode>();\r
+ for (PolytomousKeyNode child: node.getChildren()){\r
+ children.add(child);\r
+ }\r
+ PolytomousKeyNode parent = node.getParent();\r
+ parent = HibernateProxyHelper.deproxy(parent, PolytomousKeyNode.class);\r
+\r
+ if(!deleteChildren){\r
+\r
+ for (PolytomousKeyNode child: children){\r
+ if (!child.equals(node)){\r
+ parent.addChild(child);\r
+ dao.update(child);\r
+ result.addUpdatedObject(child);\r
+ }\r
+\r
+ }\r
+\r
+\r
+ dao.update(node);\r
+ result.addUpdatedObject(node);\r
+ }\r
+ if (parent!= null){\r
+ parent.removeChild(node);\r
+ dao.update(parent);\r
+ }\r
+ if (node.getKey().getRoot().equals(node)){\r
+ node.getKey().setRoot(null);\r
+ }\r
+ if (node.getTaxon() != null){\r
+ node.removeTaxon();\r
+ }\r
+ if (dao.delete(node) == null){\r
+ result.setAbort();\r
+ }\r
+ dao.saveOrUpdate(parent);\r
+ result.addUpdatedObject(parent);\r
+ return result;\r
+\r
+ }\r