Project

General

Profile

Download (4.98 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.cdm.api.service;
11

    
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.UUID;
17

    
18
import javax.persistence.EntityNotFoundException;
19

    
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.stereotype.Service;
22
import org.springframework.transaction.annotation.Transactional;
23

    
24
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
25
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
26
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
27
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
28
import eu.etaxonomy.cdm.model.description.FeatureNode;
29
import eu.etaxonomy.cdm.model.description.FeatureTree;
30
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureNodeDao;
31
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureTreeDao;
32
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
33

    
34
@Service
35
@Transactional(readOnly = false)
36
public class FeatureTreeServiceImpl extends IdentifiableServiceBase<FeatureTree, IFeatureTreeDao> implements IFeatureTreeService {
37

    
38
    private IFeatureNodeDao featureNodeDao;
39

    
40
    @Autowired
41
    private IFeatureNodeService featureNodeService;
42

    
43
    @Override
44
    @Autowired
45
    protected void setDao(IFeatureTreeDao dao) {
46
        this.dao = dao;
47
    }
48

    
49
    @Autowired
50
    protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao) {
51
        this.featureNodeDao = featureNodeDao;
52
    }
53

    
54
    @Override
55
    @Transactional(readOnly = false)
56
    public void updateCaches(Class<? extends FeatureTree> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<FeatureTree> cacheStrategy, IProgressMonitor monitor) {
57
        if (clazz == null){
58
            clazz = FeatureTree.class;
59
        }
60
        super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
61
    }
62

    
63
    @Override
64
    public List<FeatureNode> getFeatureNodesAll() {
65
        return featureNodeDao.list();
66
    }
67

    
68
    @Override
69
    public Map<UUID, FeatureNode> saveFeatureNodesAll(Collection<FeatureNode> featureNodeCollection) {
70
        return featureNodeDao.saveAll(featureNodeCollection);
71
    }
72

    
73
    @Override
74
    public Map<UUID, FeatureNode> saveOrUpdateFeatureNodesAll(Collection<FeatureNode> featureNodeCollection) {
75
        return featureNodeDao.saveOrUpdateAll(featureNodeCollection);
76
    }
77

    
78
    @Override
79
    public FeatureTree loadWithNodes(UUID uuid, List<String> propertyPaths, List<String> nodePaths) {
80

    
81
        if(!nodePaths.contains("children")) {
82
            nodePaths.add("children");
83
        }
84

    
85
        List<String> rootPaths = new ArrayList<String>();
86
        rootPaths.add("root");
87
        for(String path : nodePaths) {
88
            rootPaths.add("root." + path);
89
        }
90

    
91
        if(propertyPaths != null) {
92
            rootPaths.addAll(propertyPaths);
93
        }
94

    
95
        FeatureTree featureTree = load(uuid, rootPaths);
96
        if(featureTree == null){
97
            throw new EntityNotFoundException("No FeatureTree entity found for " + uuid);
98
        }
99
        dao.deepLoadNodes(featureTree.getRoot().getChildNodes() ,nodePaths);
100
        return featureTree;
101
    }
102

    
103
    /**
104
     * Returns the featureTree specified by the given <code>uuid</code>.
105
     * The specified featureTree either can be one of those stored in the CDM database or can be the
106
     * DefaultFeatureTree (contains all Features in use).
107
     * The uuid of the DefaultFeatureTree is defined in {@link IFeatureTreeService#DefaultFeatureTreeUuid}.
108
     * The DefaultFeatureTree is also returned if no feature tree at all is stored in the cdm database.
109
     *
110
     * @see eu.etaxonomy.cdm.api.service.ServiceBase#load(java.util.UUID, java.util.List)
111
     */
112
    @Override
113
    public FeatureTree load(UUID uuid, List<String> propertyPaths) {
114
        return super.load(uuid, propertyPaths);
115
    }
116

    
117
    @Override
118
    public FeatureTree createTransientDefaultFeatureTree() {
119
        return load(IFeatureTreeDao.DefaultFeatureTreeUuid);
120
    }
121

    
122
    @Override
123
    public DeleteResult delete(UUID featureTreeUuid){
124
        DeleteResult result = new DeleteResult();
125
        FeatureTree tree = dao.load(featureTreeUuid);
126

    
127
        FeatureNode rootNode = HibernateProxyHelper.deproxy(tree.getRoot(), FeatureNode.class);
128
        FeatureNodeDeletionConfigurator config = new FeatureNodeDeletionConfigurator();
129
        config.setChildHandling(ChildHandling.DELETE);
130
        result =featureNodeService.deleteFeatureNode(rootNode.getUuid(), config);
131
        tree.setRoot(null);
132
        if (result.isOk()){
133
          dao.delete(tree);
134
          result.addDeletedObject(tree);
135
        }
136
        return result;
137

    
138
    }
139
}
(24-24/103)