Re-added the "templatable" aspect back into the web-client config XML

Refactored cache in Permissions service so it can be re-used by other services e.g. Ownable
Added cache into OwnableService (Andy to validate on Monday)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2081 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-01-06 17:28:23 +00:00
parent 0b80b960b8
commit eff2ff343c
3 changed files with 197 additions and 125 deletions

View File

@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.util.HashMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.cache.AutoExpireCache;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
@@ -28,11 +29,18 @@ import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.namespace.QName;
import org.springframework.beans.factory.InitializingBean;
/**
* Ownership service support. Use in permissions framework as dynamic authority.
*
* @author Andy Hind
*/
public class OwnableServiceImpl implements OwnableService, InitializingBean
{
private NodeService nodeService;
private AuthenticationService authenticationService;
private static AutoExpireCache<NodeRef, String> ownerCache = new AutoExpireCache<NodeRef, String>(1024, 0.75f);
public OwnableServiceImpl()
{
@@ -40,7 +48,7 @@ public class OwnableServiceImpl implements OwnableService, InitializingBean
}
// IOC
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
@@ -54,11 +62,11 @@ public class OwnableServiceImpl implements OwnableService, InitializingBean
public void afterPropertiesSet() throws Exception
{
if(nodeService == null)
if (nodeService == null)
{
throw new IllegalArgumentException("A node service must be set");
}
if(authenticationService == null)
if (authenticationService == null)
{
throw new IllegalArgumentException("An authentication service must be set");
}
@@ -66,28 +74,34 @@ public class OwnableServiceImpl implements OwnableService, InitializingBean
// OwnableService implmentation
public String getOwner(NodeRef nodeRef)
{
String userName = null;
// If ownership is not explicitly set then we fall back to the creator
//
if(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_OWNABLE))
String userName = ownerCache.get(nodeRef);
if (userName == null)
{
userName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER));
}
else if(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUDITABLE))
{
userName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_CREATOR));
// If ownership is not explicitly set then we fall back to the creator
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_OWNABLE))
{
userName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER));
}
else if(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUDITABLE))
{
userName = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_CREATOR));
}
ownerCache.put(nodeRef, userName);
}
return userName;
}
public void setOwner(NodeRef nodeRef, String userName)
{
if(!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_OWNABLE))
ownerCache.remove(nodeRef);
if (!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_OWNABLE))
{
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>(1, 1.0f);
properties.put(ContentModel.PROP_OWNER, userName);
nodeService.addAspect(nodeRef, ContentModel.ASPECT_OWNABLE, properties);
}
@@ -95,7 +109,6 @@ public class OwnableServiceImpl implements OwnableService, InitializingBean
{
nodeService.setProperty(nodeRef, ContentModel.PROP_OWNER, userName);
}
}
public void takeOwnership(NodeRef nodeRef)
@@ -107,5 +120,4 @@ public class OwnableServiceImpl implements OwnableService, InitializingBean
{
return getOwner(nodeRef) != null;
}
}