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