@Override
  public Account updateImpl(com.liferay.portal.model.Account account) throws SystemException {
    account = toUnwrappedModel(account);

    boolean isNew = account.isNew();

    Session session = null;

    try {
      session = openSession();

      if (account.isNew()) {
        session.save(account);

        account.setNew(false);
      } else {
        session.merge(account);
      }
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (isNew) {
      FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    EntityCacheUtil.putResult(
        AccountModelImpl.ENTITY_CACHE_ENABLED, AccountImpl.class, account.getPrimaryKey(), account);

    return account;
  }
예제 #2
0
  private static void _updateCompany(HttpServletRequest request) throws Exception {

    Company company = CompanyLocalServiceUtil.getCompanyById(PortalInstances.getDefaultCompanyId());

    Account account = company.getAccount();

    String currentName = account.getName();

    String newName = ParamUtil.getString(request, "companyName", PropsValues.COMPANY_DEFAULT_NAME);

    if (!currentName.equals(newName)) {
      account.setName(newName);

      AccountLocalServiceUtil.updateAccount(account);
    }

    String languageId =
        ParamUtil.getString(request, "companyLocale", PropsValues.COMPANY_DEFAULT_LOCALE);

    User defaultUser = company.getDefaultUser();

    defaultUser.setLanguageId(languageId);

    UserLocalServiceUtil.updateUser(defaultUser);

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    themeDisplay.setCompany(company);
  }
  /**
   * Creates a new account with the primary key. Does not add the account to the database.
   *
   * @param accountId the primary key for the new account
   * @return the new account
   */
  public Account create(long accountId) {
    Account account = new AccountImpl();

    account.setNew(true);
    account.setPrimaryKey(accountId);

    return account;
  }
  @Override
  public void clearCache(List<Account> accounts) {
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

    for (Account account : accounts) {
      EntityCacheUtil.removeResult(
          AccountModelImpl.ENTITY_CACHE_ENABLED, AccountImpl.class, account.getPrimaryKey());
    }
  }
 /**
  * Caches the accounts in the entity cache if it is enabled.
  *
  * @param accounts the accounts
  */
 public void cacheResult(List<Account> accounts) {
   for (Account account : accounts) {
     if (EntityCacheUtil.getResult(
             AccountModelImpl.ENTITY_CACHE_ENABLED, AccountImpl.class, account.getPrimaryKey())
         == null) {
       cacheResult(account);
     } else {
       account.resetOriginalValues();
     }
   }
 }
  @Override
  protected Account removeImpl(Account account) throws SystemException {
    account = toUnwrappedModel(account);

    Session session = null;

    try {
      session = openSession();

      if (!session.contains(account)) {
        account = (Account) session.get(AccountImpl.class, account.getPrimaryKeyObj());
      }

      if (account != null) {
        session.delete(account);
      }
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);
    }

    if (account != null) {
      clearCache(account);
    }

    return account;
  }
  public int compareTo(Account account) {
    long primaryKey = account.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    Account account = null;

    try {
      account = (Account) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = account.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static Account toModel(AccountSoap soapModel) {
    Account model = new AccountImpl();

    model.setAccountId(soapModel.getAccountId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setParentAccountId(soapModel.getParentAccountId());
    model.setName(soapModel.getName());
    model.setLegalName(soapModel.getLegalName());
    model.setLegalId(soapModel.getLegalId());
    model.setLegalType(soapModel.getLegalType());
    model.setSicCode(soapModel.getSicCode());
    model.setTickerSymbol(soapModel.getTickerSymbol());
    model.setIndustry(soapModel.getIndustry());
    model.setType(soapModel.getType());
    model.setSize(soapModel.getSize());

    return model;
  }
예제 #10
0
  @Override
  public String getDescriptiveName(Locale locale) throws PortalException {
    Group curGroup = this;

    String name = getName(locale);

    if (Validator.isNull(name)) {
      Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(getGroupId());

      name = getName(siteDefaultLocale);
    }

    if (isCompany() && !isCompanyStagingGroup()) {
      name = LanguageUtil.get(locale, "global");
    } else if (isControlPanel()) {
      name = LanguageUtil.get(locale, "control-panel");
    } else if (isGuest()) {
      Company company = CompanyLocalServiceUtil.getCompany(getCompanyId());

      Account account = company.getAccount();

      name = account.getName();
    } else if (isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(getClassPK());

      name = layout.getName(locale);
    } else if (isLayoutPrototype()) {
      LayoutPrototype layoutPrototype =
          LayoutPrototypeLocalServiceUtil.getLayoutPrototype(getClassPK());

      name = layoutPrototype.getName(locale);
    } else if (isLayoutSetPrototype()) {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(getClassPK());

      name = layoutSetPrototype.getName(locale);
    } else if (isOrganization()) {
      long organizationId = getOrganizationId();

      Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

      name = organization.getName();

      curGroup = organization.getGroup();
    } else if (isUser()) {
      long userId = getClassPK();

      User user = UserLocalServiceUtil.getUser(userId);

      name = user.getFullName();
    } else if (isUserGroup()) {
      long userGroupId = getClassPK();

      UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(userGroupId);

      name = userGroup.getName();
    } else if (isUserPersonalSite()) {
      name = LanguageUtil.get(locale, "user-personal-site");
    }

    if (curGroup.isStaged() && !curGroup.isStagedRemotely() && curGroup.isStagingGroup()) {

      Group liveGroup = getLiveGroup();

      name = liveGroup.getDescriptiveName(locale);
    }

    return name;
  }
  /**
   * Caches the account in the entity cache if it is enabled.
   *
   * @param account the account
   */
  public void cacheResult(Account account) {
    EntityCacheUtil.putResult(
        AccountModelImpl.ENTITY_CACHE_ENABLED, AccountImpl.class, account.getPrimaryKey(), account);

    account.resetOriginalValues();
  }
  protected Account toUnwrappedModel(Account account) {
    if (account instanceof AccountImpl) {
      return account;
    }

    AccountImpl accountImpl = new AccountImpl();

    accountImpl.setNew(account.isNew());
    accountImpl.setPrimaryKey(account.getPrimaryKey());

    accountImpl.setAccountId(account.getAccountId());
    accountImpl.setCompanyId(account.getCompanyId());
    accountImpl.setUserId(account.getUserId());
    accountImpl.setUserName(account.getUserName());
    accountImpl.setCreateDate(account.getCreateDate());
    accountImpl.setModifiedDate(account.getModifiedDate());
    accountImpl.setParentAccountId(account.getParentAccountId());
    accountImpl.setName(account.getName());
    accountImpl.setLegalName(account.getLegalName());
    accountImpl.setLegalId(account.getLegalId());
    accountImpl.setLegalType(account.getLegalType());
    accountImpl.setSicCode(account.getSicCode());
    accountImpl.setTickerSymbol(account.getTickerSymbol());
    accountImpl.setIndustry(account.getIndustry());
    accountImpl.setType(account.getType());
    accountImpl.setSize(account.getSize());

    return accountImpl;
  }