2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.api
.service
;
11 import java
.util
.ArrayList
;
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
.PolytomousKey
;
21 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
22 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IPolytomousKeyDao
;
23 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IPolytomousKeyNodeDao
;
26 * @author a.kohlbecker
30 @Transactional(readOnly
= false)
31 public class PolytomousKeyNodeServiceImpl
32 extends VersionableServiceBase
<PolytomousKeyNode
, IPolytomousKeyNodeDao
>
33 implements IPolytomousKeyNodeService
{
37 protected void setDao(IPolytomousKeyNodeDao dao
) {
42 protected IPolytomousKeyDao keyDao
;
45 public DeleteResult
delete(UUID nodeUUID
, boolean deleteChildren
){
46 DeleteResult result
= new DeleteResult();
47 PolytomousKeyNode node
= dao
.findByUuid(nodeUUID
);
48 node
= HibernateProxyHelper
.deproxy(node
);
50 // result.addException(new Exception("The polytomouskey node was already deleted."));
53 List
<PolytomousKeyNode
> children
= new ArrayList
<>();
55 for (PolytomousKeyNode child
: node
.getChildren()){
58 PolytomousKeyNode parent
= node
.getParent();
59 parent
= HibernateProxyHelper
.deproxy(parent
);
60 PolytomousKey key
= null;
63 key
= HibernateProxyHelper
.deproxy(key
);
67 for (PolytomousKeyNode child
: children
){
68 if (!child
.equals(node
)){
69 parent
.addChild(child
);
70 dao
.saveOrUpdate(child
);
71 result
.addUpdatedObject(child
);
75 dao
.saveOrUpdate(node
);
76 result
.addUpdatedObject(node
);
79 parent
.removeChild(node
);
80 dao
.saveOrUpdate(parent
);
82 if (node
.getKey() != null && key
!= null){
85 if (node
.getTaxon() != null){
88 if (dao
.delete(node
) == null){
91 result
.addDeletedObject(node
);
94 dao
.saveOrUpdate(parent
);
95 result
.addUpdatedObject(parent
);
97 keyDao
.saveOrUpdate(key
);
98 result
.addUpdatedObject(key
);