001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portlet.roleadmin;
020:
021: import java.io.IOException;
022: import java.util.List;
023:
024: import javax.portlet.PortletException;
025: import javax.portlet.RenderRequest;
026: import javax.portlet.RenderResponse;
027:
028: import com.nabhinc.portal.spi.RoleAdminServiceLocator;
029: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
030: import com.nabhinc.portlet.mvcportlet.core.RenderConfig;
031: import com.nabhinc.portlet.mvcportlet.core.RenderProcessor;
032: import com.nabhinc.spi.RoleAdminService;
033:
034: /**
035: *
036: *
037: * @author Padmanabh Dabke
038: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
039: */
040: public class RoleListFetcher extends BaseRequestProcessor implements
041: RenderProcessor {
042:
043: public String process(RenderRequest request,
044: RenderResponse response, RenderConfig renderConfig)
045: throws PortletException, IOException {
046: RoleAdminService adminService = RoleAdminServiceLocator
047: .getRoleAdminService();
048: if (adminService == null) {
049: throw new PortletException(
050: "Cannot retrieve roles since role admin service is not running");
051: }
052: int numUsers = adminService.getUserRoleCount();
053: if (numUsers == 0)
054: return "no-such-record";
055:
056: List roleList = null;
057: int pageIndex = 0;
058: int pageSize = 10;
059:
060: String pageIndexStr = (String) request
061: .getParameter("pageindex");
062: if (pageIndexStr != null) {
063: pageIndex = Integer.parseInt(pageIndexStr);
064: }
065:
066: String pageSizeStr = request.getPreferences().getValue(
067: "pagesize", null);
068: if (pageSizeStr != null)
069: pageSize = Integer.parseInt(pageSizeStr);
070:
071: request.setAttribute("role_admin.role_count", new Integer(
072: numUsers));
073: request.setAttribute("role_admin.page_index", new Integer(
074: pageIndex));
075: request.setAttribute("role_admin.page_size", new Integer(
076: pageSize));
077:
078: int offset = pageIndex * pageSize;
079: if (offset >= numUsers)
080: return "page-empty";
081: String descending = request.getParameter("descending");
082: if (descending == null) {
083: descending = (String) request.getPortletSession()
084: .getAttribute("descending");
085: } else {
086: request.getPortletSession().setAttribute("descending",
087: descending);
088: }
089: boolean isDescending = "true".equals(descending);
090:
091: String orderBy = request.getParameter("orderby");
092: if (orderBy == null) {
093: orderBy = (String) request.getPortletSession()
094: .getAttribute("orderby");
095: } else {
096: request.getPortletSession()
097: .setAttribute("orderby", orderBy);
098: }
099: roleList = adminService.getUserRoles(offset, pageSize, orderBy,
100: isDescending);
101: if (roleList.size() > 0) {
102: request.setAttribute("role_admin.role_list", roleList);
103: return "success";
104: } else {
105: return "page-empty";
106: }
107:
108: }
109:
110: }
|