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:
020: package com.nabhinc.portlet.useradmin;
021:
022: import java.io.IOException;
023:
024: import javax.portlet.ActionRequest;
025: import javax.portlet.ActionResponse;
026: import javax.portlet.PortletException;
027:
028: import org.w3c.dom.Element;
029:
030: import com.nabhinc.portal.api.PortalInformationStore;
031: import com.nabhinc.portal.api.PortalInformationStoreLocator;
032: import com.nabhinc.portal.spi.UserAdminServiceLocator;
033: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
034: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
035: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
036: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
037: import com.nabhinc.spi.UserAdminService;
038: import com.nabhinc.util.StringUtil;
039:
040: /**
041: *
042: *
043: * @author Padmanabh Dabke
044: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
045: */
046: public class UserDeleter extends BaseRequestProcessor implements
047: ActionProcessor {
048: private String[] brpPSites = { "/my/" };
049:
050: public void init(Element arg0, ControllerPortletConfig config)
051: throws PortletException {
052: super .init(arg0, config);
053: String sites = config.getParameter("psites-path");
054: if (sites != null) {
055: brpPSites = StringUtil.split(sites, ",");
056: for (int i = 0; i < brpPSites.length; i++) {
057: if (!brpPSites[i].startsWith("/"))
058: brpPSites[i] = "/" + brpPSites[i];
059: if (!brpPSites[i].endsWith("/"))
060: brpPSites[i] = brpPSites[i] + "/";
061: }
062: }
063: }
064:
065: public String process(ActionRequest request,
066: ActionResponse response, ActionConfig actionConfig)
067: throws PortletException, IOException {
068: UserAdminService adminService = UserAdminServiceLocator
069: .getUserAdminService();
070: PortalInformationStore storeInfo = PortalInformationStoreLocator
071: .getPortalInformationStore();
072: if (adminService == null) {
073: throw new PortletException(
074: "Cannot delete user since user admin service is not running");
075: }
076:
077: String[] userIdStr = request.getParameterValues("marked");
078: if (userIdStr == null || userIdStr.length == 0)
079: return "success";
080: int[] userIds = new int[userIdStr.length];
081: String userName = null;
082: for (int i = 0; i < userIds.length; i++) {
083: userIds[i] = Integer.parseInt(userIdStr[i]);
084: try {
085: userName = adminService.getUser(userIds[i])
086: .getUserName();
087: // delete user from specified sites
088: for (int j = 0; j < brpPSites.length; j++)
089: storeInfo.deletePortalApplication(brpPSites[j]
090: + userName);
091: storeInfo.deleteUserPreferences(userName);
092: } catch (Exception ex) {
093: // Ignore. Continue with delete user anyway when the file does not exist nor removable.
094: }
095: }
096: adminService.deleteUsers(userIds);
097: return "success";
098: }
099:
100: }
|