mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Added removeProperty method to NodeService.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5558 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1022,6 +1022,27 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
|
||||
{
|
||||
Pair<Integer, String> avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
|
||||
if (isBuiltInProperty(qname))
|
||||
{
|
||||
// Ignore
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
fAVMService.deleteNodeProperty(avmVersionPath.getSecond(), qname);
|
||||
}
|
||||
catch (AVMNotFoundException e)
|
||||
{
|
||||
throw new InvalidNodeRefException(avmVersionPath.getSecond() + " not found.", nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper to spoof built in properties.
|
||||
* @param avmVersionPath The broken out version and path from a NodeRef.
|
||||
|
@@ -983,6 +983,11 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
|
||||
assertNotNull("Property value not set", valueCheck);
|
||||
assertEquals("Property value incorrect", "VALUE2", valueCheck);
|
||||
|
||||
// Remove a property
|
||||
nodeService.removeProperty(nodeRef, qnameProperty2);
|
||||
valueCheck = nodeService.getProperty(nodeRef, qnameProperty2);
|
||||
assertNull("Property not removed", valueCheck);
|
||||
|
||||
// set the property value to null
|
||||
try
|
||||
{
|
||||
|
@@ -1047,7 +1047,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
||||
* @return the values of the properties after the set operation is complete
|
||||
* @throws InvalidNodeRefException
|
||||
*/
|
||||
public Map<QName, Serializable> setPropertyImpl(Node node, QName qname, Serializable value) throws InvalidNodeRefException
|
||||
private Map<QName, Serializable> setPropertyImpl(Node node, QName qname, Serializable value) throws InvalidNodeRefException
|
||||
{
|
||||
NodeRef nodeRef = node.getNodeRef();
|
||||
|
||||
@@ -1063,6 +1063,32 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
||||
return getPropertiesImpl(node);
|
||||
}
|
||||
|
||||
public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
|
||||
{
|
||||
if (qname.equals(ContentModel.PROP_NAME))
|
||||
{
|
||||
throw new UnsupportedOperationException("The property " + qname + " may not be removed individually");
|
||||
}
|
||||
|
||||
// Invoke policy behaviours
|
||||
invokeBeforeUpdateNode(nodeRef);
|
||||
|
||||
// Get the node
|
||||
Node node = getNodeNotNull(nodeRef);
|
||||
|
||||
// Get the values before
|
||||
Map<QName, Serializable> propertiesBefore = getPropertiesImpl(node);
|
||||
// Remove the property
|
||||
Map<QName, PropertyValue> properties = node.getProperties();
|
||||
properties.remove(qname);
|
||||
// Get the values afterwards
|
||||
Map<QName, Serializable> propertiesAfter = getPropertiesImpl(node);
|
||||
|
||||
// Invoke policy behaviours
|
||||
invokeOnUpdateNode(nodeRef);
|
||||
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms {@link Node#getParentAssocs()} to a new collection
|
||||
*/
|
||||
|
@@ -376,6 +376,15 @@ public class NodeServiceImpl implements NodeService, VersionModel
|
||||
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws UnsupportedOperationException always
|
||||
*/
|
||||
public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException
|
||||
{
|
||||
// This operation is not supported for a version store
|
||||
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* The node will appear to be attached to the root of the version store
|
||||
*
|
||||
|
@@ -372,12 +372,10 @@ public interface NodeService
|
||||
|
||||
/**
|
||||
* Sets the value of a property to be any <code>Serializable</code> instance.
|
||||
* To remove a property value, use {@link #getProperties(NodeRef)}, remove the
|
||||
* value and call {@link #setProperties(NodeRef, Map<QName,Serializable>)}.
|
||||
* <p>
|
||||
* <b>NOTE:</b> Null values <u>are</u> allowed.
|
||||
*
|
||||
* @param nodeRef
|
||||
* @param nodeRef a reference to an existing node
|
||||
* @param qname the fully qualified name of the property
|
||||
* @param propertyValue the value of the property - never null
|
||||
* @throws InvalidNodeRefException if the node could not be found
|
||||
@@ -385,6 +383,16 @@ public interface NodeService
|
||||
@Auditable(key = Auditable.Key.ARG_0 ,parameters = {"nodeRef", "qname", "value"})
|
||||
public void setProperty(NodeRef nodeRef, QName qname, Serializable value) throws InvalidNodeRefException;
|
||||
|
||||
/**
|
||||
* Removes a property value completely.
|
||||
*
|
||||
* @param nodeRef a reference to an existing node
|
||||
* @param qname the fully qualified name of the property
|
||||
* @throws InvalidNodeRefException if the node could not be found
|
||||
*/
|
||||
@Auditable(key = Auditable.Key.ARG_0 ,parameters = {"nodeRef", "qname"})
|
||||
public void removeProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException;
|
||||
|
||||
/**
|
||||
* @param nodeRef the child node
|
||||
* @return Returns a list of all parent-child associations that exist where the given
|
||||
|
Reference in New Issue
Block a user