try {
ForumFactory forumFactory = ForumFactory.getInstance(getAuthToken(request));
ProfileManager manager = forumFactory.getProfileManager();
Forum forum = forumFactory.getForum(Integer.parseInt(request.getParameter("id")));
//check permission
checkPermission(request, OperationConstants.LIST_FORUM_PERMISSION, forum);
ForumPermissionsBean fb = new ForumPermissionsBean();
fb.setId(forum.getID());
fb.setName(forum.getName());
fb.setDescription(forum.getDescription());
int[] ids;
UserBean ub = null;
GroupBean gb = null;
User user = null;
Group group = null;
ids = forum.usersWithPermission(Constants.READ);
for (int i = 0; i < ids.length; i++) {
ub = new UserBean();
user = manager.getUser(ids[i]);
ub.setId(user.getID());
if( user.getID() == -1 )ub.setUserName(messages.getMessage(getLocale(request),"user.anonymous"));
else if( user.getID() == 0 )ub.setUserName(messages.getMessage(getLocale(request),"user.registered"));
else
ub.setUserName(user.getUsername());
fb.addUsersWithReadPerm(ub);
}
ids = forum.usersWithPermission(Constants.CREATE_THREAD);
for (int i = 0; i < ids.length; i++) {
ub = new UserBean();
user = manager.getUser(ids[i]);
ub.setId(user.getID());
if( user.getID() == -1 )ub.setUserName(messages.getMessage(getLocale(request),"user.anonymous"));
else if( user.getID() == 0 )ub.setUserName(messages.getMessage(getLocale(request),"user.registered"));
else
ub.setUserName(user.getUsername());
fb.addUsersWithThreadPerm(ub);
}
ids = forum.usersWithPermission(Constants.CREATE_MESSAGE);
for (int i = 0; i < ids.length; i++) {
ub = new UserBean();
user = manager.getUser(ids[i]);
ub.setId(user.getID());
if( user.getID() == -1 )ub.setUserName(messages.getMessage(getLocale(request),"user.anonymous"));
else if( user.getID() == 0 )ub.setUserName(messages.getMessage(getLocale(request),"user.registered"));
else
ub.setUserName(user.getUsername());
fb.addUsersWithMessagePerm(ub);
}
ids = forum.usersWithPermission(Constants.MODERATOR);
for (int i = 0; i < ids.length; i++) {
ub = new UserBean();
user = manager.getUser(ids[i]);
ub.setId(user.getID());
if( user.getID() == -1 )ub.setUserName(messages.getMessage(getLocale(request),"user.anonymous"));
else if( user.getID() == 0 )ub.setUserName(messages.getMessage(getLocale(request),"user.registered"));
else
ub.setUserName(user.getUsername());
fb.addUsersWithModeratorPerm(ub);
}
ids = forum.usersWithPermission(Constants.FORUM_ADMIN);
for (int i = 0; i < ids.length; i++) {
ub = new UserBean();
user = manager.getUser(ids[i]);
ub.setId(user.getID());
if( user.getID() == -1 )ub.setUserName(messages.getMessage(getLocale(request),"user.anonymous"));
else if( user.getID() == 0 )ub.setUserName(messages.getMessage(getLocale(request),"user.registered"));
else
ub.setUserName(user.getUsername());
fb.addUsersWithAdminPerm(ub);
}
ids = forum.groupsWithPermission(Constants.READ);
for (int i = 0; i < ids.length; i++) {
gb = new GroupBean();
group = manager.getGroup(ids[i]);
gb.setId(group.getID());
gb.setName(group.getName());
fb.addGroupsWithReadPerm(gb);
}
ids = forum.groupsWithPermission(Constants.CREATE_THREAD);
for (int i = 0; i < ids.length; i++) {
gb = new GroupBean();
group = manager.getGroup(ids[i]);
gb.setId(group.getID());
gb.setName(group.getName());
fb.addGroupsWithThreadPerm(gb);
}
ids = forum.groupsWithPermission(Constants.CREATE_MESSAGE);
for (int i = 0; i < ids.length; i++) {
gb = new GroupBean();
group = manager.getGroup(ids[i]);
gb.setId(group.getID());
gb.setName(group.getName());
fb.addGroupsWithMessagePerm(gb);
}
ids = forum.groupsWithPermission(Constants.MODERATOR);
for (int i = 0; i < ids.length; i++) {
gb = new GroupBean();
group = manager.getGroup(ids[i]);
gb.setId(group.getID());
gb.setName(group.getName());
fb.addGroupsWithModeratorPerm(gb);
}
ids = forum.groupsWithPermission(Constants.FORUM_ADMIN);
for (int i = 0; i < ids.length; i++) {
gb = new GroupBean();
group = manager.getGroup(ids[i]);
gb.setId(group.getID());
gb.setName(group.getName());