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.NoSuchListTypeException;
024: import com.liferay.portal.NoSuchPhoneException;
025: import com.liferay.portal.PhoneNumberException;
026: import com.liferay.portal.kernel.util.Constants;
027: import com.liferay.portal.kernel.util.ParamUtil;
028: import com.liferay.portal.security.auth.PrincipalException;
029: import com.liferay.portal.service.PhoneServiceUtil;
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="EditPhoneAction.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Brian Wing Shun Chan
047: *
048: */
049: public class EditPhoneAction extends PortletAction {
050:
051: public void processAction(ActionMapping mapping, ActionForm form,
052: PortletConfig config, ActionRequest req, ActionResponse res)
053: throws Exception {
054:
055: String cmd = ParamUtil.getString(req, Constants.CMD);
056:
057: try {
058: if (cmd.equals(Constants.ADD)
059: || cmd.equals(Constants.UPDATE)) {
060: updatePhone(req);
061: } else if (cmd.equals(Constants.DELETE)) {
062: deletePhone(req);
063: }
064:
065: sendRedirect(req, res);
066: } catch (Exception e) {
067: if (e instanceof NoSuchPhoneException
068: || e instanceof PrincipalException) {
069:
070: SessionErrors.add(req, e.getClass().getName());
071:
072: setForward(req, "portlet.enterprise_admin.error");
073: } else if (e instanceof NoSuchListTypeException
074: || e instanceof PhoneNumberException) {
075:
076: SessionErrors.add(req, e.getClass().getName());
077: } else {
078: throw e;
079: }
080: }
081: }
082:
083: public ActionForward render(ActionMapping mapping, ActionForm form,
084: PortletConfig config, RenderRequest req, RenderResponse res)
085: throws Exception {
086:
087: try {
088: ActionUtil.getPhone(req);
089: } catch (Exception e) {
090: if (e instanceof NoSuchPhoneException
091: || e instanceof PrincipalException) {
092:
093: SessionErrors.add(req, e.getClass().getName());
094:
095: return mapping
096: .findForward("portlet.enterprise_admin.error");
097: } else {
098: throw e;
099: }
100: }
101:
102: return mapping.findForward(getForward(req,
103: "portlet.enterprise_admin.edit_phone"));
104: }
105:
106: protected void deletePhone(ActionRequest req) throws Exception {
107: long phoneId = ParamUtil.getLong(req, "phoneId");
108:
109: PhoneServiceUtil.deletePhone(phoneId);
110: }
111:
112: protected void updatePhone(ActionRequest req) throws Exception {
113: long phoneId = ParamUtil.getLong(req, "phoneId");
114:
115: String className = ParamUtil.getString(req, "className");
116: long classPK = ParamUtil.getLong(req, "classPK");
117:
118: String number = ParamUtil.getString(req, "number");
119: String extension = ParamUtil.getString(req, "extension");
120: int typeId = ParamUtil.getInteger(req, "typeId");
121: boolean primary = ParamUtil.getBoolean(req, "primary");
122:
123: if (phoneId <= 0) {
124:
125: // Add phone
126:
127: PhoneServiceUtil.addPhone(className, classPK, number,
128: extension, typeId, primary);
129: } else {
130:
131: // Update phone
132:
133: PhoneServiceUtil.updatePhone(phoneId, number, extension,
134: typeId, primary);
135: }
136: }
137:
138: }
|