001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.enterpriseadmin.action;
022:
023: import com.liferay.portal.NoSuchUserGroupException;
024: import com.liferay.portal.kernel.util.Constants;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.StringUtil;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.security.auth.PrincipalException;
029: import com.liferay.portal.service.UserServiceUtil;
030: import com.liferay.portal.struts.PortletAction;
031: import com.liferay.util.servlet.SessionErrors;
032:
033: import javax.portlet.ActionRequest;
034: import javax.portlet.ActionResponse;
035: import javax.portlet.PortletConfig;
036: import javax.portlet.RenderRequest;
037: import javax.portlet.RenderResponse;
038:
039: import org.apache.struts.action.ActionForm;
040: import org.apache.struts.action.ActionForward;
041: import org.apache.struts.action.ActionMapping;
042:
043: /**
044: * <a href="EditUserGroupAssignmentsAction.java.html"><b><i>View Source</i></b>
045: * </a>
046: *
047: * @author Charles May
048: *
049: */
050: public class EditUserGroupAssignmentsAction extends PortletAction {
051:
052: public void processAction(ActionMapping mapping, ActionForm form,
053: PortletConfig config, ActionRequest req, ActionResponse res)
054: throws Exception {
055:
056: String cmd = ParamUtil.getString(req, Constants.CMD);
057:
058: try {
059: if (cmd.equals("user_group_users")) {
060: updateUserGroupUsers(req);
061: }
062:
063: if (Validator.isNotNull(cmd)) {
064: String redirect = ParamUtil.getString(req,
065: "assignmentsRedirect");
066:
067: sendRedirect(req, res, redirect);
068: }
069: } catch (Exception e) {
070: if (e instanceof NoSuchUserGroupException
071: || e instanceof PrincipalException) {
072:
073: SessionErrors.add(req, e.getClass().getName());
074:
075: setForward(req, "portlet.enterprise_admin.error");
076: } else {
077: throw e;
078: }
079: }
080: }
081:
082: public ActionForward render(ActionMapping mapping, ActionForm form,
083: PortletConfig config, RenderRequest req, RenderResponse res)
084: throws Exception {
085:
086: try {
087: ActionUtil.getUserGroup(req);
088: } catch (Exception e) {
089: if (e instanceof NoSuchUserGroupException
090: || e instanceof PrincipalException) {
091:
092: SessionErrors.add(req, e.getClass().getName());
093:
094: return mapping
095: .findForward("portlet.enterprise_admin.error");
096: } else {
097: throw e;
098: }
099: }
100:
101: return mapping
102: .findForward(getForward(req,
103: "portlet.enterprise_admin.edit_user_group_assignments"));
104: }
105:
106: protected void updateUserGroupUsers(ActionRequest req)
107: throws Exception {
108: long userGroupId = ParamUtil.getLong(req, "userGroupId");
109:
110: long[] addUserIds = StringUtil.split(ParamUtil.getString(req,
111: "addUserIds"), 0L);
112: long[] removeUserIds = StringUtil.split(ParamUtil.getString(
113: req, "removeUserIds"), 0L);
114:
115: UserServiceUtil.addUserGroupUsers(userGroupId, addUserIds);
116: UserServiceUtil.unsetUserGroupUsers(userGroupId, removeUserIds);
117: }
118:
119: }
|