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