示例#1
0
 public void postSave(User user, boolean isNew) throws Exception {
   ExoContainer pcontainer = ExoContainerContext.getCurrentContainer();
   OrganizationService service =
       (OrganizationService) pcontainer.getComponentInstanceOfType(OrganizationService.class);
   UserProfile up = service.getUserProfileHandler().createUserProfileInstance();
   up.setUserName(user.getUserName());
   service.getUserProfileHandler().saveUserProfile(up, false);
   if (config_ == null) return;
   if (isNew && !config_.isIgnoreUser(user.getUserName())) {
     createDefaultUserMemberships(user, service);
   }
 }
  /**
   * The constructor of this class is used to build the tree of UI components that will be
   * aggregated in the portal page. 1) The component is stored in the current PortalRequestContext
   * ThreadLocal 2) The configuration for the portal associated with the current user request is
   * extracted from the PortalRequestContext 3) Then according to the context path, either a public
   * or private portal is initiated. Usually a public portal does not contain the left column and
   * only the private one has it. 4) The skin to use is setup 5) Finally, the current component is
   * associated with the current portal owner
   *
   * @throws Exception
   */
  public UIPortalApplication() throws Exception {
    log = ExoLogger.getLogger("portal:UIPortalApplication");
    PortalRequestContext context = PortalRequestContext.getCurrentInstance();
    userPortalConfig_ = (UserPortalConfig) context.getAttribute(UserPortalConfig.class);
    if (userPortalConfig_ == null) throw new Exception("Can't load user portal config");

    // dang.tung - set portal language by user preference -> browser -> default
    // ------------------------------------------------------------------------------
    String portalLanguage = null;
    LocaleConfigService localeConfigService = getApplicationComponent(LocaleConfigService.class);
    OrganizationService orgService = getApplicationComponent(OrganizationService.class);
    LocaleConfig localeConfig =
        localeConfigService.getLocaleConfig(userPortalConfig_.getPortalConfig().getLocale());
    String user = context.getRemoteUser();
    if (user != null) {
      UserProfile userProfile = orgService.getUserProfileHandler().findUserProfileByName(user);
      if (userProfile != null) {
        portalLanguage = userProfile.getUserInfoMap().get("user.language");
      } else {
        if (log.isWarnEnabled())
          log.warn("Could not load user profile for " + user + ". Using default portal locale.");
      }
    }
    localeConfig = localeConfigService.getLocaleConfig(portalLanguage);
    if (portalLanguage == null || !portalLanguage.equals(localeConfig.getLanguage())) {
      // if user language no support by portal -> get browser language if no ->
      // get portal
      portalLanguage = context.getRequest().getLocale().getLanguage();
      localeConfig = localeConfigService.getLocaleConfig(portalLanguage);
      if (!portalLanguage.equals(localeConfig.getLanguage())) {
        localeConfig =
            localeConfigService.getLocaleConfig(userPortalConfig_.getPortalConfig().getLocale());
      }
    }
    setLocale(localeConfig.getLocale());
    setOrientation(localeConfig.getOrientation());
    // -------------------------------------------------------------------------------
    context.setUIApplication(this);

    addWorkingWorkspace();

    String currentSkin = userPortalConfig_.getPortalConfig().getSkin();
    if (currentSkin != null && currentSkin.trim().length() > 0) skin_ = currentSkin;
    setOwner(context.getPortalOwner());
  }
  /**
   * Retrieve the forum contact information from and user business profile.<br>
   * Email, city, country, mobile, phone and website are taken from {@link
   * UserProfile#BUSINESE_INFO_KEYS}.
   */
  public CommonContact getCommonContact(String userId) {
    CommonContact contact = new CommonContact();
    try {
      UserProfile profile = orgService.getUserProfileHandler().findUserProfileByName(userId);

      contact.setAvatarUrl(profile.getAttribute("user.other-info.avatar.url"));
      contact.setBirthday(profile.getAttribute("user.bdate"));
      contact.setGender(profile.getAttribute("user.gender"));
      contact.setJob(profile.getAttribute("user.jobtitle"));

      contact.setEmailAddress(profile.getAttribute("user.business-info.online.email"));
      contact.setCity(profile.getAttribute("user.business-info.postal.city"));
      contact.setCountry(profile.getAttribute("user.business-info.postal.country"));
      contact.setHomePhone(profile.getAttribute("user.business-info.telecom.mobile.number"));
      contact.setWorkPhone(profile.getAttribute("user.business-info.telecom.telephone.number"));
      contact.setWebSite(profile.getAttribute("user.business-info.online.uri"));

    } catch (Exception e) {
      log.error("Could not retrieve forum user profile for " + userId + ": ", e);
    }
    return contact;
  }