minor
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / FeatureTreeServiceImpl.java
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 org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Service;
20 import org.springframework.transaction.annotation.Propagation;
21 import org.springframework.transaction.annotation.Transactional;
22
23 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
24 import eu.etaxonomy.cdm.model.common.TermVocabulary;
25 import eu.etaxonomy.cdm.model.common.VocabularyEnum;
26 import eu.etaxonomy.cdm.model.description.DescriptionBase;
27 import eu.etaxonomy.cdm.model.description.Feature;
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 IVocabularyService vocabularyService;
42
43 @Autowired
44 protected void setDao(IFeatureTreeDao dao) {
45 this.dao = dao;
46 }
47
48 @Autowired
49 protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao) {
50 this.featureNodeDao = featureNodeDao;
51 }
52
53
54 /* (non-Javadoc)
55 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
56 */
57 @Override
58 @Transactional(readOnly = false)
59 public void updateTitleCache(Class<? extends FeatureTree> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<FeatureTree> cacheStrategy, IProgressMonitor monitor) {
60 if (clazz == null){
61 clazz = FeatureTree.class;
62 }
63 super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
64 }
65
66
67 /* (non-Javadoc)
68 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#getFeatureNodesAll()
69 */
70 public List<FeatureNode> getFeatureNodesAll() {
71 return featureNodeDao.list();
72 }
73
74 /*
75 * (non-Javadoc)
76 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#saveFeatureNodesAll(java.util.Collection)
77 */
78 public Map<UUID, FeatureNode> saveFeatureNodesAll(Collection<FeatureNode> featureNodeCollection) {
79 return featureNodeDao.saveAll(featureNodeCollection);
80 }
81
82 /* (non-Javadoc)
83 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#saveOrUpdateFeatureNodesAll(java.util.Collection)
84 */
85 public Map<UUID, FeatureNode> saveOrUpdateFeatureNodesAll(Collection<FeatureNode> featureNodeCollection) {
86 return featureNodeDao.saveOrUpdateAll(featureNodeCollection);
87 }
88
89 /* (non-Javadoc)
90 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#loadWithNodes(java.util.UUID, java.util.List, java.util.List)
91 */
92 public FeatureTree loadWithNodes(UUID uuid, List<String> propertyPaths, List<String> nodePaths) {
93 nodePaths.add("children");
94
95 List<String> rootPaths = new ArrayList<String>();
96 rootPaths.add("root");
97 for(String path : nodePaths) {
98 rootPaths.add("root." + path);
99 }
100
101 if(propertyPaths != null) {
102 rootPaths.addAll(propertyPaths);
103 }
104
105 FeatureTree featureTree = load(uuid, rootPaths);
106 dao.loadNodes(featureTree.getRoot(),nodePaths);
107 return featureTree;
108 }
109
110 /**
111 * Returns the featureTree specified by the given <code>uuid</code>.
112 * The specified featureTree either can be one of those stored in the CDM database or can be the
113 * DefaultFeatureTree (contains all Features in use).
114 * The uuid of the DefaultFeatureTree is defined in {@link IFeatureTreeService#DefaultFeatureTreeUuid}.
115 * The DefaultFeatureTree is also returned if no feature tree at all is stored in the cdm database.
116 *
117 * @see eu.etaxonomy.cdm.api.service.ServiceBase#load(java.util.UUID, java.util.List)
118 */
119 @Override
120 public FeatureTree load(UUID uuid, List<String> propertyPaths) {
121 return super.load(uuid, propertyPaths);
122 }
123
124 /* (non-Javadoc)
125 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#createTransientDefaultFeatureTree()
126 */
127 @Override
128 public FeatureTree createTransientDefaultFeatureTree() {
129 return load(IFeatureTreeDao.DefaultFeatureTreeUuid);
130 }
131
132
133
134 }