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.model.Company;
28  import com.liferay.portal.model.RoleConstants;
29  import com.liferay.portal.security.auth.PrincipalException;
30  import com.liferay.portal.service.base.CompanyServiceBaseImpl;
31  
32  import java.io.File;
33  
34  /**
35   * <a href="CompanyServiceImpl.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   *
39   */
40  public class CompanyServiceImpl extends CompanyServiceBaseImpl {
41  
42      public Company addCompany(String webId, String virtualHost, String mx)
43          throws PortalException, SystemException {
44  
45          if (!getPermissionChecker().isOmniadmin()) {
46              throw new PrincipalException();
47          }
48  
49          return companyLocalService.addCompany(webId, virtualHost, mx);
50      }
51  
52      public Company getCompanyById(long companyId)
53          throws PortalException, SystemException {
54  
55          return companyLocalService.getCompanyById(companyId);
56      }
57  
58      public Company getCompanyByLogoId(long logoId)
59          throws PortalException, SystemException {
60  
61          return companyLocalService.getCompanyByLogoId(logoId);
62      }
63  
64      public Company getCompanyByMx(String mx)
65          throws PortalException, SystemException {
66  
67          return companyLocalService.getCompanyByMx(mx);
68      }
69  
70      public Company getCompanyByVirtualHost(String virtualHost)
71          throws PortalException, SystemException {
72  
73          return companyLocalService.getCompanyByVirtualHost(virtualHost);
74      }
75  
76      public Company getCompanyByWebId(String webId)
77          throws PortalException, SystemException {
78  
79          return companyLocalService.getCompanyByWebId(webId);
80      }
81  
82      public Company updateCompany(long companyId, String virtualHost, String mx)
83          throws PortalException, SystemException {
84  
85          if (!getPermissionChecker().isOmniadmin()) {
86              throw new PrincipalException();
87          }
88  
89          return companyLocalService.updateCompany(companyId, virtualHost, mx);
90      }
91  
92      public Company updateCompany(
93              long companyId, String virtualHost, String mx, String homeURL,
94              String name, String legalName, String legalId, String legalType,
95              String sicCode, String tickerSymbol, String industry, String type,
96              String size)
97          throws PortalException, SystemException {
98  
99          if (!roleLocalService.hasUserRole(
100                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
101 
102             throw new PrincipalException();
103         }
104 
105         return companyLocalService.updateCompany(
106             companyId, virtualHost, mx, homeURL, name, legalName, legalId,
107             legalType, sicCode, tickerSymbol, industry, type, size);
108     }
109 
110     public void updateDisplay(
111             long companyId, String languageId, String timeZoneId)
112         throws PortalException, SystemException {
113 
114         if (!roleLocalService.hasUserRole(
115                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
116 
117             throw new PrincipalException();
118         }
119 
120         companyLocalService.updateDisplay(companyId, languageId, timeZoneId);
121     }
122 
123     public void updateLogo(long companyId, File file)
124         throws PortalException, SystemException {
125 
126         if (!roleLocalService.hasUserRole(
127                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
128 
129             throw new PrincipalException();
130         }
131 
132         companyLocalService.updateLogo(companyId, file);
133     }
134 
135     public void updateSecurity(
136             long companyId, String authType, boolean autoLogin,
137             boolean sendPassword, boolean strangers, boolean strangersWithMx,
138             boolean strangersVerify, boolean communityLogo)
139         throws PortalException, SystemException {
140 
141         if (!roleLocalService.hasUserRole(
142                 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) {
143 
144             throw new PrincipalException();
145         }
146 
147         companyLocalService.updateSecurity(
148             companyId, authType, autoLogin, sendPassword, strangers,
149             strangersWithMx, strangersVerify, communityLogo);
150     }
151 
152 }