X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/blobdiff_plain/205bb92ba42ebb373ae73a8fa992859227bca950..cd26eb20fa0fb60fb47965ea3857477e5f61a7e2:/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java diff --git a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java index 98e8b9144d..64c052f92c 100644 --- a/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java +++ b/cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java @@ -1,9 +1,9 @@ // $Id$ /** * Copyright (C) 2009 EDIT -* European Distributed Institute of Taxonomy +* European Distributed Institute of Taxonomy * http://www.e-taxonomy.eu -* +* * The contents of this file are subject to the Mozilla Public License Version 1.1 * See LICENSE.TXT at the top of this package for the full license terms. */ @@ -15,10 +15,8 @@ import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase; import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; import eu.etaxonomy.cdm.model.description.PolytomousKeyNode; import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao; @@ -33,36 +31,59 @@ import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao; public class PolytomousKeyNodeServiceImpl extends VersionableServiceBase implements IPolytomousKeyNodeService { - @Autowired + @Override + @Autowired protected void setDao(IPolytomousKeyNodeDao dao) { this.dao = dao; } - + @Override - public UUID delete(PolytomousKeyNode node, boolean deleteChildren){ - UUID uuid = node.getUuid(); - node = (PolytomousKeyNode)HibernateProxyHelper.deproxy(node); - List children = node.getChildren(); - - if(!deleteChildren){ - PolytomousKeyNode parent = node.getParent(); - for (PolytomousKeyNode child: children){ - parent.addChild(child); - parent.removeChild(node); - dao.update(child); - } - - dao.update(node); - } - if (node.getParent()!= null){ - node.getParent().removeChild(node); - } - if (node.getKey().getRoot().equals(node)){ - node.getKey().setRoot(null); - } - dao.delete(node); - return uuid; - - } + public DeleteResult delete(UUID nodeUUID, boolean deleteChildren){ + DeleteResult result = new DeleteResult(); + PolytomousKeyNode node = dao.findByUuid(nodeUUID); + node = (PolytomousKeyNode)HibernateProxyHelper.deproxy(node); + if(node == null) { + return null; + } + List children = new ArrayList(); + for (PolytomousKeyNode child: node.getChildren()){ + children.add(child); + } + PolytomousKeyNode parent = node.getParent(); + parent = HibernateProxyHelper.deproxy(parent, PolytomousKeyNode.class); + + if(!deleteChildren){ + + for (PolytomousKeyNode child: children){ + if (!child.equals(node)){ + parent.addChild(child); + dao.update(child); + result.addUpdatedObject(child); + } + + } + + + dao.update(node); + result.addUpdatedObject(node); + } + if (parent!= null){ + parent.removeChild(node); + dao.update(parent); + } + if (node.getKey().getRoot().equals(node)){ + node.getKey().setRoot(null); + } + if (node.getTaxon() != null){ + node.removeTaxon(); + } + if (dao.delete(node) == null){ + result.setAbort(); + } + dao.saveOrUpdate(parent); + result.addUpdatedObject(parent); + return result; + + } }