private Map<String, Role> getRolePermissionMap(List<Role> roles) { Map<String, Role> roleMap = new HashMap<String, ResourceAdmin.Role>(); for (Role role : roles) { roleMap.put(role.getRole(), role); } return roleMap; }
/** * load data for table * * @throws RemoteException * @throws Exception */ public void loadData() throws RemoteException, Exception { ResourceAdmin rsAd = regResourceNode.getConnectionInfo().getResourceAdmin(); ArrayList<Role> resourceInfo = rsAd.getPermissionPerResource(regResourceNode.getRegistryResourcePath()); ArrayList<String> string = new ArrayList<String>(); string.addAll( Arrays.asList( regResourceNode .getConnectionInfo() .getUserManagerContent() .getUserManager() .getRoles("*"))); table.removeAll(); Map<String, Role> rolePermissionMap = getRolePermissionMap(resourceInfo); for (String roleName : string) { if (roleName.equals("admin")) { continue; } TableItem tableItem = null; RoleData roleData = null; if (rolePermissionMap.containsKey(roleName)) { Role role = rolePermissionMap.get(roleName); ArrayList<String> permissionListPerRole = role.getAssignedPermission(); roleData = getRoleData(role.getRole(), regResourceNode.getRegistryResourcePath()); tableItem = new TableItem(table, SWT.NULL); for (int j = 0; j < permissionListPerRole.size(); j++) { if (permissionListPerRole.get(j).equals(BaseConstants.READ)) { roleData.setReadPerm(true); } if (permissionListPerRole.get(j).equals(BaseConstants.WRITE)) { roleData.setWritePerm(true); } if (permissionListPerRole.get(j).equals(BaseConstants.DELETE)) { roleData.setDeletePerm(true); } if (permissionListPerRole.get(j).equals(BaseConstants.AUTHORIZE)) { roleData.setAuthPerm(true); } } } else { roleData = getRoleData(roleName, regResourceNode.getRegistryResourcePath()); tableItem = new TableItem(table, SWT.NULL); } tableItem.setText(roleData.role); createTable(tableItem, roleData); } // for (int i = 0; i < resourceInfo.size(); i++) { // // string.remove(resourceInfo.get(i).getRole()); // // ArrayList<String> permissionListPerRole = resourceInfo.get(i).getAssignedPermission(); // RoleData roleData = getRoleData(resourceInfo.get(i).getRole(), // regResourceNode.getRegistryResourcePath()); // // TableItem tableItem = new TableItem(table, SWT.NULL); // tableItem.setText(resourceInfo.get(i).getRole()); // for (int j = 0; j < permissionListPerRole.size(); j++) { // if (permissionListPerRole.get(j).equals(BaseConstants.READ)) { // roleData.setReadPerm(true); // } // if (permissionListPerRole.get(j).equals(BaseConstants.WRITE)) { // roleData.setWritePerm(true); // } // if (permissionListPerRole.get(j).equals(BaseConstants.DELETE)) { // roleData.setDeletePerm(true); // } // if (permissionListPerRole.get(j).equals(BaseConstants.AUTHORIZE)) { // roleData.setAuthPerm(true); // } // // } // createTable(tableItem, roleData); // } // // for (Iterator iterator = string.iterator(); iterator.hasNext();) { // String string2 = (String) iterator.next(); // RoleData roleData = getRoleData(string2, // regResourceNode.getRegistryResourcePath()); // TableItem tableItem = new TableItem(table, SWT.NULL); // tableItem.setText(string2); // createTable(tableItem, roleData); // } }