3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
17 import org
.springframework
.stereotype
.Service
;
18 import org
.springframework
.transaction
.annotation
.Transactional
;
20 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
21 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
22 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IPolytomousKeyNodeDao
;
25 * @author a.kohlbecker
30 @Transactional(readOnly
= false)
31 public class PolytomousKeyNodeServiceImpl
extends VersionableServiceBase
<PolytomousKeyNode
, IPolytomousKeyNodeDao
> implements IPolytomousKeyNodeService
{
36 protected void setDao(IPolytomousKeyNodeDao dao
) {
41 public DeleteResult
delete(UUID nodeUUID
, boolean deleteChildren
){
42 DeleteResult result
= new DeleteResult();
43 PolytomousKeyNode node
= dao
.findByUuid(nodeUUID
);
44 node
= (PolytomousKeyNode
)HibernateProxyHelper
.deproxy(node
);
48 List
<PolytomousKeyNode
> children
= new ArrayList
<PolytomousKeyNode
>();
49 for (PolytomousKeyNode child
: node
.getChildren()){
52 PolytomousKeyNode parent
= node
.getParent();
53 parent
= HibernateProxyHelper
.deproxy(parent
, PolytomousKeyNode
.class);
57 for (PolytomousKeyNode child
: children
){
58 if (!child
.equals(node
)){
59 parent
.addChild(child
);
61 result
.addUpdatedObject(child
);
68 result
.addUpdatedObject(node
);
71 parent
.removeChild(node
);
74 if (node
.getKey().getRoot().equals(node
)){
75 node
.getKey().setRoot(null);
77 if (node
.getTaxon() != null){
80 if (dao
.delete(node
) == null){
83 dao
.saveOrUpdate(parent
);
84 result
.addUpdatedObject(parent
);