001 /** 002 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved. 003 * 004 * The contents of this file are subject to the terms of the Liferay Enterprise 005 * Subscription License ("License"). You may not use this file except in 006 * compliance with the License. You can obtain a copy of the License by 007 * contacting Liferay, Inc. See the License for the specific language governing 008 * permissions and limitations under the License, including but not limited to 009 * distribution rights of the Software. 010 * 011 * 012 * 013 */ 014 015 package com.liferay.portal.service.impl; 016 017 import com.liferay.portal.kernel.exception.PortalException; 018 import com.liferay.portal.kernel.exception.SystemException; 019 import com.liferay.portal.kernel.util.UnicodeProperties; 020 import com.liferay.portal.model.Account; 021 import com.liferay.portal.model.Address; 022 import com.liferay.portal.model.Company; 023 import com.liferay.portal.model.EmailAddress; 024 import com.liferay.portal.model.Phone; 025 import com.liferay.portal.model.RoleConstants; 026 import com.liferay.portal.model.Website; 027 import com.liferay.portal.security.auth.PrincipalException; 028 import com.liferay.portal.service.base.CompanyServiceBaseImpl; 029 import com.liferay.portlet.usersadmin.util.UsersAdminUtil; 030 031 import java.io.InputStream; 032 033 import java.util.List; 034 035 /** 036 * The implementation of the company remote service. Each company refers to a 037 * separate portal instance. 038 * 039 * @author Brian Wing Shun Chan 040 * @author Julio Camarero 041 */ 042 public class CompanyServiceImpl extends CompanyServiceBaseImpl { 043 044 /** 045 * Adds a company. 046 * 047 * @param webId the company's web domain 048 * @param virtualHost the company's virtual host name 049 * @param mx the company's mail domain 050 * @param shardName the company's shard 051 * @param system whether the company is the very first company (i.e., the 052 * @param maxUsers the max number of company users (optionally 053 * <code>0</code>) 054 * @param active whether the company is active 055 * @return the company 056 * @throws PortalException if the web domain, virtual host name, or mail 057 * domain was invalid or if the user was not a universal 058 * administrator 059 * @throws SystemException if a system exception occurred 060 */ 061 public Company addCompany( 062 String webId, String virtualHost, String mx, String shardName, 063 boolean system, int maxUsers, boolean active) 064 throws PortalException, SystemException { 065 066 if (!getPermissionChecker().isOmniadmin()) { 067 throw new PrincipalException(); 068 } 069 070 return companyLocalService.addCompany( 071 webId, virtualHost, mx, shardName, system, maxUsers, active); 072 } 073 074 /** 075 * Deletes the company's logo. 076 * 077 * @param companyId the primary key of the company 078 * @throws PortalException if the company with the primary key could not be 079 * found or if the company's logo could not be found or if the user 080 * was not an administrator 081 * @throws SystemException if a system exception occurred 082 */ 083 public void deleteLogo(long companyId) 084 throws PortalException, SystemException { 085 086 if (!roleLocalService.hasUserRole( 087 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) { 088 089 throw new PrincipalException(); 090 } 091 092 companyLocalService.deleteLogo(companyId); 093 } 094 095 /** 096 * Returns the company with the primary key. 097 * 098 * @param companyId the primary key of the company 099 * @return Returns the company with the primary key 100 * @throws PortalException if a company with the primary key could not be 101 * found 102 * @throws SystemException if a system exception occurred 103 */ 104 public Company getCompanyById(long companyId) 105 throws PortalException, SystemException { 106 107 return companyLocalService.getCompanyById(companyId); 108 } 109 110 /** 111 * Returns the company with the logo. 112 * 113 * @param logoId the ID of the company's logo 114 * @return Returns the company with the logo 115 * @throws PortalException if the company with the logo could not be found 116 * @throws SystemException if a system exception occurred 117 */ 118 public Company getCompanyByLogoId(long logoId) 119 throws PortalException, SystemException { 120 121 return companyLocalService.getCompanyByLogoId(logoId); 122 } 123 124 /** 125 * Returns the company with the mail domian. 126 * 127 * @param mx the company's mail domain 128 * @return Returns the company with the mail domain 129 * @throws PortalException if the company with the mail domain could not be 130 * found 131 * @throws SystemException if a system exception occurred 132 */ 133 public Company getCompanyByMx(String mx) 134 throws PortalException, SystemException { 135 136 return companyLocalService.getCompanyByMx(mx); 137 } 138 139 /** 140 * Returns the company with the virtual host name. 141 * 142 * @param virtualHost the company's virtual host name 143 * @return Returns the company with the virtual host name 144 * @throws PortalException if the company with the virtual host name could 145 * not be found or if the virtual host was not associated with a 146 * company 147 * @throws SystemException if a system exception occurred 148 */ 149 public Company getCompanyByVirtualHost(String virtualHost) 150 throws PortalException, SystemException { 151 152 return companyLocalService.getCompanyByVirtualHost(virtualHost); 153 } 154 155 /** 156 * Returns the company with the web domain. 157 * 158 * @param webId the company's web domain 159 * @return Returns the company with the web domain 160 * @throws PortalException if the company with the web domain could not be 161 * found 162 * @throws SystemException if a system exception occurred 163 */ 164 public Company getCompanyByWebId(String webId) 165 throws PortalException, SystemException { 166 167 return companyLocalService.getCompanyByWebId(webId); 168 } 169 170 /** 171 * Removes the values that match the keys of the company's preferences. 172 * 173 * This method is called by {@link 174 * com.liferay.portlet.portalsettings.action.EditLDAPServerAction} remotely 175 * through {@link com.liferay.portal.service.CompanyService}. 176 * 177 * @param companyId the primary key of the company 178 * @param keys the company's preferences keys to be remove 179 * @throws PortalException if the user was not an administrator 180 * @throws SystemException if a system exception occurred 181 */ 182 public void removePreferences(long companyId, String[] keys) 183 throws PortalException, SystemException { 184 185 if (!roleLocalService.hasUserRole( 186 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) { 187 188 throw new PrincipalException(); 189 } 190 191 companyLocalService.removePreferences(companyId, keys); 192 } 193 194 /** 195 * Updates the company 196 * 197 * @param companyId the primary key of the company 198 * @param virtualHost the company's virtual host name 199 * @param mx the company's mail domain 200 * @param maxUsers the max number of company users (optionally 201 * <code>0</code>) 202 * @param active whether the company is active 203 * @return the company with the primary key 204 * @throws PortalException if a company with the primary key could not be 205 * found or if the new information was invalid or if the user was 206 * not a universal administrator 207 * @throws SystemException if a system exception occurred 208 */ 209 public Company updateCompany( 210 long companyId, String virtualHost, String mx, int maxUsers, 211 boolean active) 212 throws PortalException, SystemException { 213 214 if (!getPermissionChecker().isOmniadmin()) { 215 throw new PrincipalException(); 216 } 217 218 return companyLocalService.updateCompany( 219 companyId, virtualHost, mx, maxUsers, active); 220 } 221 222 /** 223 * Updates the company with additional account information. 224 * 225 * @param companyId the primary key of the company 226 * @param virtualHost the company's virtual host name 227 * @param mx the company's mail domain 228 * @param homeURL the company's home URL (optionally <code>null</code>) 229 * @param name the company's account name (optionally <code>null</code>) 230 * @param legalName the company's account legal name (optionally 231 * <code>null</code>) 232 * @param legalId the company's account legal ID (optionally 233 * <code>null</code>) 234 * @param legalType the company's account legal type (optionally 235 * <code>null</code>) 236 * @param sicCode the company's account SIC code (optionally 237 * <code>null</code>) 238 * @param tickerSymbol the company's account ticker symbol (optionally 239 * <code>null</code>) 240 * @param industry the the company's account industry (optionally 241 * <code>null</code>) 242 * @param type the company's account type (optionally <code>null</code>) 243 * @param size the company's account size (optionally <code>null</code>) 244 * @return the the company with the primary key 245 * @throws PortalException if a company with the primary key could not be 246 * found or if the new information was invalid or if the user was 247 * not an administrator 248 * @throws SystemException if a system exception occurred 249 */ 250 public Company updateCompany( 251 long companyId, String virtualHost, String mx, String homeURL, 252 String name, String legalName, String legalId, String legalType, 253 String sicCode, String tickerSymbol, String industry, String type, 254 String size) 255 throws PortalException, SystemException { 256 257 if (!roleLocalService.hasUserRole( 258 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) { 259 260 throw new PrincipalException(); 261 } 262 263 return companyLocalService.updateCompany( 264 companyId, virtualHost, mx, homeURL, name, legalName, legalId, 265 legalType, sicCode, tickerSymbol, industry, type, size); 266 } 267 268 /** 269 * Updates the company with addition information. 270 * 271 * @param companyId the primary key of the company 272 * @param virtualHost the company's virtual host name 273 * @param mx the company's mail domain 274 * @param homeURL the company's home URL (optionally <code>null</code>) 275 * @param name the company's account name (optionally <code>null</code>) 276 * @param legalName the company's account legal name (optionally 277 * <code>null</code>) 278 * @param legalId the company's accout legal ID (optionally 279 * <code>null</code>) 280 * @param legalType the company's account legal type (optionally 281 * <code>null</code>) 282 * @param sicCode the company's account SIC code (optionally 283 * <code>null</code>) 284 * @param tickerSymbol the company's account ticker symbol (optionally 285 * <code>null</code>) 286 * @param industry the the company's account industry (optionally 287 * <code>null</code>) 288 * @param type the company's account type (optionally <code>null</code>) 289 * @param size the company's account size (optionally <code>null</code>) 290 * @param languageId the ID of the company's default user's language 291 * @param timeZoneId the ID of the company's default user's time zone 292 * @param addresses the company's addresses 293 * @param emailAddresses the company's email addresses 294 * @param phones the company's phone numbers 295 * @param websites the company's websites 296 * @param properties the company's properties 297 * @return the company with the primary key 298 * @throws PortalException the company with the primary key could not be 299 * found or if the new information was invalid or if the user was 300 * not an administrator 301 * @throws SystemException if a system exception occurred 302 */ 303 public Company updateCompany( 304 long companyId, String virtualHost, String mx, String homeURL, 305 String name, String legalName, String legalId, String legalType, 306 String sicCode, String tickerSymbol, String industry, String type, 307 String size, String languageId, String timeZoneId, 308 List<Address> addresses, List<EmailAddress> emailAddresses, 309 List<Phone> phones, List<Website> websites, 310 UnicodeProperties properties) 311 throws PortalException, SystemException { 312 313 Company company = updateCompany( 314 companyId, virtualHost, mx, homeURL, name, legalName, legalId, 315 legalType, sicCode, tickerSymbol, industry, type, size); 316 317 updateDisplay(company.getCompanyId(), languageId, timeZoneId); 318 319 updatePreferences(company.getCompanyId(), properties); 320 321 UsersAdminUtil.updateAddresses( 322 Account.class.getName(), company.getAccountId(), addresses); 323 324 UsersAdminUtil.updateEmailAddresses( 325 Account.class.getName(), company.getAccountId(), emailAddresses); 326 327 UsersAdminUtil.updatePhones( 328 Account.class.getName(), company.getAccountId(), phones); 329 330 UsersAdminUtil.updateWebsites( 331 Account.class.getName(), company.getAccountId(), websites); 332 333 return company; 334 } 335 336 /** 337 * Update the company's display. 338 * 339 * @param companyId the primary key of the company 340 * @param languageId the ID of the company's default user's language 341 * @param timeZoneId the ID of the company's default user's time zone 342 * @throws PortalException if the company's default user could not be found 343 * or if the user was not an administrator 344 * @throws SystemException if a system exception occurred 345 */ 346 public void updateDisplay( 347 long companyId, String languageId, String timeZoneId) 348 throws PortalException, SystemException { 349 350 if (!roleLocalService.hasUserRole( 351 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) { 352 353 throw new PrincipalException(); 354 } 355 356 companyLocalService.updateDisplay(companyId, languageId, timeZoneId); 357 } 358 359 /** 360 * Updates the company's logo. 361 * 362 * @param companyId the primary key of the company 363 * @param inputStream the input stream of the company's logo image 364 * @throws PortalException if the company's logo ID could not be found or 365 * if the logo's image was corrupted or if the user was an 366 * administrator 367 * @throws SystemException if a system exception occurred 368 */ 369 public void updateLogo(long companyId, InputStream inputStream) 370 throws PortalException, SystemException { 371 372 if (!roleLocalService.hasUserRole( 373 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) { 374 375 throw new PrincipalException(); 376 } 377 378 companyLocalService.updateLogo(companyId, inputStream); 379 } 380 381 /** 382 * Updates the company's preferences. The company's default properties are 383 * found in portal.properties. 384 * 385 * @param companyId the primary key of the company 386 * @param properties the company's properties. See {@link 387 * com.liferay.portal.kernel.util.UnicodeProperties} 388 * @throws PortalException if the user was not an administrator 389 * @throws SystemException if a system exception occurred 390 */ 391 public void updatePreferences(long companyId, UnicodeProperties properties) 392 throws PortalException, SystemException { 393 394 if (!roleLocalService.hasUserRole( 395 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) { 396 397 throw new PrincipalException(); 398 } 399 400 companyLocalService.updatePreferences(companyId, properties); 401 } 402 403 /** 404 * Updates the company's security properties. 405 * 406 * @param companyId the primary key of the company 407 * @param authType the company's method of authenticating users 408 * @param autoLogin whether to allow users to select the "remember me" 409 * feature 410 * @param sendPassword whether to allow users to ask the company to send 411 * their passwords 412 * @param strangers whether to allow strangers to create accounts to 413 * register themselves in the company 414 * @param strangersWithMx whether to allow strangers to create accounts 415 * with email addresses that match the company mail suffix 416 * @param strangersVerify whether to require strangers who create accounts 417 * to be verified via email 418 * @param siteLogo whether to to allow site administrators to use their 419 * own logo instead of the enterprise logo 420 * @throws PortalException if the user was not an administrator 421 * @throws SystemException if a system exception occurred 422 */ 423 public void updateSecurity( 424 long companyId, String authType, boolean autoLogin, 425 boolean sendPassword, boolean strangers, boolean strangersWithMx, 426 boolean strangersVerify, boolean siteLogo) 427 throws PortalException, SystemException { 428 429 if (!roleLocalService.hasUserRole( 430 getUserId(), companyId, RoleConstants.ADMINISTRATOR, true)) { 431 432 throw new PrincipalException(); 433 } 434 435 companyLocalService.updateSecurity( 436 companyId, authType, autoLogin, sendPassword, strangers, 437 strangersWithMx, strangersVerify, siteLogo); 438 } 439 440 }