}
} finally {
Database.dispose(ps);
}
UserSecurity security = new UserSecurity(userProfileId, superAdmin);
List<RoleSecurity> roles = new ArrayList<RoleSecurity>();
Map<Long, RoleSecurity> roleIds = new HashMap<Long, RoleSecurity>();
try {
// select the roles;
ps =
conn.prepareStatement("SELECT role_id, name, description FROM role " + "WHERE role_id IN "
+ "(SELECT role_id from user_role WHERE user_profile_id = ?)");
ps.setLong(1, userProfileId);
rs = ps.executeQuery();
while (rs.next()) {
RoleSecurity role = new RoleSecurity(rs.getLong(1), rs.getString(2), rs.getString(3));
roles.add(role);
roleIds.put(role.getId(), role);
}
} finally {
Database.dispose(ps);
}
try {
// select the contests permissions
ps =
conn
.prepareStatement("SELECT role_id, contest_id, permission_level_id FROM contest_permission "
+ "WHERE role_id IN " + "(SELECT role_id from user_role WHERE user_profile_id = ?)");
ps.setLong(1, userProfileId);
rs = ps.executeQuery();
while (rs.next()) {
RoleSecurity role = roleIds.get(rs.getLong(1));
role.getContestPermission().addPermission(rs.getLong(2), PermissionLevel.findById(rs.getLong(3)));
}
} finally {
Database.dispose(ps);
}
try {
// select the forum permissions
ps =
conn.prepareStatement("SELECT role_id, forum_id, permission_level_id FROM forum_permission "
+ "WHERE role_id IN " + "(SELECT role_id from user_role WHERE user_profile_id = ?)");
ps.setLong(1, userProfileId);
rs = ps.executeQuery();
while (rs.next()) {
RoleSecurity role = roleIds.get(rs.getLong(1));
role.getForumPermission().addPermission(rs.getLong(2), PermissionLevel.findById(rs.getLong(3)));
}
} finally {
Database.dispose(ps);
}
for (RoleSecurity role : roles) {
security.importRole(role);
}
return security;
} catch (SQLException e) {