@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;
  }
  public static PortalPreferencesSoap toSoapModel(PortalPreferences model) {
    PortalPreferencesSoap soapModel = new PortalPreferencesSoap();

    soapModel.setMvccVersion(model.getMvccVersion());
    soapModel.setPortalPreferencesId(model.getPortalPreferencesId());
    soapModel.setOwnerId(model.getOwnerId());
    soapModel.setOwnerType(model.getOwnerType());
    soapModel.setPreferences(model.getPreferences());

    return soapModel;
  }