1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.enterpriseadmin.action;
16  
17  import com.liferay.portal.AccountNameException;
18  import com.liferay.portal.CompanyMxException;
19  import com.liferay.portal.CompanyVirtualHostException;
20  import com.liferay.portal.CompanyWebIdException;
21  import com.liferay.portal.kernel.servlet.SessionErrors;
22  import com.liferay.portal.kernel.util.Constants;
23  import com.liferay.portal.kernel.util.ParamUtil;
24  import com.liferay.portal.model.Company;
25  import com.liferay.portal.security.auth.PrincipalException;
26  import com.liferay.portal.service.CompanyServiceUtil;
27  import com.liferay.portal.struts.PortletAction;
28  import com.liferay.portal.util.PortalUtil;
29  
30  import javax.portlet.ActionRequest;
31  import javax.portlet.ActionResponse;
32  import javax.portlet.PortletConfig;
33  
34  import org.apache.struts.action.ActionForm;
35  import org.apache.struts.action.ActionMapping;
36  
37  /**
38   * <a href="EditCompanyAction.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class EditCompanyAction extends PortletAction {
43  
44      public void processAction(
45              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
46              ActionRequest actionRequest, ActionResponse actionResponse)
47          throws Exception {
48  
49          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
50  
51          try {
52              if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
53                  updateCompany(actionRequest);
54                  updateDisplay(actionRequest);
55              }
56  
57              sendRedirect(actionRequest, actionResponse);
58          }
59          catch (Exception e) {
60              if (e instanceof PrincipalException) {
61                  SessionErrors.add(actionRequest, e.getClass().getName());
62  
63                  setForward(actionRequest, "portlet.enterprise_admin.error");
64              }
65              else if (e instanceof AccountNameException ||
66                       e instanceof CompanyMxException ||
67                       e instanceof CompanyVirtualHostException ||
68                       e instanceof CompanyWebIdException) {
69  
70                  SessionErrors.add(actionRequest, e.getClass().getName(), e);
71  
72                  setForward(actionRequest, "portlet.enterprise_admin.view");
73              }
74              else {
75                  throw e;
76              }
77          }
78      }
79  
80      protected void updateCompany(ActionRequest actionRequest) throws Exception {
81          long companyId = PortalUtil.getCompanyId(actionRequest);
82  
83          String virtualHost = ParamUtil.getString(actionRequest, "virtualHost");
84          String mx = ParamUtil.getString(actionRequest, "mx");
85          String name = ParamUtil.getString(actionRequest, "name");
86          String legalName = ParamUtil.getString(actionRequest, "legalName");
87          String legalId = ParamUtil.getString(actionRequest, "legalId");
88          String legalType = ParamUtil.getString(actionRequest, "legalType");
89          String sicCode = ParamUtil.getString(actionRequest, "sicCode");
90          String tickerSymbol = ParamUtil.getString(
91              actionRequest, "tickerSymbol");
92          String industry = ParamUtil.getString(actionRequest, "industry");
93          String type = ParamUtil.getString(actionRequest, "type");
94          String size = ParamUtil.getString(actionRequest, "size");
95  
96          CompanyServiceUtil.updateCompany(
97              companyId, virtualHost, mx, name, legalName, legalId, legalType,
98              sicCode, tickerSymbol, industry, type, size);
99      }
100 
101     protected void updateDisplay(ActionRequest actionRequest) throws Exception {
102         Company company = PortalUtil.getCompany(actionRequest);
103 
104         String languageId = ParamUtil.getString(actionRequest, "languageId");
105         String timeZoneId = ParamUtil.getString(actionRequest, "timeZoneId");
106         boolean communityLogo = ParamUtil.getBoolean(
107             actionRequest, "communityLogo");
108 
109         CompanyServiceUtil.updateDisplay(
110             company.getCompanyId(), languageId, timeZoneId);
111 
112         CompanyServiceUtil.updateSecurity(
113             company.getCompanyId(), company.getAuthType(),
114             company.isAutoLogin(), company.isSendPassword(),
115             company.isStrangers(), company.isStrangersWithMx(),
116             company.isStrangersVerify(), communityLogo);
117     }
118 
119 }