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
31 @Transactional(readOnly
= false)
32 public class PolytomousKeyNodeServiceImpl
extends VersionableServiceBase
<PolytomousKeyNode
, IPolytomousKeyNodeDao
> 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
, PolytomousKeyNode
.class);
60 PolytomousKey key
= null;
63 key
= HibernateProxyHelper
.deproxy(key
, PolytomousKey
.class);
68 for (PolytomousKeyNode child
: children
){
69 if (!child
.equals(node
)){
70 parent
.addChild(child
);
71 dao
.saveOrUpdate(child
);
72 result
.addUpdatedObject(child
);
78 dao
.saveOrUpdate(node
);
79 result
.addUpdatedObject(node
);
82 parent
.removeChild(node
);
83 dao
.saveOrUpdate(parent
);
85 if (node
.getKey() != null && key
!= null){
88 if (node
.getTaxon() != null){
91 if (dao
.delete(node
) == null){
94 result
.addDeletedObject(node
);
97 dao
.saveOrUpdate(parent
);
98 result
.addUpdatedObject(parent
);
100 keyDao
.saveOrUpdate(key
);
101 result
.addUpdatedObject(key
);