-// $Id$
/**
* Copyright (C) 2009 EDIT
* European Distributed Institute of Taxonomy
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.description.PolytomousKey;
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
/**
* @author a.kohlbecker
- * @date 24.03.2011
- *
+ * @since 24.03.2011
*/
@Service
@Transactional(readOnly = false)
-public class PolytomousKeyNodeServiceImpl extends VersionableServiceBase<PolytomousKeyNode, IPolytomousKeyNodeDao> implements IPolytomousKeyNodeService {
-
+public class PolytomousKeyNodeServiceImpl
+ extends VersionableServiceBase<PolytomousKeyNode, IPolytomousKeyNodeDao>
+ implements IPolytomousKeyNodeService {
@Override
@Autowired
DeleteResult result = new DeleteResult();
PolytomousKeyNode node = dao.findByUuid(nodeUUID);
node = HibernateProxyHelper.deproxy(node);
- if(node == null) {
- result.addException(new Exception("The polytomouskey node was already deleted."));;
+ if (node == null) {
+ // result.addException(new Exception("The polytomouskey node was already deleted."));
+ return result;
}
- List<PolytomousKeyNode> children = new ArrayList<PolytomousKeyNode>();
- node.removeNullValueFromChildren();
+ List<PolytomousKeyNode> children = new ArrayList<>();
+
for (PolytomousKeyNode child: node.getChildren()){
children.add(child);
}
PolytomousKeyNode parent = node.getParent();
- parent = HibernateProxyHelper.deproxy(parent, PolytomousKeyNode.class);
+ parent = HibernateProxyHelper.deproxy(parent);
PolytomousKey key = null;
if (parent == null){
key = node.getKey();
- key = HibernateProxyHelper.deproxy(key, PolytomousKey.class);
+ key = HibernateProxyHelper.deproxy(key);
}
if(!deleteChildren){
-
for (PolytomousKeyNode child: children){
if (!child.equals(node)){
parent.addChild(child);
dao.saveOrUpdate(child);
result.addUpdatedObject(child);
}
-
}
-
dao.saveOrUpdate(node);
result.addUpdatedObject(node);
}
if (parent!= null){
- if (parent.getChildren().contains(null)){
- List<PolytomousKeyNode> parentChildren = parent.getChildren();
- HHH_9751_Util.removeAllNull(parentChildren);
- }
parent.removeChild(node);
dao.saveOrUpdate(parent);
}
}
if (dao.delete(node) == null){
result.setAbort();
+ }else{
+ result.addDeletedObject(node);
}
if (parent != null){
dao.saveOrUpdate(parent);
}
return result;
-
}
-
-}
+}
\ No newline at end of file