3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.api
.service
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
20 import org
.springframework
.stereotype
.Service
;
21 import org
.springframework
.transaction
.annotation
.Transactional
;
23 import eu
.etaxonomy
.cdm
.api
.service
.config
.FeatureNodeDeletionConfigurator
;
24 import eu
.etaxonomy
.cdm
.api
.service
.config
.NodeDeletionConfigurator
.ChildHandling
;
25 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
26 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
29 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
30 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
31 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureNodeDao
;
35 * @created Aug 5, 2010
39 @Transactional(readOnly
= false)
40 public class FeatureNodeServiceImpl
extends VersionableServiceBase
<FeatureNode
, IFeatureNodeDao
> implements IFeatureNodeService
{
41 private static final Logger logger
= Logger
.getLogger(FeatureNodeServiceImpl
.class);
45 protected void setDao(IFeatureNodeDao dao
) {
50 private ITermService termService
;
53 @Transactional(readOnly
= false)
54 public DeleteResult
deleteFeatureNode(UUID nodeUuid
, FeatureNodeDeletionConfigurator config
) {
55 DeleteResult result
= new DeleteResult();
56 FeatureNode node
= HibernateProxyHelper
.deproxy(dao
.load(nodeUuid
), FeatureNode
.class);
57 result
= isDeletable(node
, config
);
60 FeatureNode parent
= node
.getParent();
61 parent
= HibernateProxyHelper
.deproxy(parent
, FeatureNode
.class);
62 List
<FeatureNode
> children
= new ArrayList(node
.getChildNodes());
64 if (config
.getChildHandling().equals(ChildHandling
.DELETE
)){
66 for (FeatureNode child
: children
){
67 deleteFeatureNode(child
.getUuid(), config
);
68 // node.removeChild(child);
71 parent
.removeChild(node
);
77 parent
.removeChild(node
);
78 for (FeatureNode child
: children
){
79 node
.removeChild(child
);
80 parent
.addChild(child
);
84 result
.addException(new ReferencedObjectUndeletableException("The root node can not be deleted without its child nodes"));
90 if (config
.isDeleteElement()){
91 feature
= node
.getFeature();
92 termService
.delete(feature
.getUuid());
101 public DeleteResult
isDeletable(FeatureNode node
, FeatureNodeDeletionConfigurator config
){
102 DeleteResult result
= new DeleteResult();
103 Set
<CdmBase
> references
= commonService
.getReferencingObjectsForDeletion(node
);
104 for (CdmBase ref
:references
){
105 if (ref
instanceof FeatureNode
){
108 if (ref
instanceof FeatureTree
){
109 FeatureTree refTree
= HibernateProxyHelper
.deproxy(ref
, FeatureTree
.class);
110 if (node
.getFeatureTree().equals((refTree
))){
115 result
.addException(new ReferencedObjectUndeletableException("The featureNode is referenced by " + ref
.getUserFriendlyDescription() +" with id " +ref
.getId()));