Project

General

Profile

Download (5.89 KB) Statistics
| Branch: | Tag: | Revision:
1 78c2bf74 Katja Luther
/**
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 98cfec8f Andreas Kohlbecker
*/
9 78c2bf74 Katja Luther
10 c4e812bc ben.clark
package eu.etaxonomy.cdm.api.service;
11
12
import java.util.ArrayList;
13 96e3416d Katja Luther
import java.util.Collection;
14 c4e812bc ben.clark
import java.util.List;
15 96e3416d Katja Luther
import java.util.Map;
16 c4e812bc ben.clark
import java.util.UUID;
17
18 6ed36ca8 Andreas Kohlbecker
import javax.persistence.EntityNotFoundException;
19
20 c4e812bc ben.clark
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.stereotype.Service;
22
import org.springframework.transaction.annotation.Transactional;
23
24 e898ed12 Katja Luther
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
25 3db5c325 Katja Luther
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
26 79c0eaa0 Andreas Müller
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
27 3db5c325 Katja Luther
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
28 c4e812bc ben.clark
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 f197a589 Andreas Müller
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
33 c4e812bc ben.clark
34
@Service
35 77b4a247 Andreas Kohlbecker
@Transactional(readOnly = false)
36 c4e812bc ben.clark
public class FeatureTreeServiceImpl extends IdentifiableServiceBase<FeatureTree, IFeatureTreeDao> implements IFeatureTreeService {
37
38 98cfec8f Andreas Kohlbecker
    private IFeatureNodeDao featureNodeDao;
39
40
    @Autowired
41
    private IVocabularyService vocabularyService;
42
43 3db5c325 Katja Luther
    @Autowired
44
    private IFeatureNodeService featureNodeService;
45
46 98cfec8f Andreas Kohlbecker
    @Override
47
    @Autowired
48
    protected void setDao(IFeatureTreeDao dao) {
49
        this.dao = dao;
50
    }
51
52
    @Autowired
53
    protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao) {
54
        this.featureNodeDao = featureNodeDao;
55
    }
56
57
58
    /* (non-Javadoc)
59
     * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
60
     */
61
    @Override
62
    @Transactional(readOnly = false)
63 4116e48b Andreas Müller
    public void updateTitleCache(Class<? extends FeatureTree> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<FeatureTree> cacheStrategy, IProgressMonitor monitor) {
64 98cfec8f Andreas Kohlbecker
        if (clazz == null){
65
            clazz = FeatureTree.class;
66
        }
67
        super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
68
    }
69
70
71
    /* (non-Javadoc)
72
     * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#getFeatureNodesAll()
73
     */
74
    @Override
75
    public List<FeatureNode> getFeatureNodesAll() {
76
        return featureNodeDao.list();
77
    }
78
79
    /*
80
     * (non-Javadoc)
81
     * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#saveFeatureNodesAll(java.util.Collection)
82
     */
83
    @Override
84
    public Map<UUID, FeatureNode> saveFeatureNodesAll(Collection<FeatureNode> featureNodeCollection) {
85
        return featureNodeDao.saveAll(featureNodeCollection);
86
    }
87
88
    /* (non-Javadoc)
89
     * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#saveOrUpdateFeatureNodesAll(java.util.Collection)
90
     */
91
    @Override
92
    public Map<UUID, FeatureNode> saveOrUpdateFeatureNodesAll(Collection<FeatureNode> featureNodeCollection) {
93
        return featureNodeDao.saveOrUpdateAll(featureNodeCollection);
94
    }
95
96
    /* (non-Javadoc)
97
     * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#loadWithNodes(java.util.UUID, java.util.List, java.util.List)
98
     */
99
    @Override
100
    public FeatureTree loadWithNodes(UUID uuid, List<String> propertyPaths, List<String> nodePaths) {
101
102
        if(!nodePaths.contains("children")) {
103
            nodePaths.add("children");
104
        }
105
106
        List<String> rootPaths = new ArrayList<String>();
107
        rootPaths.add("root");
108
        for(String path : nodePaths) {
109
            rootPaths.add("root." + path);
110
        }
111
112
        if(propertyPaths != null) {
113
            rootPaths.addAll(propertyPaths);
114
        }
115
116
        FeatureTree featureTree = load(uuid, rootPaths);
117 6ed36ca8 Andreas Kohlbecker
        if(featureTree == null){
118
            throw new EntityNotFoundException("No FeatureTree entity found for " + uuid);
119
        }
120 f70a6bb7 Andreas Kohlbecker
        dao.deepLoadNodes(featureTree.getRoot().getChildNodes() ,nodePaths);
121 98cfec8f Andreas Kohlbecker
        return featureTree;
122
    }
123
124
    /**
125
     * Returns the featureTree specified by the given <code>uuid</code>.
126
     * The specified featureTree either can be one of those stored in the CDM database or can be the
127
     * DefaultFeatureTree (contains all Features in use).
128
     * The uuid of the DefaultFeatureTree is defined in {@link IFeatureTreeService#DefaultFeatureTreeUuid}.
129
     * The DefaultFeatureTree is also returned if no feature tree at all is stored in the cdm database.
130
     *
131
     * @see eu.etaxonomy.cdm.api.service.ServiceBase#load(java.util.UUID, java.util.List)
132
     */
133
    @Override
134
    public FeatureTree load(UUID uuid, List<String> propertyPaths) {
135
        return super.load(uuid, propertyPaths);
136
    }
137
138
    /* (non-Javadoc)
139
     * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#createTransientDefaultFeatureTree()
140
     */
141
    @Override
142
    public FeatureTree createTransientDefaultFeatureTree() {
143
        return load(IFeatureTreeDao.DefaultFeatureTreeUuid);
144
    }
145
146 3db5c325 Katja Luther
    @Override
147
    public DeleteResult delete(UUID featureTreeUuid){
148
        DeleteResult result = new DeleteResult();
149
        FeatureTree tree = dao.load(featureTreeUuid);
150
151
        FeatureNode rootNode = HibernateProxyHelper.deproxy(tree.getRoot(), FeatureNode.class);
152 e898ed12 Katja Luther
        FeatureNodeDeletionConfigurator config = new FeatureNodeDeletionConfigurator();
153 3db5c325 Katja Luther
        config.setChildHandling(ChildHandling.DELETE);
154
        result =featureNodeService.deleteFeatureNode(rootNode.getUuid(), config);
155 e898ed12 Katja Luther
        tree.setRoot(null);
156
        if (result.isOk()){
157
          dao.delete(tree);
158
        }
159 3db5c325 Katja Luther
        return result;
160
161
    }
162
163 98cfec8f Andreas Kohlbecker
164
165 c4e812bc ben.clark
}