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.AddressCityException;
27  import com.liferay.portal.AddressStreetException;
28  import com.liferay.portal.AddressZipException;
29  import com.liferay.portal.CompanyMxException;
30  import com.liferay.portal.CompanyVirtualHostException;
31  import com.liferay.portal.CompanyWebIdException;
32  import com.liferay.portal.EmailAddressException;
33  import com.liferay.portal.NoSuchCountryException;
34  import com.liferay.portal.NoSuchListTypeException;
35  import com.liferay.portal.NoSuchRegionException;
36  import com.liferay.portal.PhoneNumberException;
37  import com.liferay.portal.WebsiteURLException;
38  import com.liferay.portal.kernel.servlet.SessionErrors;
39  import com.liferay.portal.kernel.util.Constants;
40  import com.liferay.portal.kernel.util.ParamUtil;
41  import com.liferay.portal.kernel.util.PropertiesParamUtil;
42  import com.liferay.portal.kernel.util.PropsKeys;
43  import com.liferay.portal.kernel.util.UnicodeProperties;
44  import com.liferay.portal.model.Address;
45  import com.liferay.portal.model.Company;
46  import com.liferay.portal.model.EmailAddress;
47  import com.liferay.portal.model.Phone;
48  import com.liferay.portal.model.Website;
49  import com.liferay.portal.security.auth.PrincipalException;
50  import com.liferay.portal.service.CompanyServiceUtil;
51  import com.liferay.portal.struts.PortletAction;
52  import com.liferay.portal.util.PortalUtil;
53  import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
54  
55  import java.util.List;
56  
57  import javax.portlet.ActionRequest;
58  import javax.portlet.ActionResponse;
59  import javax.portlet.PortletConfig;
60  
61  import org.apache.struts.action.ActionForm;
62  import org.apache.struts.action.ActionMapping;
63  
64  /**
65   * <a href="EditCompanyAction.java.html"><b><i>View Source</i></b></a>
66   *
67   * @author Brian Wing Shun Chan
68   * @author Julio Camarero
69   */
70  public class EditCompanyAction extends PortletAction {
71  
72      public void processAction(
73              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
74              ActionRequest actionRequest, ActionResponse actionResponse)
75          throws Exception {
76  
77          String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
78  
79          try {
80              if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
81                  updateCompany(actionRequest);
82                  updateDisplay(actionRequest);
83              }
84  
85              sendRedirect(actionRequest, actionResponse);
86          }
87          catch (Exception e) {
88              if (e instanceof PrincipalException) {
89                  SessionErrors.add(actionRequest, e.getClass().getName());
90  
91                  setForward(actionRequest, "portlet.enterprise_admin.error");
92              }
93              else if (e instanceof AddressCityException ||
94                       e instanceof AccountNameException ||
95                       e instanceof AddressStreetException ||
96                       e instanceof AddressZipException ||
97                       e instanceof CompanyMxException ||
98                       e instanceof CompanyVirtualHostException ||
99                       e instanceof CompanyWebIdException ||
100                      e instanceof EmailAddressException ||
101                      e instanceof NoSuchCountryException ||
102                      e instanceof NoSuchListTypeException ||
103                      e instanceof NoSuchRegionException ||
104                      e instanceof PhoneNumberException ||
105                      e instanceof WebsiteURLException) {
106 
107                 if (e instanceof NoSuchListTypeException) {
108                     NoSuchListTypeException nslte = (NoSuchListTypeException)e;
109 
110                     SessionErrors.add(
111                         actionRequest,
112                         e.getClass().getName() + nslte.getType());
113                 }
114                 else {
115                     SessionErrors.add(actionRequest, e.getClass().getName(), e);
116                 }
117 
118                 setForward(actionRequest, "portlet.enterprise_admin.view");
119             }
120             else {
121                 throw e;
122             }
123         }
124     }
125 
126     protected void updateCompany(ActionRequest actionRequest) throws Exception {
127         long companyId = PortalUtil.getCompanyId(actionRequest);
128 
129         String virtualHost = ParamUtil.getString(actionRequest, "virtualHost");
130         String mx = ParamUtil.getString(actionRequest, "mx");
131         String homeURL = ParamUtil.getString(actionRequest, "homeURL");
132         String name = ParamUtil.getString(actionRequest, "name");
133         String legalName = ParamUtil.getString(actionRequest, "legalName");
134         String legalId = ParamUtil.getString(actionRequest, "legalId");
135         String legalType = ParamUtil.getString(actionRequest, "legalType");
136         String sicCode = ParamUtil.getString(actionRequest, "sicCode");
137         String tickerSymbol = ParamUtil.getString(
138             actionRequest, "tickerSymbol");
139         String industry = ParamUtil.getString(actionRequest, "industry");
140         String type = ParamUtil.getString(actionRequest, "type");
141         String size = ParamUtil.getString(actionRequest, "size");
142         String languageId = ParamUtil.getString(actionRequest, "languageId");
143         String timeZoneId = ParamUtil.getString(actionRequest, "timeZoneId");
144         List<Address> addresses = EnterpriseAdminUtil.getAddresses(
145             actionRequest);
146         List<EmailAddress> emailAddresses =
147             EnterpriseAdminUtil.getEmailAddresses(actionRequest);
148         List<Phone> phones = EnterpriseAdminUtil.getPhones(actionRequest);
149         List<Website> websites = EnterpriseAdminUtil.getWebsites(actionRequest);
150         UnicodeProperties properties = PropertiesParamUtil.getProperties(
151             actionRequest, "settings(");
152 
153         CompanyServiceUtil.updateCompany(
154             companyId, virtualHost, mx, homeURL, name, legalName, legalId,
155             legalType, sicCode, tickerSymbol, industry, type, size, languageId,
156             timeZoneId, addresses, emailAddresses, phones, websites,
157             properties);
158     }
159 
160     protected void updateDisplay(ActionRequest actionRequest) throws Exception {
161         Company company = PortalUtil.getCompany(actionRequest);
162 
163         String languageId = ParamUtil.getString(actionRequest, "languageId");
164         String timeZoneId = ParamUtil.getString(actionRequest, "timeZoneId");
165 
166         CompanyServiceUtil.updateDisplay(
167             company.getCompanyId(), languageId, timeZoneId);
168 
169         boolean communityLogo = ParamUtil.getBoolean(
170             actionRequest,
171             "settings(" + PropsKeys.COMPANY_SECURITY_COMMUNITY_LOGO + ")");
172 
173         CompanyServiceUtil.updateSecurity(
174             company.getCompanyId(), company.getAuthType(),
175             company.isAutoLogin(), company.isSendPassword(),
176             company.isStrangers(), company.isStrangersWithMx(),
177             company.isStrangersVerify(), communityLogo);
178 
179         boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo");
180 
181         if (deleteLogo) {
182             CompanyServiceUtil.deleteLogo(company.getCompanyId());
183         }
184     }
185 
186 }