protected String getTitle(AssetVocabulary assetVocabulary) {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    String title = assetVocabulary.getTitle(themeDisplay.getLanguageId());

    if (assetVocabulary.getGroupId() == themeDisplay.getCompanyGroupId()) {
      title += " (" + LanguageUtil.get(_request, "global") + ")";
    }

    return title;
  }
  protected Properties getProperties(
      ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {

    Properties properties = new Properties();

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

    Map<String, ConfigurationModel> configurationModels =
        _configurationModelRetriever.getConfigurationModels(themeDisplay.getLanguageId());

    String factoryPid = ParamUtil.getString(resourceRequest, "factoryPid");
    String pid = ParamUtil.getString(resourceRequest, "pid");

    ConfigurationModel configurationModel = configurationModels.get(pid);

    if ((configurationModel == null) && Validator.isNotNull(factoryPid)) {
      configurationModel = configurationModels.get(factoryPid);
    }

    if (configurationModel == null) {
      return properties;
    }

    Configuration configuration = _configurationModelRetriever.getConfiguration(pid);

    if (configuration == null) {
      return properties;
    }

    ExtendedAttributeDefinition[] attributeDefinitions =
        configurationModel.getAttributeDefinitions(ConfigurationModel.ALL);

    for (AttributeDefinition attributeDefinition : attributeDefinitions) {
      String[] values = AttributeDefinitionUtil.getProperty(attributeDefinition, configuration);

      String value = null;

      // See http://goo.gl/JhYK7g

      if (values.length == 1) {
        value = values[0];
      } else if (values.length > 1) {
        value = StringUtil.merge(values, "\n");
      }

      properties.setProperty(attributeDefinition.getID(), value);
    }

    return properties;
  }
Exemplo n.º 3
0
  private static void _updateAdminUser(
      HttpServletRequest request, UnicodeProperties unicodeProperties) throws Exception {

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

    Company company = CompanyLocalServiceUtil.getCompanyById(themeDisplay.getCompanyId());

    String emailAddress =
        ParamUtil.getString(
            request,
            "adminEmailAddress",
            PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX + StringPool.AT + company.getMx());

    PropsValues.ADMIN_EMAIL_FROM_ADDRESS = emailAddress;

    unicodeProperties.put(PropsKeys.ADMIN_EMAIL_FROM_ADDRESS, emailAddress);

    ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();

    String screenName =
        GetterUtil.getString(PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX, "test");

    try {
      screenName = screenNameGenerator.generate(0, 0, emailAddress);
    } catch (Exception e) {
    }

    String firstName =
        ParamUtil.getString(request, "adminFirstName", PropsValues.DEFAULT_ADMIN_FIRST_NAME);
    String lastName =
        ParamUtil.getString(request, "adminLastName", PropsValues.DEFAULT_ADMIN_LAST_NAME);

    FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

    String fullName = fullNameGenerator.getFullName(firstName, null, lastName);

    PropsValues.ADMIN_EMAIL_FROM_NAME = fullName;

    unicodeProperties.put(PropsKeys.ADMIN_EMAIL_FROM_NAME, fullName);

    User user = null;

    try {
      user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

      String greeting =
          LanguageUtil.format(
              themeDisplay.getLocale(), "welcome-x", StringPool.SPACE + fullName, false);

      Contact contact = user.getContact();

      Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

      birthdayCal.setTime(contact.getBirthday());

      int birthdayMonth = birthdayCal.get(Calendar.MONTH);
      int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
      int birthdayYear = birthdayCal.get(Calendar.YEAR);

      user =
          UserLocalServiceUtil.updateUser(
              user.getUserId(),
              StringPool.BLANK,
              StringPool.BLANK,
              StringPool.BLANK,
              false,
              user.getReminderQueryQuestion(),
              user.getReminderQueryAnswer(),
              screenName,
              emailAddress,
              user.getFacebookId(),
              user.getOpenId(),
              themeDisplay.getLanguageId(),
              user.getTimeZoneId(),
              greeting,
              user.getComments(),
              firstName,
              user.getMiddleName(),
              lastName,
              contact.getPrefixId(),
              contact.getSuffixId(),
              contact.isMale(),
              birthdayMonth,
              birthdayDay,
              birthdayYear,
              contact.getSmsSn(),
              contact.getAimSn(),
              contact.getFacebookSn(),
              contact.getIcqSn(),
              contact.getJabberSn(),
              contact.getMsnSn(),
              contact.getMySpaceSn(),
              contact.getSkypeSn(),
              contact.getTwitterSn(),
              contact.getYmSn(),
              contact.getJobTitle(),
              null,
              null,
              null,
              null,
              null,
              new ServiceContext());
    } catch (NoSuchUserException nsue) {
      UserLocalServiceUtil.addDefaultAdminUser(
          themeDisplay.getCompanyId(),
          screenName,
          emailAddress,
          themeDisplay.getLocale(),
          firstName,
          StringPool.BLANK,
          lastName);

      user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

      String defaultAdminEmailAddress =
          PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX + "@" + PropsValues.COMPANY_DEFAULT_WEB_ID;

      if (!emailAddress.equals(defaultAdminEmailAddress)) {
        User testUser =
            UserLocalServiceUtil.fetchUserByEmailAddress(
                themeDisplay.getCompanyId(), defaultAdminEmailAddress);

        if (testUser != null) {
          UserLocalServiceUtil.updateStatus(
              testUser.getUserId(), WorkflowConstants.STATUS_INACTIVE);
        }
      }
    }

    user = UserLocalServiceUtil.updatePasswordReset(user.getUserId(), true);

    HttpSession session = request.getSession();

    session.setAttribute(WebKeys.EMAIL_ADDRESS, emailAddress);
    session.setAttribute(WebKeys.SETUP_WIZARD_PASSWORD_UPDATED, true);
    session.setAttribute(WebKeys.USER_ID, user.getUserId());
  }
Exemplo n.º 4
0
  public static void copyPreferences(
      HttpServletRequest request, Layout targetLayout, Layout sourceLayout) throws Exception {

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

    LayoutTypePortlet sourceLayoutTypePortlet = (LayoutTypePortlet) sourceLayout.getLayoutType();

    List<String> sourcePortletIds = sourceLayoutTypePortlet.getPortletIds();

    for (String sourcePortletId : sourcePortletIds) {

      // Copy preference

      PortletPreferencesIds portletPreferencesIds =
          PortletPreferencesFactoryUtil.getPortletPreferencesIds(
              request, targetLayout, sourcePortletId);

      PortletPreferencesLocalServiceUtil.getPreferences(portletPreferencesIds);

      PortletPreferencesIds sourcePortletPreferencesIds =
          PortletPreferencesFactoryUtil.getPortletPreferencesIds(
              request, sourceLayout, sourcePortletId);

      PortletPreferences sourcePreferences =
          PortletPreferencesLocalServiceUtil.getPreferences(sourcePortletPreferencesIds);

      PortletPreferencesLocalServiceUtil.updatePreferences(
          portletPreferencesIds.getOwnerId(),
          portletPreferencesIds.getOwnerType(),
          portletPreferencesIds.getPlid(),
          portletPreferencesIds.getPortletId(),
          sourcePreferences);

      // Copy portlet setup

      PortletPreferences targetPreferences =
          PortletPreferencesLocalServiceUtil.getPreferences(
              themeDisplay.getCompanyId(),
              PortletKeys.PREFS_OWNER_ID_DEFAULT,
              PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
              targetLayout.getPlid(),
              sourcePortletId);

      sourcePreferences =
          PortletPreferencesLocalServiceUtil.getPreferences(
              themeDisplay.getCompanyId(),
              PortletKeys.PREFS_OWNER_ID_DEFAULT,
              PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
              sourceLayout.getPlid(),
              sourcePortletId);

      PortletPreferencesLocalServiceUtil.updatePreferences(
          PortletKeys.PREFS_OWNER_ID_DEFAULT,
          PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
          targetLayout.getPlid(),
          sourcePortletId,
          sourcePreferences);

      SitesUtil.updateLayoutScopes(
          themeDisplay.getUserId(),
          sourceLayout,
          targetLayout,
          sourcePreferences,
          targetPreferences,
          sourcePortletId,
          themeDisplay.getLanguageId());

      Portlet sourcePortlet =
          PortletLocalServiceUtil.getPortletById(sourceLayout.getCompanyId(), sourcePortletId);

      PortletLayoutListener sourcePortletLayoutListener =
          sourcePortlet.getPortletLayoutListenerInstance();

      if (sourcePortletLayoutListener != null) {
        sourcePortletLayoutListener.onAddToLayout(sourcePortletId, targetLayout.getPlid());
      }
    }
  }