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.portal.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.kernel.util.UnicodeProperties;
25  import com.liferay.portal.model.Account;
26  import com.liferay.portal.model.Address;
27  import com.liferay.portal.model.Company;
28  import com.liferay.portal.model.EmailAddress;
29  import com.liferay.portal.model.Phone;
30  import com.liferay.portal.model.RoleConstants;
31  import com.liferay.portal.model.Website;
32  import com.liferay.portal.security.auth.PrincipalException;
33  import com.liferay.portal.service.base.CompanyServiceBaseImpl;
34  import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
35  
36  import java.io.File;
37  
38  import java.util.List;
39  
40  /**
41   * <a href="CompanyServiceImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   * @author Julio Camarero
45   *
46   */
47  public class CompanyServiceImpl extends CompanyServiceBaseImpl {
48  
49      public Company addCompany(
50              String webId, String virtualHost, String mx, String shardName,
51              boolean system)
52          throws PortalException, SystemException {
53  
54          if (!getPermissionChecker().isOmniadmin()) {
55              throw new PrincipalException();
56          }
57  
58          return companyLocalService.addCompany(
59              webId, virtualHost, mx, shardName, system);
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 }