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
.HHH_9751_Util
;
20 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
21 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
22 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
23 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IPolytomousKeyDao
;
24 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IPolytomousKeyNodeDao
;
27 * @author a.kohlbecker
32 @Transactional(readOnly
= false)
33 public class PolytomousKeyNodeServiceImpl
extends VersionableServiceBase
<PolytomousKeyNode
, IPolytomousKeyNodeDao
> implements IPolytomousKeyNodeService
{
38 protected void setDao(IPolytomousKeyNodeDao dao
) {
43 protected IPolytomousKeyDao keyDao
;
46 public DeleteResult
delete(UUID nodeUUID
, boolean deleteChildren
){
47 DeleteResult result
= new DeleteResult();
48 PolytomousKeyNode node
= dao
.findByUuid(nodeUUID
);
49 node
= HibernateProxyHelper
.deproxy(node
);
51 // result.addException(new Exception("The polytomouskey node was already deleted."));;
54 List
<PolytomousKeyNode
> children
= new ArrayList
<PolytomousKeyNode
>();
56 node
.removeNullValueFromChildren();
57 for (PolytomousKeyNode child
: node
.getChildren()){
60 PolytomousKeyNode parent
= node
.getParent();
61 parent
= HibernateProxyHelper
.deproxy(parent
, PolytomousKeyNode
.class);
62 PolytomousKey key
= null;
65 key
= HibernateProxyHelper
.deproxy(key
, PolytomousKey
.class);
70 for (PolytomousKeyNode child
: children
){
71 if (!child
.equals(node
)){
72 parent
.addChild(child
);
73 dao
.saveOrUpdate(child
);
74 result
.addUpdatedObject(child
);
80 dao
.saveOrUpdate(node
);
81 result
.addUpdatedObject(node
);
84 if (parent
.getChildren().contains(null)){
85 List
<PolytomousKeyNode
> parentChildren
= parent
.getChildren();
86 HHH_9751_Util
.removeAllNull(parentChildren
);
88 parent
.removeChild(node
);
89 dao
.saveOrUpdate(parent
);
91 if (node
.getKey() != null && key
!= null){
94 if (node
.getTaxon() != null){
97 if (dao
.delete(node
) == null){
100 result
.addDeletedObject(node
);
103 dao
.saveOrUpdate(parent
);
104 result
.addUpdatedObject(parent
);
106 keyDao
.saveOrUpdate(key
);
107 result
.addUpdatedObject(key
);