use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.
the class FilePlanRoleServiceImpl method getCapabilitiesImpl.
/**
* @param rmRootNode
* @param roleAuthority
* @return
*/
private Set<Capability> getCapabilitiesImpl(NodeRef rmRootNode, String roleAuthority) {
Set<AccessPermission> permissions = permissionService.getAllSetPermissions(rmRootNode);
Set<Capability> capabilities = new HashSet<Capability>(52);
for (AccessPermission permission : permissions) {
if (permission.getAuthority().equals(roleAuthority)) {
String capabilityName = permission.getPermission();
Capability capability = capabilityService.getCapability(capabilityName);
if (capability != null && !capability.isPrivate()) {
capabilities.add(capability);
}
}
}
return capabilities;
}
use of org.alfresco.module.org_alfresco_module_rm.capability.Capability in project records-management by Alfresco.
the class CustomRefsGet method hasView.
/**
* Determines whether the current user has view capabilities on the given node.
*
* @param nodeRef Node reference
* @return boolean <code>true</code> if current user has view capability, <code>false</code> otherwise
*/
private boolean hasView(NodeRef nodeRef) {
boolean result = false;
Capability viewRecordCapability = getCapabilityService().getCapability(ViewRecordsCapability.NAME);
if (AccessStatus.ALLOWED.equals(viewRecordCapability.hasPermission(nodeRef))) {
result = true;
}
return result;
}
use of org.alfresco.module.org_alfresco_module_rm.capability.Capability 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.capability.Capability 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.capability.Capability in project records-management by Alfresco.
the class CapabilitiesGet method executeImpl.
/**
* @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!
nodeRef = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
if (nodeRef == null) {
throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "The default file plan node could not be found.");
}
}
boolean grouped = false;
String groupedString = req.getParameter("grouped");
if (StringUtils.isNotBlank(groupedString)) {
grouped = Boolean.parseBoolean(groupedString);
}
Map<String, Object> model = new TreeMap<String, Object>();
if (grouped) {
// Construct the map which is needed to build the model
Map<String, GroupedCapabilities> groupedCapabilitiesMap = new TreeMap<String, GroupedCapabilities>();
List<Group> groups = capabilityService.getGroups();
for (Group group : groups) {
String capabilityGroupTitle = group.getTitle();
if (StringUtils.isNotBlank(capabilityGroupTitle)) {
String capabilityGroupId = group.getId();
List<Capability> capabilities = capabilityService.getCapabilitiesByGroupId(capabilityGroupId);
for (Capability capability : capabilities) {
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);
}
}
}
}
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)) {
Capability capability = entry.getKey();
list.add(capability.getName());
}
}
model.put("capabilities", list);
}
return model;
}
Aggregations