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
.List
;
13 import java
.util
.UUID
;
15 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
16 import org
.springframework
.stereotype
.Service
;
17 import org
.springframework
.transaction
.annotation
.Transactional
;
19 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
20 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
21 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IPolytomousKeyNodeDao
;
24 * @author a.kohlbecker
29 @Transactional(readOnly
= false)
30 public class PolytomousKeyNodeServiceImpl
extends VersionableServiceBase
<PolytomousKeyNode
, IPolytomousKeyNodeDao
> implements IPolytomousKeyNodeService
{
35 protected void setDao(IPolytomousKeyNodeDao dao
) {
40 public DeleteResult
delete(UUID nodeUUID
, boolean deleteChildren
){
41 DeleteResult result
= new DeleteResult();
42 PolytomousKeyNode node
= dao
.findByUuid(nodeUUID
);
43 node
= (PolytomousKeyNode
)HibernateProxyHelper
.deproxy(node
);
44 List
<PolytomousKeyNode
> children
= node
.getChildren();
45 PolytomousKeyNode parent
= node
.getParent();
46 parent
= HibernateProxyHelper
.deproxy(parent
, PolytomousKeyNode
.class);
50 for (PolytomousKeyNode child
: children
){
51 parent
.addChild(child
);
52 parent
.removeChild(node
);
54 result
.addUpdatedObject(child
);
58 result
.addUpdatedObject(node
);
60 if (node
.getParent()!= null){
61 node
.getParent().removeChild(node
);
63 if (node
.getKey().getRoot().equals(node
)){
64 node
.getKey().setRoot(null);
66 if (dao
.delete(node
) == null){
69 dao
.saveOrUpdate(parent
);
70 result
.addUpdatedObject(parent
);