1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.portal.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.util.UnicodeProperties;
28  import com.liferay.portal.model.Account;
29  import com.liferay.portal.model.Address;
30  import com.liferay.portal.model.Company;
31  import com.liferay.portal.model.EmailAddress;
32  import com.liferay.portal.model.Phone;
33  import com.liferay.portal.model.RoleConstants;
34  import com.liferay.portal.model.Website;
35  import com.liferay.portal.security.auth.PrincipalException;
36  import com.liferay.portal.service.base.CompanyServiceBaseImpl;
37  import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
38  
39  import java.io.File;
40  
41  import java.util.List;
42  
43  /**
44   * <a href="CompanyServiceImpl.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   * @author Julio Camarero
48   *
49   */
50  public class CompanyServiceImpl extends CompanyServiceBaseImpl {
51  
52      public Company addCompany(String webId, String virtualHost, String mx)
53          throws PortalException, SystemException {
54  
55          if (!getPermissionChecker().isOmniadmin()) {
56              throw new PrincipalException();
57          }
58  
59          return companyLocalService.addCompany(webId, virtualHost, mx);
60      }
61  
62      public Company getCompanyById(long companyId)
63          throws PortalException, SystemException {
64  
65          return companyLocalService.getCompanyById(companyId);
66      }
67  
68      public Company getCompanyByLogoId(long logoId)
69          throws PortalException, SystemException {
70  
71          return companyLocalService.getCompanyByLogoId(logoId);
72      }
73  
74      public Company getCompanyByMx(String mx)
75          throws PortalException, SystemException {
76  
77          return companyLocalService.getCompanyByMx(mx);
78      }
79  
80      public Company getCompanyByVirtualHost(String virtualHost)
81          throws PortalException, SystemException {
82  
83          return companyLocalService.getCompanyByVirtualHost(virtualHost);
84      }
85  
86      public Company getCompanyByWebId(String webId)
87          throws PortalException, SystemException {
88  
89          return companyLocalService.getCompanyByWebId(webId);
90      }
91  
92      public Company updateCompany(long companyId, String virtualHost, String mx)
93          throws PortalException, SystemException {
94  
95          if (!getPermissionChecker().isOmniadmin()) {
96              throw new PrincipalException();
97          }
98  
99          return companyLocalService.updateCompany(companyId, virtualHost, mx);
100     }
101 
102     public Company updateCompany(
103             long companyId, String virtualHost, String mx, String homeURL,
104             String name, String legalName, String legalId, String legalType,
105             String sicCode, String tickerSymbol, String industry, String type,
106             String size)
107         throws PortalException, SystemException {
108 
109         if (!roleLocalService.hasUserRole(
110                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
111 
112             throw new PrincipalException();
113         }
114 
115         return companyLocalService.updateCompany(
116             companyId, virtualHost, mx, homeURL, name, legalName, legalId,
117             legalType, sicCode, tickerSymbol, industry, type, size);
118     }
119 
120     public Company updateCompany(
121             long companyId, String virtualHost, String mx, String homeURL,
122             String name, String legalName, String legalId, String legalType,
123             String sicCode, String tickerSymbol, String industry, String type,
124             String size, String languageId, String timeZoneId,
125             List<Address> addresses, List<EmailAddress> emailAddresses,
126             List<Phone> phones, List<Website> websites,
127             UnicodeProperties properties)
128         throws PortalException, SystemException {
129 
130         Company company = updateCompany(
131             companyId, virtualHost, mx, homeURL, name, legalName, legalId,
132             legalType, sicCode, tickerSymbol, industry, type, size);
133 
134         updateDisplay(company.getCompanyId(), languageId, timeZoneId);
135 
136         updatePreferences(company.getCompanyId(), properties);
137 
138         EnterpriseAdminUtil.updateAddresses(
139             Account.class.getName(), company.getAccountId(), addresses);
140 
141         EnterpriseAdminUtil.updateEmailAddresses(
142             Account.class.getName(), company.getAccountId(), emailAddresses);
143 
144         EnterpriseAdminUtil.updatePhones(
145             Account.class.getName(), company.getAccountId(), phones);
146 
147         EnterpriseAdminUtil.updateWebsites(
148             Account.class.getName(), company.getAccountId(), websites);
149 
150         return company;
151     }
152 
153     public void updateDisplay(
154             long companyId, String languageId, String timeZoneId)
155         throws PortalException, SystemException {
156 
157         if (!roleLocalService.hasUserRole(
158                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
159 
160             throw new PrincipalException();
161         }
162 
163         companyLocalService.updateDisplay(companyId, languageId, timeZoneId);
164     }
165 
166     public void updateLogo(long companyId, File file)
167         throws PortalException, SystemException {
168 
169         if (!roleLocalService.hasUserRole(
170                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
171 
172             throw new PrincipalException();
173         }
174 
175         companyLocalService.updateLogo(companyId, file);
176     }
177 
178     public void updatePreferences(long companyId, UnicodeProperties properties)
179         throws PortalException, SystemException {
180 
181         if (!roleLocalService.hasUserRole(
182                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
183 
184             throw new PrincipalException();
185         }
186 
187         companyLocalService.updatePreferences(companyId, properties);
188     }
189 
190     public void updateSecurity(
191             long companyId, String authType, boolean autoLogin,
192             boolean sendPassword, boolean strangers, boolean strangersWithMx,
193             boolean strangersVerify, boolean communityLogo)
194         throws PortalException, SystemException {
195 
196         if (!roleLocalService.hasUserRole(
197                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
198 
199             throw new PrincipalException();
200         }
201 
202         companyLocalService.updateSecurity(
203             companyId, authType, autoLogin, sendPassword, strangers,
204             strangersWithMx, strangersVerify, communityLogo);
205     }
206 
207 }