public static List<TreeView> assemTreeView() { List<TreeView> result = new ArrayList<TreeView>(); List<Permission> perms = Permission.findAll(); if (perms == null) return result; TreeView root = new TreeView("0", "All Permissions", Permission.iconUrl); final Map<String, TreeView> modules = new HashMap<String, TreeView>(); for (Permission p : perms) { if (!p.action.contains(".")) continue; String[] names = p.action.split("\\."); final String moduleName = names[0]; final String name = names[1]; TreeView module = modules.get(moduleName); if (module == null) { module = new TreeView("", moduleName, Permission.iconUrl); modules.put(moduleName, module); } TreeView tv = new TreeView(String.valueOf(p.id), name, Permission.iconUrl); tv.items = null; module.expanded = true; module.items.add(tv); } root.expanded = true; root.items.addAll(modules.values()); result.add(root); return result; }
public static List<String> assemActions() { List<String> actionSet = Permission.actions; List<Permission> perms = Permission.findAll(); List<String> actions = new ArrayList<String>(); if (actionSet != null) actionLoop: for (String a : actionSet) { for (Permission p : perms) { if (p.action.equals(a)) continue actionLoop; } actions.add(a); } return actions; }
/** * This method returns permissions that are not assigned to this role. * * @return list of Permission objects */ public static List<Permission> getNotAssignedPermissions(List<Permission> assignedPermissions) { List<Permission> allPermissionList = Permission.findAll(); // Logger.debug("Permissions count: " + allPermissionList.size()); List<Permission> res = new ArrayList<Permission>(); if (assignedPermissions != null && assignedPermissions.size() > 0) { Iterator<Permission> itrAllPermissions = allPermissionList.iterator(); while (itrAllPermissions.hasNext()) { Permission curPermission = itrAllPermissions.next(); // Logger.debug("curPermission: " + curPermission.name); if (!assignedPermissions.contains(curPermission)) { res.add(curPermission); } } } return res; }