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(
53              String webId, String virtualHost, String mx, String shardName,
54              boolean system)
55          throws PortalException, SystemException {
56  
57          if (!getPermissionChecker().isOmniadmin()) {
58              throw new PrincipalException();
59          }
60  
61          return companyLocalService.addCompany(
62              webId, virtualHost, mx, shardName, system);
63      }
64  
65      public Company getCompanyById(long companyId)
66          throws PortalException, SystemException {
67  
68          return companyLocalService.getCompanyById(companyId);
69      }
70  
71      public Company getCompanyByLogoId(long logoId)
72          throws PortalException, SystemException {
73  
74          return companyLocalService.getCompanyByLogoId(logoId);
75      }
76  
77      public Company getCompanyByMx(String mx)
78          throws PortalException, SystemException {
79  
80          return companyLocalService.getCompanyByMx(mx);
81      }
82  
83      public Company getCompanyByVirtualHost(String virtualHost)
84          throws PortalException, SystemException {
85  
86          return companyLocalService.getCompanyByVirtualHost(virtualHost);
87      }
88  
89      public Company getCompanyByWebId(String webId)
90          throws PortalException, SystemException {
91  
92          return companyLocalService.getCompanyByWebId(webId);
93      }
94  
95      public Company updateCompany(long companyId, String virtualHost, String mx)
96          throws PortalException, SystemException {
97  
98          if (!getPermissionChecker().isOmniadmin()) {
99              throw new PrincipalException();
100         }
101 
102         return companyLocalService.updateCompany(companyId, virtualHost, mx);
103     }
104 
105     public Company updateCompany(
106             long companyId, String virtualHost, String mx, String homeURL,
107             String name, String legalName, String legalId, String legalType,
108             String sicCode, String tickerSymbol, String industry, String type,
109             String size)
110         throws PortalException, SystemException {
111 
112         if (!roleLocalService.hasUserRole(
113                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
114 
115             throw new PrincipalException();
116         }
117 
118         return companyLocalService.updateCompany(
119             companyId, virtualHost, mx, homeURL, name, legalName, legalId,
120             legalType, sicCode, tickerSymbol, industry, type, size);
121     }
122 
123     public Company updateCompany(
124             long companyId, String virtualHost, String mx, String homeURL,
125             String name, String legalName, String legalId, String legalType,
126             String sicCode, String tickerSymbol, String industry, String type,
127             String size, String languageId, String timeZoneId,
128             List<Address> addresses, List<EmailAddress> emailAddresses,
129             List<Phone> phones, List<Website> websites,
130             UnicodeProperties properties)
131         throws PortalException, SystemException {
132 
133         Company company = updateCompany(
134             companyId, virtualHost, mx, homeURL, name, legalName, legalId,
135             legalType, sicCode, tickerSymbol, industry, type, size);
136 
137         updateDisplay(company.getCompanyId(), languageId, timeZoneId);
138 
139         updatePreferences(company.getCompanyId(), properties);
140 
141         EnterpriseAdminUtil.updateAddresses(
142             Account.class.getName(), company.getAccountId(), addresses);
143 
144         EnterpriseAdminUtil.updateEmailAddresses(
145             Account.class.getName(), company.getAccountId(), emailAddresses);
146 
147         EnterpriseAdminUtil.updatePhones(
148             Account.class.getName(), company.getAccountId(), phones);
149 
150         EnterpriseAdminUtil.updateWebsites(
151             Account.class.getName(), company.getAccountId(), websites);
152 
153         return company;
154     }
155 
156     public void updateDisplay(
157             long companyId, String languageId, String timeZoneId)
158         throws PortalException, SystemException {
159 
160         if (!roleLocalService.hasUserRole(
161                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
162 
163             throw new PrincipalException();
164         }
165 
166         companyLocalService.updateDisplay(companyId, languageId, timeZoneId);
167     }
168 
169     public void updateLogo(long companyId, File file)
170         throws PortalException, SystemException {
171 
172         if (!roleLocalService.hasUserRole(
173                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
174 
175             throw new PrincipalException();
176         }
177 
178         companyLocalService.updateLogo(companyId, file);
179     }
180 
181     public void updatePreferences(long companyId, UnicodeProperties properties)
182         throws PortalException, SystemException {
183 
184         if (!roleLocalService.hasUserRole(
185                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
186 
187             throw new PrincipalException();
188         }
189 
190         companyLocalService.updatePreferences(companyId, properties);
191     }
192 
193     public void updateSecurity(
194             long companyId, String authType, boolean autoLogin,
195             boolean sendPassword, boolean strangers, boolean strangersWithMx,
196             boolean strangersVerify, boolean communityLogo)
197         throws PortalException, SystemException {
198 
199         if (!roleLocalService.hasUserRole(
200                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
201 
202             throw new PrincipalException();
203         }
204 
205         companyLocalService.updateSecurity(
206             companyId, authType, autoLogin, sendPassword, strangers,
207             strangersWithMx, strangersVerify, communityLogo);
208     }
209 
210 }