RM-563 (Add group id and title to Capability API and definitions)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@44277 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2012-12-03 22:32:42 +00:00
parent 583b4412a8
commit a06ba9d3c3
17 changed files with 1413 additions and 1047 deletions

View File

@@ -30,350 +30,331 @@ import org.springframework.extensions.surf.util.I18NUtil;
/**
* Abstract capability implementation.
*
*
* @author Andy Hind
* @author Roy Wetherall
*/
public abstract class AbstractCapability extends RMSecurityCommon
implements Capability, RecordsManagementModel, RMPermissionModel
{
/** Logger */
@SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(AbstractCapability.class);
/** Logger */
@SuppressWarnings("unused")
private static Log logger = LogFactory.getLog(AbstractCapability.class);
/** RM entry voter */
protected RMEntryVoter voter;
/** RM entry voter */
protected RMEntryVoter voter;
/** Capability service */
protected CapabilityService capabilityService;
/** Capability service */
protected CapabilityService capabilityService;
/** Capability name */
protected String name;
/** Capability name */
protected String name;
/** Capability title and description */
protected String title;
protected String description;
/** Capability title and description */
protected String title;
protected String description;
/** Capability group id and title*/
protected String groupId;
protected String groupTitle;
/** Capability Group */
protected Group group;
/** Indicates whether this is a private capability or not */
protected boolean isPrivate = false;
/** Indicates whether this is a private capability or not */
protected boolean isPrivate = false;
/** List of actions */
// protected List<RecordsManagementAction> actions = new ArrayList<RecordsManagementAction>(1);
/** List of actions */
// protected List<RecordsManagementAction> actions = new ArrayList<RecordsManagementAction>(1);
/** Action names */
// protected List<String> actionNames = new ArrayList<String>(1);
/** Action names */
// protected List<String> actionNames = new ArrayList<String>(1);
/**
* @param voter RM entry voter
*/
public void setVoter(RMEntryVoter voter)
{
this.voter = voter;
}
/**
* @param voter RM entry voter
*/
public void setVoter(RMEntryVoter voter)
{
this.voter = voter;
}
/**
* @param capabilityService capability service
*/
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
/**
* @param capabilityService capability service
*/
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
/**
* Init method
*/
public void init()
{
capabilityService.registerCapability(this);
}
/**
* Init method
*/
public void init()
{
capabilityService.registerCapability(this);
}
/**
* Registers an action
*
* @param action
*/
// public void registerAction(RecordsManagementAction action)
// {
// this.actions.add(action);
// this.actionNames.add(action.getName());
// }
/**
* Registers an action
*
* @param action
*/
// public void registerAction(RecordsManagementAction action)
// {
// this.actions.add(action);
// this.actionNames.add(action.getName());
// }
/**
* @param name capability name
*/
public void setName(String name)
{
this.name = name;
}
/**
* @param name capability name
*/
public void setName(String name)
{
this.name = name;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getName()
*/
@Override
public String getName()
{
return name;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getName()
*/
@Override
public String getName()
{
return name;
}
/**
* @param title capability title
*/
public void setTitle(String title)
{
this.title = title;
}
/**
* @param title capability title
*/
public void setTitle(String title)
{
this.title = title;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getTitle()
*/
@Override
public String getTitle()
{
String title = this.title;
if (StringUtils.isBlank(title))
{
title = I18NUtil.getMessage("capability." + getName() + ".title");
}
return title;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getTitle()
*/
@Override
public String getTitle()
{
String title = this.title;
if (StringUtils.isBlank(title))
{
title = I18NUtil.getMessage("capability." + getName() + ".title");
}
return title;
}
/**
* @param description capability description
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @param description capability description
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @param descriptionId message id
*/
public void setDescriptionId(String descriptionId)
{
this.description = I18NUtil.getMessage(descriptionId);
}
/**
* @param descriptionId message id
*/
public void setDescriptionId(String descriptionId)
{
this.description = I18NUtil.getMessage(descriptionId);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getDescription()
*/
@Override
public String getDescription()
{
return description;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getDescription()
*/
@Override
public String getDescription()
{
return description;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#isPrivate()
*/
public boolean isPrivate()
{
return isPrivate;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#isPrivate()
*/
public boolean isPrivate()
{
return isPrivate;
}
/**
* @param isPrivate indicates whether the capability is private or not
*/
public void setPrivate(boolean isPrivate)
{
this.isPrivate = isPrivate;
}
/**
* @param isPrivate indicates whether the capability is private or not
*/
public void setPrivate(boolean isPrivate)
{
this.isPrivate = isPrivate;
}
/**
* Translates the vote to an AccessStatus
*
* @param vote
* @return
*/
private AccessStatus translate(int vote)
{
switch (vote)
{
case AccessDecisionVoter.ACCESS_ABSTAIN:
/**
* Translates the vote to an AccessStatus
*
* @param vote
* @return
*/
private AccessStatus translate(int vote)
{
switch (vote)
{
case AccessDecisionVoter.ACCESS_ABSTAIN:
return AccessStatus.UNDETERMINED;
case AccessDecisionVoter.ACCESS_GRANTED:
case AccessDecisionVoter.ACCESS_GRANTED:
return AccessStatus.ALLOWED;
case AccessDecisionVoter.ACCESS_DENIED:
case AccessDecisionVoter.ACCESS_DENIED:
return AccessStatus.DENIED;
default:
default:
return AccessStatus.UNDETERMINED;
}
}
}
}
/**
*
* @param nodeRef
* @return
*/
// public int checkActionConditionsIfPresent(NodeRef nodeRef)
// {
// String prefix = "checkActionConditionsIfPresent" + getName();
// int result = getTransactionCache(prefix, nodeRef);
// if (result != NOSET_VALUE)
// {
// return result;
// }
/**
*
* @param nodeRef
* @return
*/
// public int checkActionConditionsIfPresent(NodeRef nodeRef)
// {
// String prefix = "checkActionConditionsIfPresent" + getName();
// int result = getTransactionCache(prefix, nodeRef);
// if (result != NOSET_VALUE)
// {
// return result;
// }
//
// if (actions.size() > 0)
// {
// for (RecordsManagementAction action : actions)
// {
// if (action.isExecutable(nodeRef, null))
// if (actions.size() > 0)
// {
// for (RecordsManagementAction action : actions)
// {
// return setTransactionCache(prefix, nodeRef, AccessDecisionVoter.ACCESS_GRANTED);
// if (action.isExecutable(nodeRef, null))
// {
// return setTransactionCache(prefix, nodeRef, AccessDecisionVoter.ACCESS_GRANTED);
// }
// }
// }
// return setTransactionCache(prefix, nodeRef, AccessDecisionVoter.ACCESS_DENIED);
// }
// else
// {
// return setTransactionCache(prefix, nodeRef, AccessDecisionVoter.ACCESS_GRANTED);
// }
// return setTransactionCache(prefix, nodeRef, AccessDecisionVoter.ACCESS_DENIED);
// }
// else
// {
// return setTransactionCache(prefix, nodeRef, AccessDecisionVoter.ACCESS_GRANTED);
// }
// }
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#hasPermission(org.alfresco.service.cmr.repository.NodeRef)
*/
public AccessStatus hasPermission(NodeRef nodeRef)
{
return translate(hasPermissionRaw(nodeRef));
}
/**
* Determines whether the current user has permission on this capability.
* <p>
* Returns the raw permission value.
*
* @param nodeRef node reference
* @return raw permission value
*/
public int hasPermissionRaw(NodeRef nodeRef)
{
String prefix = "hasPermissionRaw" + getName();
int result = getTransactionCache(prefix, nodeRef);
if (result != NOSET_VALUE)
{
return result;
}
if (checkRmRead(nodeRef) == AccessDecisionVoter.ACCESS_DENIED)
{
result = AccessDecisionVoter.ACCESS_DENIED;
}
// else if (checkActionConditionsIfPresent(nodeRef) == AccessDecisionVoter.ACCESS_DENIED)
// {
// result = AccessDecisionVoter.ACCESS_DENIED;
// }
else
{
result = hasPermissionImpl(nodeRef);
}
return setTransactionCache(prefix, nodeRef, result);
}
/**
* Default implementation. Override if different behaviour required.
*
* @param nodeRef
* @return
*/
protected int hasPermissionImpl(NodeRef nodeRef)
{
return evaluate(nodeRef);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#evaluate(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
public int evaluate(NodeRef source, NodeRef target)
{
return AccessDecisionVoter.ACCESS_ABSTAIN;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getActionNames()
*/
// public List<String> getActionNames()
// {
// return actionNames;
// }
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getActions()
*/
// public List<RecordsManagementAction> getActions()
// {
// return actions;
// }
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#hasPermission(org.alfresco.service.cmr.repository.NodeRef)
*/
public AccessStatus hasPermission(NodeRef nodeRef)
{
return translate(hasPermissionRaw(nodeRef));
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getGroup()
*/
public Group getGroup()
{
return this.group;
}
/**
* Determines whether the current user has permission on this capability.
* <p>
* Returns the raw permission value.
*
* @param nodeRef node reference
* @return raw permission value
*/
public int hasPermissionRaw(NodeRef nodeRef)
{
String prefix = "hasPermissionRaw" + getName();
int result = getTransactionCache(prefix, nodeRef);
if (result != NOSET_VALUE)
{
return result;
}
public void setGroup(Group group)
{
this.group = group;
}
if (checkRmRead(nodeRef) == AccessDecisionVoter.ACCESS_DENIED)
{
result = AccessDecisionVoter.ACCESS_DENIED;
}
//else if (checkActionConditionsIfPresent(nodeRef) == AccessDecisionVoter.ACCESS_DENIED)
// {
// result = AccessDecisionVoter.ACCESS_DENIED;
// }
else
{
result = hasPermissionImpl(nodeRef);
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
return result;
}
return setTransactionCache(prefix, nodeRef, result);
}
/**
* Default implementation. Override if different behaviour required.
*
* @param nodeRef
* @return
*/
protected int hasPermissionImpl(NodeRef nodeRef)
{
return evaluate(nodeRef);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#evaluate(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
public int evaluate(NodeRef source, NodeRef target)
{
return AccessDecisionVoter.ACCESS_ABSTAIN;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getActionNames()
*/
// public List<String> getActionNames()
// {
// return actionNames;
// }
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getActions()
*/
// public List<RecordsManagementAction> getActions()
// {
// return actions;
// }
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getGroupId()
*/
public String getGroupId()
{
return this.groupId;
}
public void setGroupId(String groupId)
{
this.groupId = groupId;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Capability#getGroupTitle()
*/
public String getGroupTitle()
{
String groupTitle = this.groupTitle;
if (StringUtils.isBlank(groupTitle))
{
groupTitle = I18NUtil.getMessage("capability.group." + getGroupId() + ".title");
}
return groupTitle;
}
public void setGroupTitle(String groupTitle)
{
this.groupTitle = groupTitle;
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
return result;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final AbstractCapability other = (AbstractCapability) obj;
if (getName() == null)
{
if (other.getName() != null)
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
}
else if (!getName().equals(other.getName()))
return false;
return true;
}
if (getClass() != obj.getClass())
return false;
final AbstractCapability other = (AbstractCapability) obj;
if (getName() == null)
{
if (other.getName() != null)
return false;
}
else if (!getName().equals(other.getName()))
return false;
return true;
}
}

View File

@@ -18,91 +18,81 @@
*/
package org.alfresco.module.org_alfresco_module_rm.capability;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessStatus;
/**
* Capability Interface.
*
*
* @author andyh
* @author Roy Wetherall
*/
public interface Capability
{
/**
* Does this capability apply to this nodeRef?
* @param nodeRef
* @return
*/
AccessStatus hasPermission(NodeRef nodeRef);
/**
* Does this capability apply to this nodeRef?
* @param nodeRef
* @return
*/
AccessStatus hasPermission(NodeRef nodeRef);
/**
*
* @param nodeRef
* @return
*/
int hasPermissionRaw(NodeRef nodeRef);
/**
*
* @param nodeRef
* @return
*/
int hasPermissionRaw(NodeRef nodeRef);
/**
* Evaluates the capability.
*
* @param nodeRef
* @return
*/
int evaluate(NodeRef nodeRef);
/**
* Evaluates the capability.
*
* @param nodeRef
* @return
*/
int evaluate(NodeRef nodeRef);
/**
* Evaluates the capability, taking into account a target.
*
* @param source source node reference
* @param target target node reference
* @return int permission value
*/
int evaluate(NodeRef source, NodeRef target);
/**
* Evaluates the capability, taking into account a target.
*
* @param source source node reference
* @param target target node reference
* @return int permission value
*/
int evaluate(NodeRef source, NodeRef target);
/**
* Indicates whether this is a private capability or not. Private capabilities are used internally, otherwise
* they are made available to the user to assign to roles.
*
* @return boolean true if private, false otherwise
*/
boolean isPrivate();
/**
* Indicates whether this is a private capability or not. Private capabilities are used internally, otherwise
* they are made available to the user to assign to roles.
*
* @return boolean true if private, false otherwise
*/
boolean isPrivate();
/**
* Get the name of the capability
*
* @return String capability name
*/
String getName();
/**
* Get the name of the capability
*
* @return String capability name
*/
String getName();
/**
* Get the title of the capability
*
* @return String capability title
*/
String getTitle();
/**
* Get the title of the capability
*
* @return String capability title
*/
String getTitle();
/**
* Get the description of the capability
*
* @return String capability description
*/
String getDescription();
/**
* Get the description of the capability
*
* @return String capability description
*/
String getDescription();
/**
* Gets the group id of a capability
*
* @return String capability group id
*/
String getGroupId();
/**
* Gets the group title of a capability
*
* @return String capability group title
*/
String getGroupTitle();
/**
* Gets the group of a capability
*
* @return Group capability group
*/
Group getGroup();
}

View File

@@ -27,7 +27,7 @@ import org.alfresco.service.cmr.security.AccessStatus;
/**
* Capability service implementation
*
*
* @author Roy Wetherall
* @since 2.0
*/
@@ -35,14 +35,14 @@ public interface CapabilityService
{
/**
* Register a capability
*
*
* @param capability capability
*/
void registerCapability(Capability capability);
/**
* Get a named capability.
*
*
* @param name capability name
* @return {@link Capability} capability or null if not found
*/
@@ -50,14 +50,14 @@ public interface CapabilityService
/**
* Get a list of all the assignable capabilities.
*
*
* @return {@link Set}<{@link Capability}> set of all the assignable capabilities
*/
Set<Capability> getCapabilities();
/**
* Get a list of all the capabilities, optionally including those that are non-assignable.
*
*
* @param includePrivate indicates that the private, or non-assignable capabilities are included in the result
* @return {@link Set}<{@link Capability}> set of capabilities
*/
@@ -65,7 +65,7 @@ public interface CapabilityService
/**
* Get all the capabilities access state based on the current user for the assignable capabilities.
*
*
* @param nodeRef node reference
* @return
*/
@@ -73,14 +73,14 @@ public interface CapabilityService
/**
* Get all the capabilities access state based on the current user.
*
*
* @param nodeRef node reference
* @return
*/
Map<Capability, AccessStatus> getCapabilitiesAccessState(NodeRef nodeRef, boolean includePrivate);
/**
*
*
* @param nodeRef
* @param capabilityNames
* @return
@@ -89,10 +89,55 @@ public interface CapabilityService
/**
* Helper method to get the access state for a single capability.
*
*
* @param nodeRef
* @param capabilityName
* @return
*/
AccessStatus getCapabilityAccessState(NodeRef nodeRef, String capabilityName);
/**
* Gets the list of all the capability groups (in index order)
*
* @return {@link List}<{@link Group}> List of all the capability groups (in index order)
*/
List<Group> getGroups();
/**
* Gets a list of capabilities for the given group id
*
* @param groupId The id of a group for which the list of capabilities should be retrieved
* @return {@link List}<{@link Capability}> List of capabilities for the given group
*/
List<Capability> getCapabilitiesByGroup(String groupId);
/**
* Get a list of capabilities for the given group
*
* @param group The group for which the list of capabilities should be retrieved
* @return {@link List}<{@link Capability}> List of capabilities for the given group
*/
List<Capability> getCapabilitiesByGroup(Group group);
/**
* Gets a group from it's id
*
* @param groupId The id of the group which should be retrieved
* @return Group The group with the id groupId
*/
Group getGroup(String groupId);
/**
* Adds a group to the list of groups
*
* @param group The group which should be added
*/
void addGroup(Group group);
/**
* Removes a group from the list of groups
*
* @param group The group which should be removed
*/
void removeGroup(Group group);
}

View File

@@ -18,7 +18,9 @@
*/
package org.alfresco.module.org_alfresco_module_rm.capability;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -35,138 +37,233 @@ import org.alfresco.util.ParameterCheck;
*/
public class CapabilityServiceImpl implements CapabilityService
{
/** Capabilities */
private Map<String, Capability> capabilities = new HashMap<String, Capability>(57);
/** Capabilities */
private Map<String, Capability> capabilities = new HashMap<String, Capability>(57);
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapability(java.lang.String)
*/
@Override
public Capability getCapability(String name)
{
ParameterCheck.mandatoryString("name", name);
/** Groups */
private Map<String, Group> groups = new HashMap<String, Group>(13);
return capabilities.get(name);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapability(java.lang.String)
*/
@Override
public Capability getCapability(String name)
{
ParameterCheck.mandatoryString("name", name);
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#registerCapability(org.alfresco.module.org_alfresco_module_rm.capability.Capability)
*/
@Override
public void registerCapability(Capability capability)
{
ParameterCheck.mandatory("capability", capability);
return capabilities.get(name);
}
capabilities.put(capability.getName(), capability);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#registerCapability(org.alfresco.module.org_alfresco_module_rm.capability.Capability)
*/
@Override
public void registerCapability(Capability capability)
{
ParameterCheck.mandatory("capability", capability);
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilities()
*/
@Override
public Set<Capability> getCapabilities()
{
return getCapabilities(true);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilities(boolean)
*/
@Override
public Set<Capability> getCapabilities(boolean includePrivate)
{
Set<Capability> result = null;
if (includePrivate == true)
{
result = new HashSet<Capability>(capabilities.values());
}
else
{
result = new HashSet<Capability>(capabilities.size());
for (Capability capability : capabilities.values())
{
if (capability.isPrivate() == false)
capabilities.put(capability.getName(), capability);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilities()
*/
@Override
public Set<Capability> getCapabilities()
{
return getCapabilities(true);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilities(boolean)
*/
@Override
public Set<Capability> getCapabilities(boolean includePrivate)
{
Set<Capability> result = null;
if (includePrivate == true)
{
result = new HashSet<Capability>(capabilities.values());
}
else
{
result = new HashSet<Capability>(capabilities.size());
for (Capability capability : capabilities.values())
{
result.add(capability);
if (capability.isPrivate() == false)
{
result.add(capability);
}
}
}
}
}
return result;
}
return result;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesAccessState(org.alfresco.service.cmr.repository.NodeRef)
*/
public Map<Capability, AccessStatus> getCapabilitiesAccessState(NodeRef nodeRef)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesAccessState(org.alfresco.service.cmr.repository.NodeRef)
*/
public Map<Capability, AccessStatus> getCapabilitiesAccessState(NodeRef nodeRef)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
return getCapabilitiesAccessState(nodeRef, false);
}
return getCapabilitiesAccessState(nodeRef, false);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesAccessState(org.alfresco.service.cmr.repository.NodeRef, boolean)
*/
@Override
public Map<Capability, AccessStatus> getCapabilitiesAccessState(NodeRef nodeRef, boolean includePrivate)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesAccessState(org.alfresco.service.cmr.repository.NodeRef, boolean)
*/
@Override
public Map<Capability, AccessStatus> getCapabilitiesAccessState(NodeRef nodeRef, boolean includePrivate)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
Set<Capability> listOfCapabilites = getCapabilities(includePrivate);
HashMap<Capability, AccessStatus> answer = new HashMap<Capability, AccessStatus>();
for (Capability capability : listOfCapabilites)
{
AccessStatus status = capability.hasPermission(nodeRef);
if (answer.put(capability, status) != null)
{
throw new IllegalStateException();
}
}
return answer;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesAccessState(org.alfresco.service.cmr.repository.NodeRef, java.util.List)
*/
public Map<Capability, AccessStatus> getCapabilitiesAccessState(NodeRef nodeRef, List<String> capabilityNames)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("capabilityNames", capabilityNames);
HashMap<Capability, AccessStatus> answer = new HashMap<Capability, AccessStatus>();
for (String capabilityName : capabilityNames)
{
Capability capability = capabilities.get(capabilityName);
if (capability != null)
{
Set<Capability> listOfCapabilites = getCapabilities(includePrivate);
HashMap<Capability, AccessStatus> answer = new HashMap<Capability, AccessStatus>();
for (Capability capability : listOfCapabilites)
{
AccessStatus status = capability.hasPermission(nodeRef);
if (answer.put(capability, status) != null)
{
throw new IllegalStateException();
throw new IllegalStateException();
}
}
}
return answer;
}
}
return answer;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilityAccessState(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
*/
@Override
public AccessStatus getCapabilityAccessState(NodeRef nodeRef, String capabilityName)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("capabilityName", capabilityName);
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesAccessState(org.alfresco.service.cmr.repository.NodeRef, java.util.List)
*/
public Map<Capability, AccessStatus> getCapabilitiesAccessState(NodeRef nodeRef, List<String> capabilityNames)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("capabilityNames", capabilityNames);
AccessStatus result = AccessStatus.UNDETERMINED;
Capability capability = getCapability(capabilityName);
if (capability != null)
{
List<String> list = Collections.singletonList(capabilityName);
Map<Capability, AccessStatus> map = getCapabilitiesAccessState(nodeRef, list);
result = map.get(capability);
}
return result;
}
HashMap<Capability, AccessStatus> answer = new HashMap<Capability, AccessStatus>();
for (String capabilityName : capabilityNames)
{
Capability capability = capabilities.get(capabilityName);
if (capability != null)
{
AccessStatus status = capability.hasPermission(nodeRef);
if (answer.put(capability, status) != null)
{
throw new IllegalStateException();
}
}
}
return answer;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilityAccessState(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
*/
@Override
public AccessStatus getCapabilityAccessState(NodeRef nodeRef, String capabilityName)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("capabilityName", capabilityName);
AccessStatus result = AccessStatus.UNDETERMINED;
Capability capability = getCapability(capabilityName);
if (capability != null)
{
List<String> list = Collections.singletonList(capabilityName);
Map<Capability, AccessStatus> map = getCapabilitiesAccessState(nodeRef, list);
result = map.get(capability);
}
return result;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getGroups()
*/
@Override
public List<Group> getGroups()
{
List<Group> groups = new ArrayList<Group>();
for (Map.Entry<String, Group> entry : this.groups.entrySet())
{
groups.add(entry.getValue());
}
Collections.sort(groups, new Comparator<Group>()
{
public int compare(Group g1, Group g2)
{
return Integer.parseInt(g1.getIndex()) - Integer.parseInt(g2.getIndex());
}
});
return groups;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesByGroup(java.lang.String)
*/
@Override
public List<Capability> getCapabilitiesByGroup(String groupId)
{
ParameterCheck.mandatoryString("groupId", groupId);
String id = this.groups.get(groupId).getId();
List<Capability> capabilities = new ArrayList<Capability>();
for (Capability capability : getCapabilities())
{
Group group = capability.getGroup();
if (group != null)
{
if (group.getId().equalsIgnoreCase(id))
{
capabilities.add(capability);
}
}
}
return capabilities;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getCapabilitiesByGroup(org.alfresco.module.org_alfresco_module_rm.capability.Group)
*/
@Override
public List<Capability> getCapabilitiesByGroup(Group group)
{
ParameterCheck.mandatory("group", group);
return getCapabilitiesByGroup(group.getId());
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#getGroup(java.lang.String)
*/
@Override
public Group getGroup(String groupId)
{
ParameterCheck.mandatoryString("groupId", groupId);
return this.groups.get(groupId);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#addGroup(org.alfresco.module.org_alfresco_module_rm.capability.Group)
*/
@Override
public void addGroup(Group group)
{
ParameterCheck.mandatory("group", group);
groups.put(group.getId(), group);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService#removeGroup(org.alfresco.module.org_alfresco_module_rm.capability.Group)
*/
@Override
public void removeGroup(Group group)
{
ParameterCheck.mandatory("group", group);
groups.remove(group.getId());
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.capability;
/**
* Group interface
*
* @author Tuna Aksoy
* @since 2.1
*/
public interface Group
{
/**
* Gets the id of a group (Get the id of the group)
*
* @return String the group id
*/
String getId();
/**
* Gets the title of a group
*
* @return String the group title
*/
String getTitle();
/**
* Gets the index of a group
*
* @return String the group index
*/
String getIndex();
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.capability;
import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Group implementation
*
* @author Tuna Aksoy
* @since 2.1
*/
public class GroupImpl implements Group
{
/** The group id */
private String id;
/** The group title */
private String title;
/** The group index */
private String index;
/** Capability service */
private CapabilityService capabilityService;
/**
* Sets the capability service
*
* @param capabilityService the capability service
*/
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
public void init()
{
this.capabilityService.addGroup(this);
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Group#getId()
*/
@Override
public String getId()
{
return this.id;
}
public void setId(String id)
{
this.id = id;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Group#getTitle()
*/
@Override
public String getTitle()
{
String title = this.title;
if (StringUtils.isBlank(title))
{
title = I18NUtil.getMessage("capability.group." + getId() + ".title");
}
return title;
}
public void setTitle(String title)
{
this.title = title;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.capability.Group#getIndex()
*/
@Override
public String getIndex()
{
return this.index;
}
public void setIndex(String index)
{
this.index = index;
}
}

View File

@@ -22,13 +22,14 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.capability.Group;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AccessStatus;
@@ -41,165 +42,169 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
public class CapabilitiesGet extends DeclarativeWebScript
{
private RecordsManagementService recordsManagementService;
private RecordsManagementService recordsManagementService;
private CapabilityService capabilityService;
private CapabilityService capabilityService;
public void setRecordsManagementService(RecordsManagementService recordsManagementService)
{
this.recordsManagementService = recordsManagementService;
}
public void setRecordsManagementService(RecordsManagementService recordsManagementService)
{
this.recordsManagementService = recordsManagementService;
}
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
/**
* @see org.alfresco.repo.web.scripts.content.StreamContent#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String storeType = templateVars.get("store_type");
String storeId = templateVars.get("store_id");
String nodeId = templateVars.get("id");
/**
* @see org.alfresco.repo.web.scripts.content.StreamContent#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String storeType = templateVars.get("store_type");
String storeId = templateVars.get("store_id");
String nodeId = templateVars.get("id");
NodeRef nodeRef = null;
if (StringUtils.isNotBlank(storeType) && StringUtils.isNotBlank(storeId) && StringUtils.isNotBlank(nodeId))
{
nodeRef = new NodeRef(new StoreRef(storeType, storeId), nodeId);
}
else
{
// we are talking about the file plan node
// TODO we are making the assumption there is only one file plan here!
List<NodeRef> filePlans = recordsManagementService.getFilePlans();
if (filePlans.isEmpty() == true)
{
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No file plan node has been found.");
}
else if (filePlans.size() != 1)
{
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "More than one file plan has been found.");
}
nodeRef = filePlans.get(0);
}
boolean grouped = false;
String groupedString = req.getParameter("grouped");
if (StringUtils.isNotBlank(groupedString))
{
grouped = Boolean.parseBoolean(groupedString);
}
Map<String, Object> model = new HashMap<String, Object>(1);
if (grouped == true)
{
// Construct the map which is needed to build the model
Map<String, GroupedCapabilities> groupedCapabilitiesMap = new HashMap<String, GroupedCapabilities>(13);
Set<Capability> capabilities = capabilityService.getCapabilities();
for (Capability capability : capabilities)
{
String capabilityGroupTitle = capability.getGroupTitle();
if (StringUtils.isNotBlank(capabilityGroupTitle))
NodeRef nodeRef = null;
if (StringUtils.isNotBlank(storeType) && StringUtils.isNotBlank(storeId) && StringUtils.isNotBlank(nodeId))
{
nodeRef = new NodeRef(new StoreRef(storeType, storeId), nodeId);
}
else
{
// we are talking about the file plan node
// TODO we are making the assumption there is only one file plan here!
List<NodeRef> filePlans = recordsManagementService.getFilePlans();
if (filePlans.isEmpty() == true)
{
String capabilityGroupId = capability.getGroupId();
String capabilityName = capability.getName();
String capabilityTitle = capability.getTitle();
if (groupedCapabilitiesMap.containsKey(capabilityGroupId))
{
groupedCapabilitiesMap.get(capabilityGroupId).addCapability(capabilityName, capabilityTitle);
}
else
{
GroupedCapabilities groupedCapabilities = new GroupedCapabilities(capabilityGroupId, capabilityGroupTitle, capabilityName, capabilityTitle);
groupedCapabilities.addCapability(capabilityName, capabilityTitle);
groupedCapabilitiesMap.put(capabilityGroupId, groupedCapabilities);
}
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No file plan node has been found.");
}
}
model.put("groupedCapabilities", groupedCapabilitiesMap);
}
else
{
boolean includePrivate = false;
String includePrivateString = req.getParameter("includeAll");
if (StringUtils.isNotBlank(includePrivateString))
{
includePrivate = Boolean.parseBoolean(includePrivateString);
}
Map<Capability, AccessStatus> map = capabilityService.getCapabilitiesAccessState(nodeRef, includePrivate);
List<String> list = new ArrayList<String>(map.size());
for (Map.Entry<Capability, AccessStatus> entry : map.entrySet())
{
AccessStatus accessStatus = entry.getValue();
if (AccessStatus.DENIED.equals(accessStatus) == false)
else if (filePlans.size() != 1)
{
Capability capability = entry.getKey();
list.add(capability.getName());
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "More than one file plan has been found.");
}
}
model.put("capabilities", list);
}
nodeRef = filePlans.get(0);
}
return model;
}
boolean grouped = false;
String groupedString = req.getParameter("grouped");
if (StringUtils.isNotBlank(groupedString))
{
grouped = Boolean.parseBoolean(groupedString);
}
/**
* Class to represent grouped capabilities for use in a Freemarker template
*
*/
public class GroupedCapabilities
{
private String capabilityGroupId;
private String capabilityGroupTitle;
private String capabilityName;
private String capabilityTitle;
private Map<String, String> capabilities;
Map<String, Object> model = new HashMap<String, Object>(1);
if (grouped == true)
{
// Construct the map which is needed to build the model
Map<String, GroupedCapabilities> groupedCapabilitiesMap = new TreeMap<String, GroupedCapabilities>();
public GroupedCapabilities(String capabilityGroupId, String capabilityGroupTitle, String capabilityName, String capabilityTitle)
{
this.capabilityGroupId = capabilityGroupId;
this.capabilityGroupTitle = capabilityGroupTitle;
this.capabilityName = capabilityName;
this.capabilityTitle = capabilityTitle;
this.capabilities = new HashMap<String, String>(5);
}
List<Group> groups = capabilityService.getGroups();
for (Group group : groups)
{
String capabilityGroupTitle = group.getTitle();
if (StringUtils.isNotBlank(capabilityGroupTitle))
{
String capabilityGroupId = group.getId();
public String getGroupId()
{
return this.capabilityGroupId;
}
List<Capability> capabilities = capabilityService.getCapabilitiesByGroup(capabilityGroupId);
for (Capability capability : capabilities)
{
String capabilityName = capability.getName();
String capabilityTitle = capability.getTitle();
public String getGroupTitle()
{
return this.capabilityGroupTitle;
}
if (groupedCapabilitiesMap.containsKey(capabilityGroupId))
{
groupedCapabilitiesMap.get(capabilityGroupId).addCapability(capabilityName, capabilityTitle);
}
else
{
GroupedCapabilities groupedCapabilities = new GroupedCapabilities(capabilityGroupId, capabilityGroupTitle, capabilityName, capabilityTitle);
groupedCapabilities.addCapability(capabilityName, capabilityTitle);
groupedCapabilitiesMap.put(capabilityGroupId, groupedCapabilities);
}
}
}
}
model.put("groupedCapabilities", groupedCapabilitiesMap);
}
else
{
boolean includePrivate = false;
String includePrivateString = req.getParameter("includeAll");
if (StringUtils.isNotBlank(includePrivateString))
{
includePrivate = Boolean.parseBoolean(includePrivateString);
}
public String getCapabilityName()
{
return this.capabilityName;
}
Map<Capability, AccessStatus> map = capabilityService.getCapabilitiesAccessState(nodeRef, includePrivate);
List<String> list = new ArrayList<String>(map.size());
for (Map.Entry<Capability, AccessStatus> entry : map.entrySet())
{
AccessStatus accessStatus = entry.getValue();
if (AccessStatus.DENIED.equals(accessStatus) == false)
{
Capability capability = entry.getKey();
list.add(capability.getName());
}
}
model.put("capabilities", list);
}
public String getCapabilityTitle()
{
return this.capabilityTitle;
}
return model;
}
public Map<String, String> getCapabilities()
{
return this.capabilities;
}
/**
* Class to represent grouped capabilities for use in a Freemarker template
*
*/
public class GroupedCapabilities
{
private String capabilityGroupId;
private String capabilityGroupTitle;
private String capabilityName;
private String capabilityTitle;
private Map<String, String> capabilities;
public void addCapability(String capabilityName, String capabilityTitle)
{
this.capabilities.put(capabilityName, capabilityTitle);
}
}
public GroupedCapabilities(String capabilityGroupId, String capabilityGroupTitle, String capabilityName, String capabilityTitle)
{
this.capabilityGroupId = capabilityGroupId;
this.capabilityGroupTitle = capabilityGroupTitle;
this.capabilityName = capabilityName;
this.capabilityTitle = capabilityTitle;
this.capabilities = new HashMap<String, String>(5);
}
public String getGroupId()
{
return this.capabilityGroupId;
}
public String getGroupTitle()
{
return this.capabilityGroupTitle;
}
public String getCapabilityName()
{
return this.capabilityName;
}
public String getCapabilityTitle()
{
return this.capabilityTitle;
}
public Map<String, String> getCapabilities()
{
return this.capabilities;
}
public void addCapability(String capabilityName, String capabilityTitle)
{
this.capabilities.put(capabilityName, capabilityTitle);
}
}
}