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.AccountNameException;
024: import com.liferay.portal.CompanyMxException;
025: import com.liferay.portal.CompanyVirtualHostException;
026: import com.liferay.portal.CompanyWebIdException;
027: import com.liferay.portal.kernel.util.Constants;
028: import com.liferay.portal.kernel.util.ParamUtil;
029: import com.liferay.portal.model.Company;
030: import com.liferay.portal.security.auth.PrincipalException;
031: import com.liferay.portal.service.CompanyServiceUtil;
032: import com.liferay.portal.struts.PortletAction;
033: import com.liferay.portal.util.PortalUtil;
034: import com.liferay.util.servlet.SessionErrors;
035:
036: import javax.portlet.ActionRequest;
037: import javax.portlet.ActionResponse;
038: import javax.portlet.PortletConfig;
039:
040: import org.apache.struts.action.ActionForm;
041: import org.apache.struts.action.ActionMapping;
042:
043: /**
044: * <a href="EditCompanyAction.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Brian Wing Shun Chan
047: *
048: */
049: public class EditCompanyAction 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: updateCompany(req);
061: updateDisplay(req);
062: }
063:
064: sendRedirect(req, res);
065: } catch (Exception e) {
066: if (e instanceof PrincipalException) {
067: SessionErrors.add(req, e.getClass().getName());
068:
069: setForward(req, "portlet.enterprise_admin.error");
070: } else if (e instanceof AccountNameException
071: || e instanceof CompanyMxException
072: || e instanceof CompanyVirtualHostException
073: || e instanceof CompanyWebIdException) {
074:
075: SessionErrors.add(req, e.getClass().getName(), e);
076:
077: setForward(req, "portlet.enterprise_admin.view");
078: } else {
079: throw e;
080: }
081: }
082: }
083:
084: protected void updateCompany(ActionRequest req) throws Exception {
085: long companyId = PortalUtil.getCompanyId(req);
086:
087: String virtualHost = ParamUtil.getString(req, "virtualHost");
088: String mx = ParamUtil.getString(req, "mx");
089: String name = ParamUtil.getString(req, "name");
090: String legalName = ParamUtil.getString(req, "legalName");
091: String legalId = ParamUtil.getString(req, "legalId");
092: String legalType = ParamUtil.getString(req, "legalType");
093: String sicCode = ParamUtil.getString(req, "sicCode");
094: String tickerSymbol = ParamUtil.getString(req, "tickerSymbol");
095: String industry = ParamUtil.getString(req, "industry");
096: String type = ParamUtil.getString(req, "type");
097: String size = ParamUtil.getString(req, "size");
098:
099: CompanyServiceUtil.updateCompany(companyId, virtualHost, mx,
100: name, legalName, legalId, legalType, sicCode,
101: tickerSymbol, industry, type, size);
102: }
103:
104: protected void updateDisplay(ActionRequest req) throws Exception {
105: Company company = PortalUtil.getCompany(req);
106:
107: String languageId = ParamUtil.getString(req, "languageId");
108: String timeZoneId = ParamUtil.getString(req, "timeZoneId");
109: boolean communityLogo = ParamUtil.getBoolean(req,
110: "communityLogo");
111:
112: CompanyServiceUtil.updateDisplay(company.getCompanyId(),
113: languageId, timeZoneId);
114:
115: CompanyServiceUtil.updateSecurity(company.getCompanyId(),
116: company.getAuthType(), company.isAutoLogin(), company
117: .isSendPassword(), company.isStrangers(),
118: company.isStrangersWithMx(), company
119: .isStrangersVerify(), communityLogo);
120: }
121:
122: }
|