2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Collection
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import javax
.persistence
.EntityNotFoundException
;
20 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
21 import org
.springframework
.stereotype
.Service
;
22 import org
.springframework
.transaction
.annotation
.Transactional
;
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
;
35 @Transactional(readOnly
= false)
36 public class FeatureTreeServiceImpl
extends IdentifiableServiceBase
<FeatureTree
, IFeatureTreeDao
> implements IFeatureTreeService
{
38 private IFeatureNodeDao featureNodeDao
;
41 private IVocabularyService vocabularyService
;
44 private IFeatureNodeService featureNodeService
;
48 protected void setDao(IFeatureTreeDao dao
) {
53 protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao
) {
54 this.featureNodeDao
= featureNodeDao
;
59 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
62 @Transactional(readOnly
= false)
63 public void updateTitleCache(Class
<?
extends FeatureTree
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<FeatureTree
> cacheStrategy
, IProgressMonitor monitor
) {
65 clazz
= FeatureTree
.class;
67 super.updateTitleCacheImpl(clazz
, stepSize
, cacheStrategy
, monitor
);
72 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#getFeatureNodesAll()
75 public List
<FeatureNode
> getFeatureNodesAll() {
76 return featureNodeDao
.list();
81 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#saveFeatureNodesAll(java.util.Collection)
84 public Map
<UUID
, FeatureNode
> saveFeatureNodesAll(Collection
<FeatureNode
> featureNodeCollection
) {
85 return featureNodeDao
.saveAll(featureNodeCollection
);
89 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#saveOrUpdateFeatureNodesAll(java.util.Collection)
92 public Map
<UUID
, FeatureNode
> saveOrUpdateFeatureNodesAll(Collection
<FeatureNode
> featureNodeCollection
) {
93 return featureNodeDao
.saveOrUpdateAll(featureNodeCollection
);
97 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#loadWithNodes(java.util.UUID, java.util.List, java.util.List)
100 public FeatureTree
loadWithNodes(UUID uuid
, List
<String
> propertyPaths
, List
<String
> nodePaths
) {
102 if(!nodePaths
.contains("children")) {
103 nodePaths
.add("children");
106 List
<String
> rootPaths
= new ArrayList
<String
>();
107 rootPaths
.add("root");
108 for(String path
: nodePaths
) {
109 rootPaths
.add("root." + path
);
112 if(propertyPaths
!= null) {
113 rootPaths
.addAll(propertyPaths
);
116 FeatureTree featureTree
= load(uuid
, rootPaths
);
117 if(featureTree
== null){
118 throw new EntityNotFoundException("No FeatureTree entity found for " + uuid
);
120 dao
.deepLoadNodes(featureTree
.getRoot().getChildNodes() ,nodePaths
);
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.
131 * @see eu.etaxonomy.cdm.api.service.ServiceBase#load(java.util.UUID, java.util.List)
134 public FeatureTree
load(UUID uuid
, List
<String
> propertyPaths
) {
135 return super.load(uuid
, propertyPaths
);
139 * @see eu.etaxonomy.cdm.api.service.IFeatureTreeService#createTransientDefaultFeatureTree()
142 public FeatureTree
createTransientDefaultFeatureTree() {
143 return load(IFeatureTreeDao
.DefaultFeatureTreeUuid
);
147 public DeleteResult
delete(UUID featureTreeUuid
){
148 DeleteResult result
= new DeleteResult();
149 FeatureTree tree
= dao
.load(featureTreeUuid
);
151 FeatureNode rootNode
= HibernateProxyHelper
.deproxy(tree
.getRoot(), FeatureNode
.class);
152 FeatureNodeDeletionConfigurator config
= new FeatureNodeDeletionConfigurator();
153 config
.setChildHandling(ChildHandling
.DELETE
);
154 result
=featureNodeService
.deleteFeatureNode(rootNode
.getUuid(), config
);
158 result
.addDeletedObject(tree
);