@Override
  public PortalPreferences getPortalPreferences(
      HttpSession session, long userId, boolean signedIn) {

    long ownerId = userId;
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_USER;

    PortalPreferences portalPreferences = null;

    if (signedIn) {
      PortalPreferencesWrapper portalPreferencesWrapper =
          PortalPreferencesWrapperCacheUtil.get(ownerId, ownerType);

      if (portalPreferencesWrapper == null) {
        portalPreferencesWrapper =
            (PortalPreferencesWrapper)
                PortalPreferencesLocalServiceUtil.getPreferences(ownerId, ownerType);

        portalPreferences = portalPreferencesWrapper.getPortalPreferencesImpl();
      } else {
        PortalPreferencesImpl portalPreferencesImpl =
            portalPreferencesWrapper.getPortalPreferencesImpl();

        portalPreferences = portalPreferencesImpl.clone();
      }
    } else {
      if (session != null) {
        portalPreferences = (PortalPreferences) session.getAttribute(WebKeys.PORTAL_PREFERENCES);
      }

      if (portalPreferences == null) {
        PortalPreferencesWrapper portalPreferencesWrapper =
            PortalPreferencesWrapperCacheUtil.get(ownerId, ownerType);

        if (portalPreferencesWrapper == null) {
          portalPreferencesWrapper =
              (PortalPreferencesWrapper)
                  PortalPreferencesLocalServiceUtil.getPreferences(ownerId, ownerType);

          portalPreferences = portalPreferencesWrapper.getPortalPreferencesImpl();
        } else {
          PortalPreferencesImpl portalPreferencesImpl =
              portalPreferencesWrapper.getPortalPreferencesImpl();

          portalPreferences = portalPreferencesImpl.clone();
        }

        if (session != null) {
          session.setAttribute(WebKeys.PORTAL_PREFERENCES, portalPreferences);
        }
      }
    }

    portalPreferences.setSignedIn(signedIn);
    portalPreferences.setUserId(userId);

    return portalPreferences;
  }
 protected PortletPreferences getPortalPreferences(long companyId) {
   return PortalPreferencesLocalServiceUtil.getPreferences(
       companyId, PortletKeys.PREFS_OWNER_TYPE_COMPANY);
 }