1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.api.service;
|
11
|
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
import org.springframework.stereotype.Service;
|
17
|
import org.springframework.transaction.annotation.Transactional;
|
18
|
|
19
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
20
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
21
|
import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao;
|
22
|
|
23
|
/**
|
24
|
* @author a.kohlbecker
|
25
|
* @date 24.03.2011
|
26
|
*
|
27
|
*/
|
28
|
@Service
|
29
|
@Transactional(readOnly = false)
|
30
|
public class PolytomousKeyNodeServiceImpl extends VersionableServiceBase<PolytomousKeyNode, IPolytomousKeyNodeDao> implements IPolytomousKeyNodeService {
|
31
|
|
32
|
|
33
|
@Override
|
34
|
@Autowired
|
35
|
protected void setDao(IPolytomousKeyNodeDao dao) {
|
36
|
this.dao = dao;
|
37
|
}
|
38
|
|
39
|
@Override
|
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);
|
47
|
|
48
|
if(!deleteChildren){
|
49
|
|
50
|
for (PolytomousKeyNode child: children){
|
51
|
parent.addChild(child);
|
52
|
parent.removeChild(node);
|
53
|
dao.update(child);
|
54
|
result.addUpdatedObject(child);
|
55
|
}
|
56
|
|
57
|
dao.update(node);
|
58
|
result.addUpdatedObject(node);
|
59
|
}
|
60
|
if (node.getParent()!= null){
|
61
|
node.getParent().removeChild(node);
|
62
|
}
|
63
|
if (node.getKey().getRoot().equals(node)){
|
64
|
node.getKey().setRoot(null);
|
65
|
}
|
66
|
if (dao.delete(node) == null){
|
67
|
result.setAbort();
|
68
|
}
|
69
|
dao.saveOrUpdate(parent);
|
70
|
result.addUpdatedObject(parent);
|
71
|
return result;
|
72
|
|
73
|
}
|
74
|
|
75
|
}
|