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