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