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.communities.action;
022:
023: import com.liferay.portal.MembershipRequestCommentsException;
024: import com.liferay.portal.NoSuchGroupException;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.model.MembershipRequest;
027: import com.liferay.portal.model.impl.MembershipRequestImpl;
028: import com.liferay.portal.security.auth.PrincipalException;
029: import com.liferay.portal.service.MembershipRequestServiceUtil;
030: import com.liferay.portal.struts.PortletAction;
031: import com.liferay.portal.util.LiveUsers;
032: import com.liferay.util.servlet.SessionErrors;
033: import com.liferay.util.servlet.SessionMessages;
034:
035: import javax.portlet.ActionRequest;
036: import javax.portlet.ActionResponse;
037: import javax.portlet.PortletConfig;
038: import javax.portlet.RenderRequest;
039: import javax.portlet.RenderResponse;
040:
041: import org.apache.struts.action.ActionForm;
042: import org.apache.struts.action.ActionForward;
043: import org.apache.struts.action.ActionMapping;
044:
045: /**
046: * <a href="ReplyMembershipRequestAction.java.html"><b><i>View Source</i></b>
047: * </a>
048: *
049: * @author Jorge Ferrer
050: *
051: */
052: public class ReplyMembershipRequestAction extends PortletAction {
053:
054: public void processAction(ActionMapping mapping, ActionForm form,
055: PortletConfig config, ActionRequest req, ActionResponse res)
056: throws Exception {
057:
058: try {
059: long membershipRequestId = ParamUtil.getLong(req,
060: "membershipRequestId");
061:
062: int statusId = ParamUtil.getInteger(req, "statusId");
063: String replyComments = ParamUtil.getString(req,
064: "replyComments");
065:
066: MembershipRequest membershipRequest = MembershipRequestServiceUtil
067: .getMembershipRequest(membershipRequestId);
068:
069: MembershipRequestServiceUtil.updateStatus(
070: membershipRequestId, replyComments, statusId);
071:
072: if (statusId == MembershipRequestImpl.STATUS_APPROVED) {
073: LiveUsers.joinGroup(new long[] { membershipRequest
074: .getUserId() }, membershipRequest.getGroupId());
075: }
076:
077: SessionMessages.add(req, "membership_reply_sent");
078:
079: sendRedirect(req, res);
080: } catch (Exception e) {
081: if (e instanceof NoSuchGroupException
082: || e instanceof PrincipalException) {
083:
084: SessionErrors.add(req, e.getClass().getName());
085:
086: setForward(req, "portlet.communities.error");
087: } else if (e instanceof MembershipRequestCommentsException) {
088:
089: SessionErrors.add(req, e.getClass().getName());
090:
091: setForward(req,
092: "portlet.communities.reply_membership_request");
093: } else {
094: throw e;
095: }
096: }
097: }
098:
099: public ActionForward render(ActionMapping mapping, ActionForm form,
100: PortletConfig config, RenderRequest req, RenderResponse res)
101: throws Exception {
102:
103: try {
104: ActionUtil.getGroup(req);
105: } catch (Exception e) {
106: if (e instanceof NoSuchGroupException
107: || e instanceof PrincipalException) {
108:
109: SessionErrors.add(req, e.getClass().getName());
110:
111: return mapping.findForward("portlet.communities.error");
112: } else {
113: throw e;
114: }
115: }
116:
117: return mapping.findForward(getForward(req,
118: "portlet.communities.reply_membership_request"));
119: }
120:
121: }
|