Project

General

Profile

« Previous | Next » 

Revision ac5020e6

Added by Andreas Müller about 8 years ago

Fix CCE in DefinedTermDaoImpl.getPartOf (#5556) and make deproxy more
generic

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyNodeServiceImpl.java
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.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.stereotype.Service;
18
import org.springframework.transaction.annotation.Transactional;
19

  
20
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
21
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
22
import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao;
23

  
24
/**
25
 * @author a.kohlbecker
26
 * @date 24.03.2011
27
 *
28
 */
29
@Service
30
@Transactional(readOnly = false)
31
public class PolytomousKeyNodeServiceImpl  extends VersionableServiceBase<PolytomousKeyNode, IPolytomousKeyNodeDao> implements IPolytomousKeyNodeService {
32

  
33

  
34
	@Override
35
    @Autowired
36
	protected void setDao(IPolytomousKeyNodeDao dao) {
37
		this.dao = dao;
38
	}
39

  
40
	@Override
41
	public DeleteResult delete(UUID nodeUUID, boolean deleteChildren){
42
        DeleteResult result = new DeleteResult();
43
        PolytomousKeyNode node = dao.findByUuid(nodeUUID);
44
        node = (PolytomousKeyNode)HibernateProxyHelper.deproxy(node);
45
        if(node == null) {
46
            return null;
47
        }
48
        List<PolytomousKeyNode> children = new ArrayList<PolytomousKeyNode>();
49
        for (PolytomousKeyNode child: node.getChildren()){
50
            children.add(child);
51
        }
52
        PolytomousKeyNode parent = node.getParent();
53
        parent = HibernateProxyHelper.deproxy(parent, PolytomousKeyNode.class);
54

  
55
        if(!deleteChildren){
56

  
57
            for (PolytomousKeyNode child: children){
58
                if (!child.equals(node)){
59
                    parent.addChild(child);
60
                    dao.update(child);
61
                    result.addUpdatedObject(child);
62
                }
63

  
64
            }
65

  
66

  
67
            dao.update(node);
68
            result.addUpdatedObject(node);
69
        }
70
        if (parent!= null){
71
            parent.removeChild(node);
72
            dao.update(parent);
73
        }
74
        if (node.getKey().getRoot().equals(node)){
75
            node.getKey().setRoot(null);
76
        }
77
        if (node.getTaxon() != null){
78
            node.removeTaxon();
79
        }
80
        if (dao.delete(node) == null){
81
            result.setAbort();
82
        }
83
        dao.saveOrUpdate(parent);
84
        result.addUpdatedObject(parent);
85
        return result;
86

  
87
    }
88

  
89
}
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.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
15

  
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.stereotype.Service;
18
import org.springframework.transaction.annotation.Transactional;
19

  
20
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
21
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
22
import eu.etaxonomy.cdm.persistence.dao.description.IPolytomousKeyNodeDao;
23

  
24
/**
25
 * @author a.kohlbecker
26
 * @date 24.03.2011
27
 *
28
 */
29
@Service
30
@Transactional(readOnly = false)
31
public class PolytomousKeyNodeServiceImpl  extends VersionableServiceBase<PolytomousKeyNode, IPolytomousKeyNodeDao> implements IPolytomousKeyNodeService {
32

  
33

  
34
	@Override
35
    @Autowired
36
	protected void setDao(IPolytomousKeyNodeDao dao) {
37
		this.dao = dao;
38
	}
39

  
40
	@Override
41
	public DeleteResult delete(UUID nodeUUID, boolean deleteChildren){
42
        DeleteResult result = new DeleteResult();
43
        PolytomousKeyNode node = dao.findByUuid(nodeUUID);
44
        node = HibernateProxyHelper.deproxy(node);
45
        if(node == null) {
46
            return null;
47
        }
48
        List<PolytomousKeyNode> children = new ArrayList<PolytomousKeyNode>();
49
        for (PolytomousKeyNode child: node.getChildren()){
50
            children.add(child);
51
        }
52
        PolytomousKeyNode parent = node.getParent();
53
        parent = HibernateProxyHelper.deproxy(parent, PolytomousKeyNode.class);
54

  
55
        if(!deleteChildren){
56

  
57
            for (PolytomousKeyNode child: children){
58
                if (!child.equals(node)){
59
                    parent.addChild(child);
60
                    dao.update(child);
61
                    result.addUpdatedObject(child);
62
                }
63

  
64
            }
65

  
66

  
67
            dao.update(node);
68
            result.addUpdatedObject(node);
69
        }
70
        if (parent!= null){
71
            parent.removeChild(node);
72
            dao.update(parent);
73
        }
74
        if (node.getKey().getRoot().equals(node)){
75
            node.getKey().setRoot(null);
76
        }
77
        if (node.getTaxon() != null){
78
            node.removeTaxon();
79
        }
80
        if (dao.delete(node) == null){
81
            result.setAbort();
82
        }
83
        dao.saveOrUpdate(parent);
84
        result.addUpdatedObject(parent);
85
        return result;
86

  
87
    }
88

  
89
}

Also available in: Unified diff