diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index 1a2d5b7f2a..6b39d6389f 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -50,7 +50,6 @@ - @@ -440,7 +439,10 @@ - + + + + @@ -466,10 +468,13 @@ @@ -597,7 +602,11 @@ org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.createRole=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.updateRole=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.deleteRole=RM_ALLOW + org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.getUsersAssignedToRole=RM.Read.0 + org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.getGroupsAssignedToRole=RM.Read.0 + org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.getAllAssignedToRole=RM.Read.0 org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.assignRoleToAuthority=RM_ALLOW + org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.unassignRoleFromAuthority=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.getAllRolesContainerGroup=RM_ALLOW org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService.*=RM_DENY ]]> diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml index 0d6f8ccc87..aee66f263a 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml @@ -268,38 +268,43 @@ - + + - + + - + + - + + - + + diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.delete.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.delete.desc.xml index c7b6c75835..1cd7262836 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.delete.desc.xml +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.delete.desc.xml @@ -6,7 +6,9 @@ ]]> - /api/rma/admin/rmroles/{rolename} + /api/rma/admin/rmroles/{rolename} + /api/rma/admin/{siteid}/rmroles/{rolename} + /api/rma/admin/{store_type}/{store_id}/{id}/rmroles/{rolename} argument user required diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.get.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.get.desc.xml index 21693f3819..75a9fa715c 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.get.desc.xml +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.get.desc.xml @@ -6,7 +6,9 @@ ]]> - /api/rma/admin/rmroles/{rolename} + /api/rma/admin/rmroles/{rolename} + /api/rma/admin/{siteid}/rmroles/{rolename} + /api/rma/admin/{store_type}/{store_id}/{id}/rmroles/{rolename} argument user required diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.lib.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.lib.ftl index f1404c3d2a..cc454571ba 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.lib.ftl +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.lib.ftl @@ -10,6 +10,27 @@ "${capability.name}": "${capability.title}" <#if capability_has_next>, } + <#if role.showAuths> + , + "assignedUsers" : + [ + <#list role.assignedUsers as user> + { + "name" : "${user.name}", + "displayLabel" : "${user.displayLabel}" + }<#if user_has_next>, + + ], + "assignedGroups" : + [ + <#list role.assignedGroups as group> + { + "name" : "${group.name}", + "displayLabel" : "${group.displayLabel}" + }<#if group_has_next>, + + ] + } \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.put.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.put.desc.xml index 7849806794..093b5e49c9 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.put.desc.xml +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmrole.put.desc.xml @@ -6,7 +6,9 @@ ]]> - /api/rma/admin/rmroles/{rolename} + /api/rma/admin/rmroles/{rolename} + /api/rma/admin/{siteid}/rmroles/{rolename} + /api/rma/admin/{store_type}/{store_id}/{id}/rmroles/{rolename} argument user required diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmroles.get.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmroles.get.desc.xml index c3dd070b97..ec3ef12310 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmroles.get.desc.xml +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmroles.get.desc.xml @@ -1,12 +1,19 @@ - Get list of records management roles + Get list of records management roles and their details, for a file plan. - /api/rma/admin/rmroles?user={user?} + /api/rma/admin/rmroles?user={user?}&auths={auths?} + /api/rma/admin/{store_type}/{store_id}/{id}/rmroles?user={user?}&auths={auths?} + /api/rma/admin/{siteid}/rmroles?user={user?}&auths={auths?} argument user required diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmroles.post.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmroles.post.desc.xml index 205815899c..9486b8337b 100644 --- a/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmroles.post.desc.xml +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/rma/admin/rmrole/rmroles.post.desc.xml @@ -6,7 +6,9 @@ ]]> - /api/rma/admin/rmroles + /api/rma/admin/rmroles + /api/rma/admin/{siteid}/rmroles + /api/rma/admin/{store_type}/{store_id}/{id}/rmroles argument user required diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementService.java index 1f8d5a4ff2..d5020c82db 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementService.java @@ -154,8 +154,11 @@ public interface RecordsManagementService /** * Gets the file plan the node is in. * - * @return {@link NodeRef} file node reference, null if none + * @return {@link NodeRef} file node reference, null if none + * + * @deprecated As of 2.1, see {@link FilePlanService#getFilePlan(NodeRef)} */ + @Deprecated NodeRef getFilePlan(NodeRef nodeRef); /********** File Plan Methods **********/ @@ -165,11 +168,11 @@ public interface RecordsManagementService * Searches the SpacesStore by default. * * @return List list of file plan nodes + * @deprecated As of 2.1, see {@link FilePlanService#getFilePlans()} */ + @Deprecated List getFilePlans(); - // TODO NodeRef getFilePlanById(String id); - /** * Creates a file plan as a child of the given parent node, with the name * provided. diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java index df5c56d9eb..72dd07686c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/RecordsManagementServiceImpl.java @@ -35,7 +35,6 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomM import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl; -import org.alfresco.repo.domain.node.NodeDAO; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; @@ -47,8 +46,10 @@ import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; -import org.alfresco.util.Pair; import org.alfresco.util.ParameterCheck; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.extensions.surf.util.I18NUtil; /** @@ -60,7 +61,8 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl implements RecordsManagementService, RecordsManagementModel, RecordsManagementPolicies.OnCreateReference, - RecordsManagementPolicies.OnRemoveReference + RecordsManagementPolicies.OnRemoveReference, + ApplicationContextAware { /** I18N */ private final static String MSG_ERROR_ADD_CONTENT_CONTAINER = "rm.service.error-add-content-container"; @@ -86,9 +88,6 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl /** Service registry */ private RecordsManagementServiceRegistry serviceRegistry; - - /** Node DAO */ - private NodeDAO nodeDAO; /** Policy component */ private PolicyComponent policyComponent; @@ -99,6 +98,18 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl /** Java behaviour */ private JavaBehaviour onChangeToDispositionActionDefinition; + /** Application context */ + private ApplicationContext applicationContext; + + /** + * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException + { + this.applicationContext = applicationContext; + } + /** * Set the service registry service * @@ -120,16 +131,6 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl { this.policyComponent = policyComponent; } - - /** - * Set the node DAO object - * - * @param nodeDAO node DAO - */ - public void setNodeDAO(NodeDAO nodeDAO) - { - this.nodeDAO = nodeDAO; - } /** * Sets the default RM store reference @@ -571,32 +572,13 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl /** * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementService#getFilePlan(org.alfresco.service.cmr.repository.NodeRef) + * @deprecated As of 2.1, see {@link FilePlanService#getFilePlan(NodeRef)} */ + @Deprecated public NodeRef getFilePlan(NodeRef nodeRef) { - NodeRef result = null; - - if (nodeRef != null) - { - result = (NodeRef)nodeService.getProperty(nodeRef, PROP_ROOT_NODEREF); - if (result == null) - { - if (instanceOf(nodeRef, TYPE_FILE_PLAN) == true) - { - result = nodeRef; - } - else - { - ChildAssociationRef parentAssocRef = nodeService.getPrimaryParent(nodeRef); - if (parentAssocRef != null) - { - result = getFilePlan(parentAssocRef.getParentRef()); - } - } - } - } - - return result; + FilePlanService filePlanService = (FilePlanService)applicationContext.getBean("filePlanService"); + return filePlanService.getFilePlan(nodeRef); } /** @@ -648,27 +630,13 @@ public class RecordsManagementServiceImpl extends ServiceBaseImpl /** * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementService#getRecordsManagementRoots(org.alfresco.service.cmr.repository.StoreRef) + * + * @deprecated As of 2.1, see {@link FilePlanService#getFilePlans()} */ + @Deprecated public List getFilePlans() { - final List results = new ArrayList(); - Set aspects = new HashSet(1); - aspects.add(ASPECT_RECORDS_MANAGEMENT_ROOT); - nodeDAO.getNodesWithAspects(aspects, Long.MIN_VALUE, Long.MAX_VALUE, new NodeDAO.NodeRefQueryCallback() - { - @Override - public boolean handle(Pair nodePair) - { - NodeRef nodeRef = nodePair.getSecond(); - if (StoreRef.STORE_REF_ARCHIVE_SPACESSTORE.equals(nodeRef.getStoreRef()) == false) - { - results.add(nodeRef); - } - - return true; - } - }); - return results; + return new ArrayList(serviceRegistry.getFilePlanService().getFilePlans()); } /** diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMPermissionModel.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMPermissionModel.java index 3b2c329dfa..50cc4ff0d9 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMPermissionModel.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMPermissionModel.java @@ -29,28 +29,15 @@ import org.alfresco.repo.security.permissions.impl.SimplePermissionReference; public interface RMPermissionModel { // Assignment of Filing - public static final String FILING = "Filing"; - public static final String READ_RECORDS = "ReadRecords"; - public static final String FILE_RECORDS = "FileRecords"; // Roles - public static final String ROLE_NAME_USER = "User"; - //public static final String ROLE_USER = SimplePermissionReference.getPermissionReference(RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT, ROLE_NAME_USER).toString(); - public static final String ROLE_NAME_POWER_USER = "PowerUser"; - // public static final String ROLE_POWER_USER = SimplePermissionReference.getPermissionReference(RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT, ROLE_NAME_POWER_USER).toString(); - public static final String ROLE_NAME_SECURITY_OFFICER = "SecurityOfficer"; - // public static final String ROLE_SECURITY_OFFICER = SimplePermissionReference.getPermissionReference(RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT, ROLE_NAME_SECURITY_OFFICER) - // .toString(); - public static final String ROLE_NAME_RECORDS_MANAGER = "RecordsManager"; - // public static final String ROLE_RECORDS_MANAGER = SimplePermissionReference.getPermissionReference(RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT, ROLE_NAME_RECORDS_MANAGER) - // .toString(); public static final String ROLE_NAME_ADMINISTRATOR = "Administrator"; public static final String ROLE_ADMINISTRATOR = SimplePermissionReference.getPermissionReference(RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT, ROLE_NAME_ADMINISTRATOR).toString(); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanService.java index 9676e36bba..fbae15f2cc 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanService.java @@ -18,7 +18,10 @@ */ package org.alfresco.module.org_alfresco_module_rm.fileplan; +import java.util.Set; + import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; import com.hazelcast.impl.Node; @@ -38,6 +41,38 @@ public interface FilePlanService */ boolean isFilePlan(NodeRef nodeRef); + /** + * Gets all the file plan nodes. + * Looks in the SpacesStore by default. + * + * @return Set set of file plan nodes + */ + Set getFilePlans(); + + /** + * Getse all the file plan nodes in a store. + * + * @param storeRef store reference + * @return Set set of file plan nodes + */ + Set getFilePlans(StoreRef storeRef); + + /** + * Gets the file plan the node is in. + * + * @return {@link NodeRef} file node reference, null if none + */ + NodeRef getFilePlan(NodeRef nodeRef); + + /** + * Gets a file plan by site id. Assumes the site is a RM site and that the file plan node, ie + * the document library container, has been already created. Otherwise returns null. + * + * @param siteId records management site id + * @return NodeRef file plan, null if can't be found + */ + NodeRef getFilePlanBySiteId(String siteId); + /** * Indicates whether the unfiled container exists for a given file plan or not. * diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java index 92d4479c64..fc23697dd9 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java @@ -20,8 +20,10 @@ package org.alfresco.module.org_alfresco_module_rm.fileplan; import java.io.Serializable; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; @@ -31,10 +33,16 @@ import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedReaderDynamicAuthority; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedWriterDynamicAuthority; import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl; +import org.alfresco.repo.domain.node.NodeDAO; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.cmr.site.SiteInfo; +import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; import org.alfresco.util.ParameterCheck; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -55,12 +63,27 @@ public class FilePlanServiceImpl extends ServiceBaseImpl private static final String NAME_UNFILED_CONTAINER = "Unfiled Records"; private static final QName QNAME_UNFILED_CONTAINER = QName.createQName(RM_URI, NAME_UNFILED_CONTAINER); + /** RM site file plan container */ + private static final String FILE_PLAN_CONTAINER = "documentLibrary"; + /** Services */ private PermissionService permissionService; /** Application context */ private ApplicationContext applicationContext; + /** Node DAO */ + private NodeDAO nodeDAO; + + /** Internal node service */ + private NodeService internalNodeService; + + /** Site service */ + private SiteService siteService; + + /** + * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + */ @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { @@ -86,6 +109,30 @@ public class FilePlanServiceImpl extends ServiceBaseImpl this.permissionService = permissionService; } + /** + * @param nodeDAO node DAO + */ + public void setNodeDAO(NodeDAO nodeDAO) + { + this.nodeDAO = nodeDAO; + } + + /** + * @param internalNodeService node service (internal bean) + */ + public void setInternalNodeService(NodeService internalNodeService) + { + this.internalNodeService = internalNodeService; + } + + /** + * @param siteService site service + */ + public void setSiteService(SiteService siteService) + { + this.siteService = siteService; + } + /** * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#isFilePlan(org.alfresco.service.cmr.repository.NodeRef) */ @@ -94,6 +141,97 @@ public class FilePlanServiceImpl extends ServiceBaseImpl return instanceOf(nodeRef, TYPE_FILE_PLAN); } + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#getFilePlans() + */ + @Override + public Set getFilePlans() + { + return getFilePlans(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#getFilePlans(org.alfresco.service.cmr.repository.StoreRef) + */ + @Override + public Set getFilePlans(final StoreRef storeRef) + { + ParameterCheck.mandatory("storeRef", storeRef); + + final Set results = new HashSet(); + Set aspects = new HashSet(1); + aspects.add(ASPECT_RECORDS_MANAGEMENT_ROOT); + nodeDAO.getNodesWithAspects(aspects, Long.MIN_VALUE, Long.MAX_VALUE, new NodeDAO.NodeRefQueryCallback() + { + @Override + public boolean handle(Pair nodePair) + { + NodeRef nodeRef = nodePair.getSecond(); + if (storeRef.equals(nodeRef.getStoreRef()) == true) + { + results.add(nodeRef); + } + + return true; + } + }); + return results; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#getFilePlan(org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + public NodeRef getFilePlan(NodeRef nodeRef) + { + NodeRef result = null; + if (nodeRef != null) + { + result = (NodeRef)internalNodeService.getProperty(nodeRef, PROP_ROOT_NODEREF); + if (result == null) + { + if (instanceOf(nodeRef, TYPE_FILE_PLAN) == true) + { + result = nodeRef; + } + else + { + ChildAssociationRef parentAssocRef = internalNodeService.getPrimaryParent(nodeRef); + if (parentAssocRef != null) + { + result = getFilePlan(parentAssocRef.getParentRef()); + } + } + } + } + + return result; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#getFilePlanBySiteId(java.lang.String) + */ + @Override + public NodeRef getFilePlanBySiteId(String siteId) + { + NodeRef filePlan = null; + + SiteInfo siteInfo = siteService.getSite(siteId); + if (siteInfo != null) + { + if (siteService.hasContainer(siteId, FILE_PLAN_CONTAINER) == true) + { + NodeRef nodeRef = siteService.getContainer(siteId, FILE_PLAN_CONTAINER); + if (instanceOf(nodeRef, TYPE_FILE_PLAN) == true) + { + filePlan = nodeRef; + } + } + } + + return filePlan; + } + /** * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#existsUnfiledContainer(org.alfresco.service.cmr.repository.NodeRef) */ diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleService.java index afb260d62a..c0f3cd1b9e 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleService.java @@ -120,6 +120,33 @@ public interface FilePlanRoleService */ void deleteRole(NodeRef filePlan, String role); + /** + * Gets all the users that have been directly assigned to a role. + * + * @param filePlan file plan + * @param role role + * @return {@link Set}<{@link String}> set of users + */ + Set getUsersAssignedToRole(NodeRef filePlan, String role); + + /** + * Gets all the groups that have been directly assigned to a role. + * + * @param filePlan file plan + * @param role role + * @return {@link Set}<{@link String}> set of groups + */ + Set getGroupsAssignedToRole(NodeRef filePlan, String role); + + /** + * Gets all the groups and users that have been directly assigned to a role. + * + * @param filePlan file plan + * @param role role + * @return {@link Set}<{@link String}> set of groups and users + */ + Set getAllAssignedToRole(NodeRef filePlan, String role); + /** * Assign a role to an authority * @@ -128,4 +155,14 @@ public interface FilePlanRoleService * @param authorityName authority name */ void assignRoleToAuthority(NodeRef filePlan, String role, String authorityName); + + + /** + * Unassign a role from an authority + * + * @param filePlan file plan + * @param role role + * @param authorityName authority name + */ + void unassignRoleFromAuthority(NodeRef filePlan, String role, String authorityName); } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleServiceImpl.java index 66530648b6..e99c0e2cb5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleServiceImpl.java @@ -47,6 +47,7 @@ import org.alfresco.service.cmr.security.AccessPermission; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.util.ParameterCheck; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONArray; @@ -686,23 +687,105 @@ public class FilePlanRoleServiceImpl implements FilePlanRoleService, } }, AuthenticationUtil.getSystemUserName()); } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService#getUsersAssignedToRole(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) + */ + @Override + public Set getUsersAssignedToRole(final NodeRef filePlan, final String roleName) + { + ParameterCheck.mandatory("filePlan", filePlan); + ParameterCheck.mandatory("roleName", roleName); + + return getAuthoritiesAssignedToRole(filePlan, roleName, AuthorityType.USER); + } + + /** + * Gets all the authorities of a given type directly assigned to the given role in the file plan. + * + * @param filePlan file plan + * @param roleName role name + * @param authorityType authority type + * @return Set directly assigned authorities + */ + private Set getAuthoritiesAssignedToRole(final NodeRef filePlan, final String roleName, final AuthorityType authorityType) + { + return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork>() + { + public Set doWork() throws Exception + { + Role role = getRole(filePlan, roleName); + if (role == null) + { + throw new AlfrescoRuntimeException("Can not get authorities for role " + roleName + ", because it does not exist. (filePlan=" + filePlan.toString() + ")"); + } + return authorityService.getContainedAuthorities(authorityType, role.getRoleGroupName(), false); + } + }, AuthenticationUtil.getSystemUserName()); + + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService#getGroupsAssignedToRole(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) + */ + @Override + public Set getGroupsAssignedToRole(final NodeRef filePlan, final String roleName) + { + ParameterCheck.mandatory("filePlan", filePlan); + ParameterCheck.mandatory("roleName", roleName); + + return getAuthoritiesAssignedToRole(filePlan, roleName, AuthorityType.GROUP); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService#getAllAssignedToRole(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) + */ + @Override + public Set getAllAssignedToRole(NodeRef filePlan, String role) + { + ParameterCheck.mandatory("filePlan", filePlan); + ParameterCheck.mandatory("roleName", role); + + Set result = new HashSet(21); + result.addAll(getUsersAssignedToRole(filePlan, role)); + result.addAll(getGroupsAssignedToRole(filePlan, role)); + return result; + } /** * @see org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService#assignRoleToAuthority(org.alfresco.service.cmr.repository.NodeRef, java.lang.String, java.lang.String) */ - public void assignRoleToAuthority(final NodeRef rmRootNode, final String role, final String authorityName) + public void assignRoleToAuthority(final NodeRef filePlan, final String role, final String authorityName) { - AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() { - public Boolean doWork() throws Exception + public Void doWork() throws Exception { - String roleAuthority = authorityService.getName(AuthorityType.GROUP, getFullRoleName(role, rmRootNode)); + String roleAuthority = authorityService.getName(AuthorityType.GROUP, getFullRoleName(role, filePlan)); authorityService.addAuthority(roleAuthority, authorityName); return null; } }, AuthenticationUtil.getSystemUserName()); } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService#unassignRoleFromAuthority(org.alfresco.service.cmr.repository.NodeRef, java.lang.String, java.lang.String) + */ + @Override + public void unassignRoleFromAuthority(final NodeRef filePlan, final String role, final String authorityName) + { + AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + { + public Void doWork() throws Exception + { + String roleAuthority = authorityService.getName(AuthorityType.GROUP, getFullRoleName(role, filePlan)); + authorityService.removeAuthority(roleAuthority, authorityName); + return null; + + } + }, AuthenticationUtil.getSystemUserName()); + } /** * @see org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService#getAllRolesContainerGroup(org.alfresco.service.cmr.repository.NodeRef) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRoleDelete.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRoleDelete.java index 20c66be130..cc5b7c774d 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRoleDelete.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRoleDelete.java @@ -19,43 +19,30 @@ package org.alfresco.module.org_alfresco_module_rm.script.admin; import java.util.HashMap; -import java.util.List; import java.util.Map; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.extensions.webscripts.Cache; -import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; /** - * + * Delete role web script * * @author Roy Wetherall */ -public class RmRoleDelete extends DeclarativeWebScript +public class RmRoleDelete extends RoleDeclarativeWebScript { + /** Logger */ @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(RmRoleDelete.class); - - private RecordsManagementService rmService; - private FilePlanRoleService filePlanRoleService; - - public void setFilePlanRoleService(FilePlanRoleService filePlanRoleService) - { - this.filePlanRoleService = filePlanRoleService; - } - - public void setRecordsManagementService(RecordsManagementService rmService) - { - this.rmService = rmService; - } + /** + * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache) + */ @Override public Map executeImpl(WebScriptRequest req, Status status, Cache cache) { @@ -69,16 +56,21 @@ public class RmRoleDelete extends DeclarativeWebScript throw new WebScriptException(Status.STATUS_NOT_FOUND, "No role name was provided on the URL."); } - List roots = rmService.getFilePlans(); - NodeRef root = roots.get(0); + // get the file plan + NodeRef filePlan = getFilePlan(req); + if (filePlan == null) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "File plan does not exist."); + } // Check that the role exists - if (filePlanRoleService.existsRole(root, roleParam) == false) + if (filePlanRoleService.existsRole(filePlan, roleParam) == false) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "The role " + roleParam + " does not exist on the records managment root " + root); + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "The role " + roleParam + " does not exist on the records managment root " + filePlan.toString()); } - filePlanRoleService.deleteRole(root, roleParam); + filePlanRoleService.deleteRole(filePlan, roleParam); return model; } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRoleGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRoleGet.java index be10a6ec37..d6d0251089 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRoleGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRoleGet.java @@ -19,42 +19,25 @@ package org.alfresco.module.org_alfresco_module_rm.script.admin; import java.util.HashMap; -import java.util.List; import java.util.Map; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.extensions.webscripts.Cache; -import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; /** - * + * Role GET web script API * * @author Roy Wetherall */ -public class RmRoleGet extends DeclarativeWebScript +public class RmRoleGet extends RoleDeclarativeWebScript { @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(RmRoleGet.class); - - private RecordsManagementService rmService; - private FilePlanRoleService filePlanRoleService; - - public void setFilePlanRoleService(FilePlanRoleService filePlanRoleService) - { - this.filePlanRoleService = filePlanRoleService; - } - - public void setRecordsManagementService(RecordsManagementService rmService) - { - this.rmService = rmService; - } @Override public Map executeImpl(WebScriptRequest req, Status status, Cache cache) @@ -69,18 +52,22 @@ public class RmRoleGet extends DeclarativeWebScript throw new WebScriptException(Status.STATUS_NOT_FOUND, "No role name was provided on the URL."); } - // Get the root records management node - // TODO this should be passed - List roots = rmService.getFilePlans(); - NodeRef root = roots.get(0); - - // Check that the role exists - if (filePlanRoleService.existsRole(root, roleParam) == false) + // get the file plan + NodeRef filePlan = getFilePlan(req); + if (filePlan == null) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "The role " + roleParam + " does not exist on the records managment root " + root); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "File plan does not exist."); } - model.put("role", filePlanRoleService.getRole(root, roleParam)); + // Check that the role exists + if (filePlanRoleService.existsRole(filePlan, roleParam) == false) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "The role " + roleParam + " does not exist on the records managment root " + filePlan); + } + + RoleItem item = new RoleItem(filePlanRoleService.getRole(filePlan, roleParam)); + model.put("role", item); return model; } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolePut.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolePut.java index b32510ec48..cc8b10d644 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolePut.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolePut.java @@ -21,14 +21,11 @@ package org.alfresco.module.org_alfresco_module_rm.script.admin; import java.io.IOException; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; -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.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.logging.Log; @@ -38,7 +35,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; import org.springframework.extensions.webscripts.Cache; -import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; @@ -48,24 +44,12 @@ import org.springframework.extensions.webscripts.WebScriptRequest; * * @author Roy Wetherall */ -public class RmRolePut extends DeclarativeWebScript +public class RmRolePut extends RoleDeclarativeWebScript { @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(RmRolePut.class); - private RecordsManagementService rmService; private CapabilityService capabilityService; - private FilePlanRoleService filePlanRoleService; - - public void setFilePlanRoleService(FilePlanRoleService filePlanRoleService) - { - this.filePlanRoleService = filePlanRoleService; - } - - public void setRecordsManagementService(RecordsManagementService rmService) - { - this.rmService = rmService; - } public void setCapabilityService(CapabilityService capabilityService) { @@ -101,17 +85,22 @@ public class RmRolePut extends DeclarativeWebScript capabilites.add(capability); } - List roots = rmService.getFilePlans(); - NodeRef root = roots.get(0); - - // Check that the role exists - if (filePlanRoleService.existsRole(root, roleParam) == false) + // get the file plan + NodeRef filePlan = getFilePlan(req); + if (filePlan == null) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "The role " + roleParam + " does not exist on the records managment root " + root); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "File plan does not exist."); } - Role role = filePlanRoleService.updateRole(root, name, displayLabel, capabilites); - model.put("role", role); + // Check that the role exists + if (filePlanRoleService.existsRole(filePlan, roleParam) == false) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, + "The role " + roleParam + " does not exist on the records managment root " + filePlan); + } + + Role role = filePlanRoleService.updateRole(filePlan, name, displayLabel, capabilites); + model.put("role", new RoleItem(role)); } catch (IOException iox) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolesGet.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolesGet.java index 69cf04da03..f1ce61c27b 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolesGet.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolesGet.java @@ -19,20 +19,16 @@ package org.alfresco.module.org_alfresco_module_rm.script.admin; import java.util.HashMap; -import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; -import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.extensions.webscripts.Cache; -import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; /** @@ -40,55 +36,49 @@ import org.springframework.extensions.webscripts.WebScriptRequest; * * @author Roy Wetherall */ -public class RmRolesGet extends DeclarativeWebScript +public class RmRolesGet extends RoleDeclarativeWebScript { + /** Logger */ @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(RmRolesGet.class); - private RecordsManagementService rmService; - - private FilePlanRoleService filePlanRoleService; - - public void setFilePlanRoleService(FilePlanRoleService filePlanRoleService) - { - this.filePlanRoleService = filePlanRoleService; - } - - public void setRecordsManagementService(RecordsManagementService rmService) - { - this.rmService = rmService; - } - + /** + * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache) + */ @Override public Map executeImpl(WebScriptRequest req, Status status, Cache cache) { Map model = new HashMap(); Set roles = null; - // TODO should be passed - List roots = rmService.getFilePlans(); - if (roots != null && roots.size() > 0) + // get the file plan + NodeRef filePlan = getFilePlan(req); + if (filePlan == null) { - NodeRef root = roots.get(0); + throw new WebScriptException(Status.STATUS_FOUND, "File plan does not exist."); + } - // Get the user filter - String user = req.getParameter("user"); - if (user != null && user.length() != 0) - { - roles = filePlanRoleService.getRolesByUser(root, user); - } - else - { - roles = filePlanRoleService.getRoles(root); - } + // get the user filter + String user = req.getParameter("user"); + if (user != null && user.length() != 0) + { + roles = filePlanRoleService.getRolesByUser(filePlan, user); } else { - roles = new HashSet(1); + roles = filePlanRoleService.getRoles(filePlan); } - - model.put("roles", roles); - + + // get the auths parameter + boolean showAuths = false; + String auths = req.getParameter("auths"); + if (auths != null && auths.length() != 0) + { + showAuths = Boolean.parseBoolean(auths); + } + + Set items = createRoleItems(filePlan, roles, showAuths); + model.put("roles", items); return model; } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolesPost.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolesPost.java index 09980eee6b..663481ba5f 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolesPost.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RmRolesPost.java @@ -21,14 +21,11 @@ package org.alfresco.module.org_alfresco_module_rm.script.admin; import java.io.IOException; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; -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.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.service.cmr.repository.NodeRef; import org.apache.commons.logging.Log; @@ -38,7 +35,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; import org.springframework.extensions.webscripts.Cache; -import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptRequest; @@ -48,25 +44,13 @@ import org.springframework.extensions.webscripts.WebScriptRequest; * * @author Roy Wetherall */ -public class RmRolesPost extends DeclarativeWebScript +public class RmRolesPost extends RoleDeclarativeWebScript { @SuppressWarnings("unused") private static Log logger = LogFactory.getLog(RmRolesPost.class); - private RecordsManagementService rmService; - private FilePlanRoleService filePlanRoleService; private CapabilityService capabilityService; - public void setFilePlanRoleService(FilePlanRoleService filePlanRoleService) - { - this.filePlanRoleService = filePlanRoleService; - } - - public void setRecordsManagementService(RecordsManagementService rmService) - { - this.rmService = rmService; - } - public void setCapabilityService(CapabilityService capabilityService) { this.capabilityService = capabilityService; @@ -93,13 +77,15 @@ public class RmRolesPost extends DeclarativeWebScript capabilites.add(capability); } - List roots = rmService.getFilePlans(); - NodeRef root = roots.get(0); + // get the file plan + NodeRef filePlan = getFilePlan(req); + if (filePlan == null) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "File plan does not exist."); + } - Role role = filePlanRoleService.createRole(root, name, displayString, capabilites); - - //Set roles = rmSecurityService.getRoles(root); - model.put("role", role); + Role role = filePlanRoleService.createRole(filePlan, name, displayString, capabilites); + model.put("role", new RoleItem(role)); } catch (IOException iox) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RoleDeclarativeWebScript.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RoleDeclarativeWebScript.java new file mode 100644 index 0000000000..741363cf40 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RoleDeclarativeWebScript.java @@ -0,0 +1,263 @@ +/* + * Copyright (C) 2005-2011 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.script.admin; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.alfresco.module.org_alfresco_module_rm.capability.Capability; +import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; +import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; +import org.alfresco.module.org_alfresco_module_rm.role.Role; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.security.AuthorityService; +import org.apache.cxf.common.util.StringUtils; +import org.springframework.extensions.webscripts.DeclarativeWebScript; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * Base declarative web script for role API. + * + * @author Roy Wetherall + * @since 2.1 + */ +public class RoleDeclarativeWebScript extends DeclarativeWebScript +{ + /** File plan service */ + protected FilePlanService filePlanService; + + /** File plan role service */ + protected FilePlanRoleService filePlanRoleService; + + /** Authority service */ + protected AuthorityService authorityService; + + /** + * @param filePlanService file plan service + */ + public void setFilePlanService(FilePlanService filePlanService) + { + this.filePlanService = filePlanService; + } + + /** + * @param filePlanRoleService file plan role service + */ + public void setFilePlanRoleService(FilePlanRoleService filePlanRoleService) + { + this.filePlanRoleService = filePlanRoleService; + } + + /** + * @param authorityService authority service + */ + public void setAuthorityService(AuthorityService authorityService) + { + this.authorityService = authorityService; + } + + /** + * Utility method to get the file plan from the passed parameters. + * + * @param req + * @return + */ + protected NodeRef getFilePlan(WebScriptRequest req) + { + NodeRef filePlan = null; + + Map templateVars = req.getServiceMatch().getTemplateVars(); + String siteId = templateVars.get("siteid"); + if (siteId != null) + { + filePlan = filePlanService.getFilePlanBySiteId(siteId); + } + + if (filePlan == null) + { + String storeType = templateVars.get("store_type"); + String storeId = templateVars.get("store_id"); + String id = templateVars.get("id"); + + if (StringUtils.isEmpty(storeType) == false && + StringUtils.isEmpty(storeId) == false && + StringUtils.isEmpty(id) == false) + { + StoreRef storeRef = new StoreRef(storeType, storeId); + NodeRef nodeRef = new NodeRef(storeRef, id); + if (filePlanService.isFilePlan(nodeRef) == true) + { + filePlan = nodeRef; + } + } + } + + if (filePlan == null) + { + // Assume we are in a legacy repository and we will grab the default file plan + filePlan = filePlanService.getFilePlanBySiteId("rm"); + } + + return filePlan; + } + + /** + * + * @param filePlan + * @param roles + * @return + */ + protected Set createRoleItems(NodeRef filePlan, Set roles) + { + return createRoleItems(filePlan, roles, false); + } + + /** + * + * @param filePlan + * @param roles + * @param showAuths + * @return + */ + protected Set createRoleItems(NodeRef filePlan, Set roles, boolean showAuths) + { + Set items = new HashSet(roles.size()); + for (Role role : roles) + { + RoleItem item = null; + if (showAuths == true) + { + item = new RoleItem(role, + createAuthorityItems(filePlanRoleService.getUsersAssignedToRole(filePlan, role.getName())), + createAuthorityItems(filePlanRoleService.getGroupsAssignedToRole(filePlan, role.getName()))); + } + else + { + item = new RoleItem(role); + } + items.add(item); + } + return items; + } + + /** + * + * @param authorities + * @return + */ + private Set createAuthorityItems(Set authorities) + { + Set result = new HashSet(authorities.size()); + + for (String authority : authorities) + { + String displayLabel = authorityService.getAuthorityDisplayName(authority); + result.add(new AuthorityItem(authority, displayLabel)); + } + + return result; + } + + /** + * Role item utility class + * + * @author Roy Wetherall + * @since 2.1 + */ + public class RoleItem + { + private String name; + private String displayLabel; + private Set capabilities; + private boolean showAuths = false; + private Set assignedUsers; + private Set assignedGroups; + + public RoleItem(Role role) + { + this.name = role.getName(); + this.displayLabel = role.getDisplayLabel(); + this.capabilities = role.getCapabilities(); + } + + public RoleItem(Role role, Set assignedUsers, Set assignedGroups) + { + this.name = role.getName(); + this.displayLabel = role.getDisplayLabel(); + this.capabilities = role.getCapabilities(); + this.showAuths = true; + this.assignedUsers = assignedUsers; + this.assignedGroups = assignedGroups; + } + + public String getName() + { + return name; + } + + public String getDisplayLabel() + { + return displayLabel; + } + + public Set getCapabilities() + { + return capabilities; + } + + public boolean getShowAuths() + { + return showAuths; + } + + public Set getAssignedGroups() + { + return assignedGroups; + } + + public Set getAssignedUsers() + { + return assignedUsers; + } + } + + public class AuthorityItem + { + private String name; + private String displayLabel; + + public AuthorityItem(String name, String displayLabel) + { + this.name = name; + this.displayLabel = displayLabel; + } + + public String getName() + { + return name; + } + + public String getDisplayLabel() + { + return displayLabel; + } + } +} \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/repo/action/parameter/NodeParameterProcessor.java b/rm-server/source/java/org/alfresco/repo/action/parameter/NodeParameterProcessor.java index 982e2d769d..d014f100c3 100644 --- a/rm-server/source/java/org/alfresco/repo/action/parameter/NodeParameterProcessor.java +++ b/rm-server/source/java/org/alfresco/repo/action/parameter/NodeParameterProcessor.java @@ -24,7 +24,6 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.PropertyDefinition; -import org.alfresco.service.cmr.repository.MLText; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.NamespaceService; diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java index 5ceecf10df..a36081ea16 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java @@ -26,6 +26,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.service.DataSetServiceImp import org.alfresco.module.org_alfresco_module_rm.test.service.DispositionServiceImplTest; import org.alfresco.module.org_alfresco_module_rm.test.service.ExtendedSecurityServiceImplTest; import org.alfresco.module.org_alfresco_module_rm.test.service.FilePlanRoleServiceImplTest; +import org.alfresco.module.org_alfresco_module_rm.test.service.FilePlanServiceImplTest; import org.alfresco.module.org_alfresco_module_rm.test.service.FreezeServiceImplTest; import org.alfresco.module.org_alfresco_module_rm.test.service.ModelSecurityServiceImplTest; import org.alfresco.module.org_alfresco_module_rm.test.service.RecordServiceImplTest; @@ -67,6 +68,7 @@ public class ServicesTestSuite extends TestSuite suite.addTestSuite(RecordServiceImplTest.class); suite.addTestSuite(CapabilityServiceImplTest.class); suite.addTestSuite(FilePlanRoleServiceImplTest.class); + suite.addTestSuite(FilePlanServiceImplTest.class); return suite; } } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/FilePlanRoleServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/FilePlanRoleServiceImplTest.java index 92a4c6cb1f..5ca7a0aff9 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/FilePlanRoleServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/FilePlanRoleServiceImplTest.java @@ -23,6 +23,7 @@ import java.util.Set; import org.alfresco.module.org_alfresco_module_rm.capability.Capability; import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.service.cmr.security.AuthorityType; @@ -158,7 +159,11 @@ public class FilePlanRoleServiceImplTest extends BaseRMTestCase }); } - public void testAssignRoleToAuthority() throws Exception + /** + * {@link FilePlanRoleService#assignRoleToAuthority(org.alfresco.service.cmr.repository.NodeRef, String, String)} + * {@link FilePlanRoleService#getAuthorities(org.alfresco.service.cmr.repository.NodeRef, String) + */ + public void testAuthorityAssignment() throws Exception { doTestInTransaction(new Test() { @@ -168,12 +173,37 @@ public class FilePlanRoleServiceImplTest extends BaseRMTestCase assertNotNull(roles); assertEquals(1, roles.size()); + Set authorities = filePlanRoleService.getUsersAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER); + assertNotNull(authorities); + assertEquals(1, authorities.size()); + + authorities = filePlanRoleService.getGroupsAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER); + assertNotNull(authorities); + assertEquals(0, authorities.size()); + + authorities = filePlanRoleService.getAllAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER); + assertNotNull(authorities); + assertEquals(1, authorities.size()); + filePlanRoleService.assignRoleToAuthority(filePlan, ROLE_NAME_RECORDS_MANAGER, rmUserName); roles = filePlanRoleService.getRolesByUser(filePlan, rmUserName); assertNotNull(roles); assertEquals(2, roles.size()); + authorities = filePlanRoleService.getUsersAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER); + assertNotNull(authorities); + assertEquals(2, authorities.size()); + + authorities = filePlanRoleService.getGroupsAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER); + assertNotNull(authorities); + assertEquals(0, authorities.size()); + + authorities = filePlanRoleService.getAllAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER); + assertNotNull(authorities); + assertEquals(2, authorities.size()); + + return null; } }); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/FilePlanServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/FilePlanServiceImplTest.java new file mode 100644 index 0000000000..7b4b30a6a2 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/FilePlanServiceImplTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2005-2013 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.test.service; + +import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.site.SiteVisibility; +import org.alfresco.util.GUID; + +/** + * File plan service unit test + * + * @author Roy Wetherall + * @since 2.1 + */ +public class FilePlanServiceImplTest extends BaseRMTestCase +{ + /** + * Pull in collaboration test data + */ + @Override + protected boolean isCollaborationSiteTest() + { + return true; + } + + /** + * {@link FilePlanService#isFilePlan(org.alfresco.service.cmr.repository.NodeRef)} + */ + public void testIsFilePlan() + { + doTestInTransaction(new VoidTest() + { + public void runImpl() throws Exception + { + assertTrue(filePlanService.isFilePlan(filePlan)); + assertFalse(filePlanService.isFilePlan(rmContainer)); + assertFalse(filePlanService.isFilePlan(dmDocument)); + } + }); + } + + /** + * {@link FilePlanService#getFilePlan(org.alfresco.service.cmr.repository.NodeRef)} + */ + public void testGetFilePlans() + { + doTestInTransaction(new VoidTest() + { + public void runImpl() throws Exception + { + assertEquals(filePlan, filePlanService.getFilePlan(filePlan)); + assertEquals(filePlan, filePlanService.getFilePlan(rmContainer)); + assertEquals(filePlan, filePlanService.getFilePlan(rmFolder)); + assertNull(filePlanService.getFilePlan(dmDocument)); + } + }); + } + + /** + * {@link FilePlanService#getFilePlanBySiteId(String)} + */ + public void testGetFilePlanBySiteId() + { + doTestInTransaction(new VoidTest() + { + public void runImpl() throws Exception + { + assertEquals(filePlan, filePlanService.getFilePlanBySiteId(SITE_ID)); + assertNull(filePlanService.getFilePlanBySiteId("rubbish")); + + String siteId = GUID.generate(); + siteService.createSite("anything", siteId, "title", "descrition", SiteVisibility.PUBLIC); + assertNull(filePlanService.getFilePlanBySiteId(siteId)); + } + }); + + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java index 790feb1d87..f387eb4329 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java @@ -155,6 +155,7 @@ public class RecordsManagementServiceImplTest extends BaseRMTestCase { doTestInTransaction(new Test() { + @SuppressWarnings("deprecation") @Override public NodeRef run() { @@ -176,17 +177,10 @@ public class RecordsManagementServiceImplTest extends BaseRMTestCase { doTestInTransaction(new Test() { + @SuppressWarnings("deprecation") @Override public NodeRef run() { -// List roots = rmService.getRecordsManagementRoots(storeRef); -// assertNotNull(roots); -// assertTrue(roots.size() != 0); -// assertTrue(roots.contains(rmRootContainer)); -// -// RecordsManagementServiceImpl temp = (RecordsManagementServiceImpl)applicationContext.getBean("recordsManagementService"); -// temp.setDefaultStoreRef(storeRef); - List roots = rmService.getFilePlans(); assertNotNull(roots); assertTrue(roots.size() != 0); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RoleRestApiTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RoleRestApiTest.java index 0c9975a7fc..3807d58fa4 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RoleRestApiTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/webscript/RoleRestApiTest.java @@ -18,14 +18,18 @@ */ package org.alfresco.module.org_alfresco_module_rm.test.webscript; +import java.text.MessageFormat; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import org.alfresco.module.org_alfresco_module_rm.capability.Capability; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase; +import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.util.GUID; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; @@ -41,9 +45,20 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response; public class RoleRestApiTest extends BaseRMWebScriptTestCase implements RecordsManagementModel { - protected static final String GET_ROLES_URL = "/api/rma/admin/rmroles"; + protected static final String GET_ROLES_URL_BY_SITE = "/api/rma/admin/{0}/rmroles"; + protected static final String GET_ROLES_URL_BY_FILEPLAN = "/api/rma/admin/{0}/{1}/{2}/rmroles"; protected static final String SERVICE_URL_PREFIX = "/alfresco/service"; - protected static final String APPLICATION_JSON = "application/json"; + protected static final String APPLICATION_JSON = "application/json"; + + private String getRolesUrlBySite() + { + return MessageFormat.format(GET_ROLES_URL_BY_SITE, SITE_ID); + } + + private String getRoleUrlByFilePlan() + { + return MessageFormat.format(GET_ROLES_URL_BY_FILEPLAN, filePlan.getStoreRef().getProtocol(), filePlan.getStoreRef().getIdentifier(), filePlan.getId()); + } public void testGetRoles() throws Exception { @@ -54,13 +69,18 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5)); filePlanRoleService.createRole(filePlan, role2, "My Test Role Too", getListOfCapabilities(5)); + // create test group + String groupName = GUID.generate(); + String group = authorityService.createAuthority(AuthorityType.GROUP, groupName, "monkey", null); + // Add the admin user to one of the roles filePlanRoleService.assignRoleToAuthority(filePlan, role1, "admin"); + filePlanRoleService.assignRoleToAuthority(filePlan, role1, group); try { - // Get the roles - Response rsp = sendRequest(new GetRequest(GET_ROLES_URL),200); + // Get the roles (for the default file plan) + Response rsp = sendRequest(new GetRequest(getRolesUrlBySite()),200); String rspContent = rsp.getContentAsString(); JSONObject obj = new JSONObject(rspContent); @@ -71,20 +91,16 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase assertNotNull(roleObj); assertEquals(role1, roleObj.get("name")); assertEquals("My Test Role", roleObj.get("displayLabel")); - JSONArray caps = roleObj.getJSONArray("capabilities"); - assertNotNull(caps); - assertEquals(5, caps.length()); + checkCapabilities(roleObj, 5); roleObj = roles.getJSONObject(role2); assertNotNull(roleObj); assertEquals(role2, roleObj.get("name")); assertEquals("My Test Role Too", roleObj.get("displayLabel")); - caps = roleObj.getJSONArray("capabilities"); - assertNotNull(caps); - assertEquals(5, caps.length()); + checkCapabilities(roleObj, 5); - // Get the roles for "admin" - rsp = sendRequest(new GetRequest(GET_ROLES_URL + "?user=admin"),200); + // Get the roles, specifying the file plan + rsp = sendRequest(new GetRequest(getRoleUrlByFilePlan()),200); rspContent = rsp.getContentAsString(); obj = new JSONObject(rspContent); @@ -95,11 +111,67 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase assertNotNull(roleObj); assertEquals(role1, roleObj.get("name")); assertEquals("My Test Role", roleObj.get("displayLabel")); - caps = roleObj.getJSONArray("capabilities"); - assertNotNull(caps); - assertEquals(5, caps.length()); + checkCapabilities(roleObj, 5); + + roleObj = roles.getJSONObject(role2); + assertNotNull(roleObj); + assertEquals(role2, roleObj.get("name")); + assertEquals("My Test Role Too", roleObj.get("displayLabel")); + checkCapabilities(roleObj, 5); + + // Get the roles for "admin" + rsp = sendRequest(new GetRequest(getRolesUrlBySite() + "?user=admin"),200); + rspContent = rsp.getContentAsString(); + + obj = new JSONObject(rspContent); + roles = obj.getJSONObject("data"); + assertNotNull(roles); + + roleObj = roles.getJSONObject(role1); + assertNotNull(roleObj); + assertEquals(role1, roleObj.get("name")); + assertEquals("My Test Role", roleObj.get("displayLabel")); + checkCapabilities(roleObj, 5); assertFalse(roles.has(role2)); + + // Get the roles including assigned authorities + rsp = sendRequest(new GetRequest(getRoleUrlByFilePlan() + "?auths=true"),200); + rspContent = rsp.getContentAsString(); + + System.out.println(rspContent); + + obj = new JSONObject(rspContent); + roles = obj.getJSONObject("data"); + assertNotNull(roles); + + roleObj = roles.getJSONObject(role1); + assertNotNull(roleObj); + assertEquals(role1, roleObj.get("name")); + assertEquals("My Test Role", roleObj.get("displayLabel")); + checkCapabilities(roleObj, 5); + + JSONArray users = roleObj.getJSONArray("assignedUsers"); + assertNotNull(users); + assertEquals(1, users.length()); + + JSONArray groups = roleObj.getJSONArray("assignedGroups"); + assertNotNull(groups); + assertEquals(1, groups.length()); + + roleObj = roles.getJSONObject(role2); + assertNotNull(roleObj); + assertEquals(role2, roleObj.get("name")); + assertEquals("My Test Role Too", roleObj.get("displayLabel")); + checkCapabilities(roleObj, 5); + + users = roleObj.getJSONArray("assignedUsers"); + assertNotNull(users); + assertEquals(0, users.length()); + + groups = roleObj.getJSONArray("assignedGroups"); + assertNotNull(groups); + assertEquals(0, groups.length()); } finally { @@ -110,6 +182,25 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase } + @SuppressWarnings("unchecked") + private void checkCapabilities(JSONObject role, int expectedCount) throws JSONException + { + JSONObject capabilities = role.getJSONObject("capabilities"); + assertNotNull(capabilities); + + int count = 0; + Iterator it = capabilities.keys(); + while (it.hasNext()) + { + String key = (String)it.next(); + assertNotNull(key); + assertNotNull(capabilities.getString(key)); + count ++; + } + + assertEquals(expectedCount, count); + } + public void testPostRoles() throws Exception { Set caps = getListOfCapabilities(5); @@ -126,7 +217,7 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase obj.put("displayLabel", "Display Label"); obj.put("capabilities", arrCaps); - Response rsp = sendRequest(new PostRequest(GET_ROLES_URL, obj.toString(), APPLICATION_JSON),200); + Response rsp = sendRequest(new PostRequest(getRolesUrlBySite(), obj.toString(), APPLICATION_JSON),200); try { String rspContent = rsp.getContentAsString(); @@ -138,9 +229,7 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase assertNotNull(roleObj); assertEquals(roleName, roleObj.get("name")); assertEquals("Display Label", roleObj.get("displayLabel")); - JSONArray resultCaps = roleObj.getJSONArray("capabilities"); - assertNotNull(resultCaps); - assertEquals(5, resultCaps.length()); + checkCapabilities(roleObj, 5); } finally { @@ -170,7 +259,7 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase obj.put("capabilities", arrCaps); // Get the roles - Response rsp = sendRequest(new PutRequest(GET_ROLES_URL + "/" + role1, obj.toString(), APPLICATION_JSON),200); + Response rsp = sendRequest(new PutRequest(getRolesUrlBySite() + "/" + role1, obj.toString(), APPLICATION_JSON),200); String rspContent = rsp.getContentAsString(); JSONObject result = new JSONObject(rspContent); @@ -180,12 +269,10 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase assertNotNull(roleObj); assertEquals(role1, roleObj.get("name")); assertEquals("Changed", roleObj.get("displayLabel")); - JSONArray bob = roleObj.getJSONArray("capabilities"); - assertNotNull(bob); - assertEquals(4, bob.length()); + checkCapabilities(roleObj, 4); // Bad requests - sendRequest(new PutRequest(GET_ROLES_URL + "/cheese", obj.toString(), APPLICATION_JSON), 404); + sendRequest(new PutRequest(getRolesUrlBySite() + "/cheese", obj.toString(), APPLICATION_JSON), 404); } finally { @@ -203,7 +290,7 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase try { // Get the roles - Response rsp = sendRequest(new GetRequest(GET_ROLES_URL + "/" + role1),200); + Response rsp = sendRequest(new GetRequest(getRolesUrlBySite() + "/" + role1),200); String rspContent = rsp.getContentAsString(); JSONObject obj = new JSONObject(rspContent); @@ -213,12 +300,10 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase assertNotNull(roleObj); assertEquals(role1, roleObj.get("name")); assertEquals("My Test Role", roleObj.get("displayLabel")); - JSONArray caps = roleObj.getJSONArray("capabilities"); - assertNotNull(caps); - assertEquals(5, caps.length()); + checkCapabilities(roleObj, 5); // Bad requests - sendRequest(new GetRequest(GET_ROLES_URL + "/cheese"), 404); + sendRequest(new GetRequest(getRolesUrlBySite() + "/cheese"), 404); } finally { @@ -234,11 +319,11 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase assertFalse(filePlanRoleService.existsRole(filePlan, role1)); filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5)); assertTrue(filePlanRoleService.existsRole(filePlan, role1)); - sendRequest(new DeleteRequest(GET_ROLES_URL + "/" + role1),200); + sendRequest(new DeleteRequest(getRolesUrlBySite() + "/" + role1),200); assertFalse(filePlanRoleService.existsRole(filePlan, role1)); // Bad request - sendRequest(new DeleteRequest(GET_ROLES_URL + "/cheese"), 404); + sendRequest(new DeleteRequest(getRolesUrlBySite() + "/cheese"), 404); } private Set getListOfCapabilities(int size)