use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.
the class UserRightsReportGet method executeImpl.
/*
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
NodeRef filePlanNode = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
if (filePlanNode == null) {
status.setCode(HttpServletResponse.SC_BAD_REQUEST, "The default RM site could not be found.");
return null;
}
// construct all the maps etc. needed to build the model
Map<String, UserModel> usersMap = new HashMap<String, UserModel>(8);
Map<String, RoleModel> rolesMap = new HashMap<String, RoleModel>(8);
Map<String, GroupModel> groupsMap = new HashMap<String, GroupModel>(8);
// iterate over all the roles for the file plan and construct models
Set<Role> roles = filePlanRoleService.getRoles(filePlanNode);
for (Role role : roles) {
// get or create the RoleModel object for current role
String roleName = role.getName();
RoleModel roleModel = rolesMap.get(roleName);
if (roleModel == null) {
roleModel = new RoleModel(role);
rolesMap.put(roleName, roleModel);
}
// get the users for the current RM role
String group = role.getRoleGroupName();
Set<String> users = authorityService.getContainedAuthorities(AuthorityType.USER, group, false);
roleModel.setUsers(users);
// setup a user model object for each user
for (String userName : users) {
UserModel userModel = usersMap.get(userName);
if (userModel == null) {
NodeRef userRef = this.personService.getPerson(userName);
userModel = new UserModel(userName, (String) this.nodeService.getProperty(userRef, ContentModel.PROP_FIRSTNAME), (String) this.nodeService.getProperty(userRef, ContentModel.PROP_LASTNAME));
usersMap.put(userName, userModel);
}
userModel.addRole(roleName);
}
// get the groups for the cuurent RM role
Set<String> groups = authorityService.getContainedAuthorities(AuthorityType.GROUP, group, false);
roleModel.setGroups(groups);
// setup a user model object for each user in each group
for (String groupName : groups) {
GroupModel groupModel = groupsMap.get(groupName);
if (groupModel == null) {
groupModel = new GroupModel(groupName, authorityService.getAuthorityDisplayName(groupName));
groupsMap.put(groupName, groupModel);
}
// get users in each group
Set<String> groupUsers = this.authorityService.getContainedAuthorities(AuthorityType.USER, groupName, true);
for (String userName : groupUsers) {
UserModel userModel = usersMap.get(userName);
if (userModel == null) {
NodeRef userRef = this.personService.getPerson(userName);
userModel = new UserModel(userName, (String) this.nodeService.getProperty(userRef, ContentModel.PROP_FIRSTNAME), (String) this.nodeService.getProperty(userRef, ContentModel.PROP_LASTNAME));
usersMap.put(userName, userModel);
}
userModel.addGroup(groupName);
userModel.addRole(roleName);
groupModel.addUser(userName);
}
}
}
// add all the lists data to a Map
Map<String, Object> reportModel = new HashMap<String, Object>(4);
reportModel.put("users", usersMap);
reportModel.put("roles", rolesMap);
reportModel.put("groups", groupsMap);
// create model object with the lists model
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("report", reportModel);
return model;
}
use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.
the class RmRolePut method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
JSONObject json = null;
try {
// Role name
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String roleParam = templateVars.get("rolename");
if (roleParam == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No role name was provided on the URL.");
}
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
String name = json.getString("name");
// TODO check
String displayLabel = json.getString("displayLabel");
// TODO check
JSONArray capabilitiesArray = json.getJSONArray("capabilities");
Set<Capability> capabilites = new HashSet<Capability>(capabilitiesArray.length());
for (int i = 0; i < capabilitiesArray.length(); i++) {
Capability capability = capabilityService.getCapability(capabilitiesArray.getString(i));
capabilites.add(capability);
}
// 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(filePlan, roleParam)) {
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) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
}
return model;
}
use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.
the class RmRolesPost method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
JSONObject json = null;
try {
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
String name = json.getString("name");
// TODO check
String displayString = json.getString("displayLabel");
// TODO check
JSONArray capabilitiesArray = json.getJSONArray("capabilities");
Set<Capability> capabilites = new HashSet<Capability>(capabilitiesArray.length());
for (int i = 0; i < capabilitiesArray.length(); i++) {
Capability capability = capabilityService.getCapability(capabilitiesArray.getString(i));
capabilites.add(capability);
}
// 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(filePlan, name, displayString, capabilites);
model.put("role", new RoleItem(role));
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
}
return model;
}
use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.
the class RMv22RemoveInPlaceRolesFromAllPatch method applyInternal.
/**
* @see org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch#applyInternal()
*/
@Override
public void applyInternal() {
// get all file plans
Set<NodeRef> filePlans = filePlanService.getFilePlans();
for (NodeRef filePlan : filePlans) {
Role extendedReaders = filePlanRoleService.getRole(filePlan, FilePlanRoleService.ROLE_EXTENDED_READERS);
Role extendedWriters = filePlanRoleService.getRole(filePlan, FilePlanRoleService.ROLE_EXTENDED_WRITERS);
// remove extended readers and writers roles from the all roles group
String allRolesGroup = filePlanRoleService.getAllRolesContainerGroup(filePlan);
Set<String> members = authorityService.getContainedAuthorities(null, allRolesGroup, true);
if (members.contains(extendedReaders.getRoleGroupName())) {
authorityService.removeAuthority(allRolesGroup, extendedReaders.getRoleGroupName());
}
if (members.contains(extendedWriters.getRoleGroupName())) {
authorityService.removeAuthority(allRolesGroup, extendedWriters.getRoleGroupName());
}
}
}
use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.
the class CreateHoldTest method setupTestUsersImpl.
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#setupTestUsersImpl(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void setupTestUsersImpl(NodeRef filePlan) {
super.setupTestUsersImpl(filePlan);
// Create test user
testUser = generate();
createPerson(testUser);
// Join the RM site
siteService.setMembership(siteId, testUser, SITE_CONSUMER);
// Create role
Set<Capability> capabilities = new HashSet<Capability>(2);
capabilities.add(capabilityService.getCapability(VIEW_RECORDS));
capabilities.add(capabilityService.getCapability(CREATE_HOLD));
Role role = filePlanRoleService.createRole(filePlan, generate(), generate(), capabilities);
// Add the test user to RM Records Manager role
filePlanRoleService.assignRoleToAuthority(filePlan, role.getName(), testUser);
}
Aggregations