-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator;
+import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.FeatureNode;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
import eu.etaxonomy.cdm.persistence.dao.description.IFeatureNodeDao;
/**
* @author n.hoffmann
- * @created Aug 5, 2010
+ * @since Aug 5, 2010
* @version 1.0
*/
@Service
@Override
@Transactional(readOnly = false)
- public DeleteResult deleteFeatureNode(UUID nodeUuid, NodeDeletionConfigurator config) {
+ public DeleteResult deleteFeatureNode(UUID nodeUuid, FeatureNodeDeletionConfigurator config) {
DeleteResult result = new DeleteResult();
FeatureNode node = HibernateProxyHelper.deproxy(dao.load(nodeUuid), FeatureNode.class);
result = isDeletable(node, config);
Feature feature;
if (result.isOk()){
-
+ FeatureNode parent = node.getParent();
+ parent = HibernateProxyHelper.deproxy(parent, FeatureNode.class);
List<FeatureNode> children = new ArrayList(node.getChildNodes());
if (config.getChildHandling().equals(ChildHandling.DELETE)){
for (FeatureNode child: children){
- node.removeChild(child);
deleteFeatureNode(child.getUuid(), config);
+ // node.removeChild(child);
}
+ if (parent != null){
+ parent.removeChild(node);
+ }
+
} else{
- FeatureNode parent = node.getParent();
+
if (parent != null){
parent.removeChild(node);
for (FeatureNode child: children){
}
dao.delete(node);
+ result.addDeletedObject(node);
+ if(parent!=null){
+ result.addUpdatedObject(parent);
+ }
if (config.isDeleteElement()){
feature = node.getFeature();
termService.delete(feature.getUuid());
+ result.addDeletedObject(feature);
}
}
+ return result;
+ }
+ @Override
+ public UpdateResult createChildFeatureNode(FeatureNode node, Feature featureChild){
+ Feature feature = (Feature) termService.save(featureChild);
+ return addChildFeatureNode(node, feature);
+ }
+ @Override
+ public UpdateResult addChildFeatureNode(FeatureNode node, Feature featureChild){
+ FeatureNode childNode = FeatureNode.NewInstance(featureChild);
+ UpdateResult result = new UpdateResult();
+ node.addChild(childNode);
+ save(childNode);
+ result.addUpdatedObject(node);
+ result.setCdmEntity(childNode);
return result;
}
@Override
- public DeleteResult isDeletable(FeatureNode node, NodeDeletionConfigurator config){
+ public UpdateResult addChildFeatureNode(UUID nodeUUID, UUID featureChildUuid){
+ FeatureNode node = load(nodeUUID);
+ Feature child = HibernateProxyHelper.deproxy(termService.load(featureChildUuid), Feature.class);
+ return addChildFeatureNode(node, child);
+ }
+
+ @Override
+ public DeleteResult isDeletable(FeatureNode node, FeatureNodeDeletionConfigurator config){
DeleteResult result = new DeleteResult();
Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(node);
for (CdmBase ref:references){
if (ref instanceof FeatureNode){
break;
}
+ if (ref instanceof FeatureTree){
+ FeatureTree refTree = HibernateProxyHelper.deproxy(ref, FeatureTree.class);
+ if (node.getFeatureTree().equals((refTree))){
+ break;
+ }
+ }
result.setAbort();
- result.addException(new ReferencedObjectUndeletableException("The featureNode is referenced ..."));
+ result.addException(new ReferencedObjectUndeletableException("The featureNode is referenced by " + ref.getUserFriendlyDescription() +" with id " +ref.getId()));
}
return result;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UpdateResult moveFeatureNode(UUID movedNodeUuid, UUID targetNodeUuid, int position) {
+ UpdateResult result = new UpdateResult();
+ FeatureNode movedNode = HibernateProxyHelper.deproxy(load(movedNodeUuid), FeatureNode.class);
+ FeatureNode targetNode = HibernateProxyHelper.deproxy(load(targetNodeUuid), FeatureNode.class);
+ FeatureNode parent = HibernateProxyHelper.deproxy(movedNode.getParent(), FeatureNode.class);
+ if(position<0){
+ targetNode.addChild(movedNode);
+ }
+ else{
+ targetNode.addChild(movedNode, position);
+ }
+ result.addUpdatedObject(targetNode);
+ if(parent!=null){
+ result.addUpdatedObject(parent);
+ }
+ result.setCdmEntity(movedNode);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UpdateResult moveFeatureNode(UUID movedNodeUuid, UUID targetNodeUuid) {
+ return moveFeatureNode(movedNodeUuid, targetNodeUuid, -1);
+ }
+
}