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