Beispiel #1
0
  protected Field createField(
      DDMStructure ddmStructure,
      String fieldName,
      List<Serializable> fieldValues,
      ServiceContext serviceContext) {

    Field field = new Field();

    field.setDDMStructureId(ddmStructure.getStructureId());

    String languageId =
        GetterUtil.getString(
            serviceContext.getAttribute("languageId"), serviceContext.getLanguageId());

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    String defaultLanguageId =
        GetterUtil.getString(serviceContext.getAttribute("defaultLanguageId"));

    Locale defaultLocale = LocaleUtil.fromLanguageId(defaultLanguageId);

    if (fieldName.startsWith(StringPool.UNDERLINE)) {
      locale = LocaleUtil.getSiteDefault();

      defaultLocale = LocaleUtil.getSiteDefault();
    }

    field.setDefaultLocale(defaultLocale);

    field.setName(fieldName);
    field.setValues(locale, fieldValues);

    return field;
  }
  protected Map<Locale, String> getDefaultLocaleMap(String value) {
    Map<Locale, String> map = new HashMap<>();

    map.put(LocaleUtil.getSiteDefault(), value);

    return map;
  }
  @Override
  public AssetCategory addCategory(
      long userId, long groupId, String title, long vocabularyId, ServiceContext serviceContext)
      throws PortalException {

    Map<Locale, String> titleMap = new HashMap<>();

    Locale locale = LocaleUtil.getSiteDefault();

    titleMap.put(locale, title);

    Map<Locale, String> descriptionMap = new HashMap<>();

    descriptionMap.put(locale, StringPool.BLANK);

    return assetCategoryLocalService.addCategory(
        userId,
        groupId,
        AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID,
        titleMap,
        descriptionMap,
        vocabularyId,
        null,
        serviceContext);
  }
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public AssetVocabulary updateVocabulary(
      long vocabularyId,
      String title,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      String settings,
      ServiceContext serviceContext)
      throws PortalException {

    String name = titleMap.get(LocaleUtil.getSiteDefault());

    AssetVocabulary vocabulary = assetVocabularyPersistence.findByPrimaryKey(vocabularyId);

    if (!vocabulary.getName().equals(name)) {
      validate(vocabulary.getGroupId(), name);
    }

    vocabulary.setName(name);
    vocabulary.setTitleMap(titleMap);

    if (Validator.isNotNull(title)) {
      vocabulary.setTitle(title);
    }

    vocabulary.setDescriptionMap(descriptionMap);
    vocabulary.setSettings(settings);

    assetVocabularyPersistence.update(vocabulary);

    return vocabulary;
  }
  @Override
  public AssetEntry getAssetEntry(String className, long classPK) throws PortalException {

    LayoutRevision layoutRevision = _layoutRevisionLocalService.getLayoutRevision(classPK);

    LayoutSetBranch layoutSetBranch =
        _layoutSetBranchLocalService.getLayoutSetBranch(layoutRevision.getLayoutSetBranchId());

    User user = _userLocalService.getUserById(layoutRevision.getUserId());

    AssetEntry assetEntry = _assetEntryLocalService.createAssetEntry(classPK);

    assetEntry.setGroupId(layoutRevision.getGroupId());
    assetEntry.setCompanyId(user.getCompanyId());
    assetEntry.setUserId(user.getUserId());
    assetEntry.setUserName(user.getFullName());
    assetEntry.setCreateDate(layoutRevision.getCreateDate());
    assetEntry.setClassNameId(PortalUtil.getClassNameId(LayoutRevision.class.getName()));
    assetEntry.setClassPK(layoutRevision.getLayoutRevisionId());

    StringBundler sb = new StringBundler(4);

    sb.append(layoutRevision.getHTMLTitle(LocaleUtil.getSiteDefault()));
    sb.append(" [");
    sb.append(layoutSetBranch.getName());
    sb.append("]");

    assetEntry.setTitle(sb.toString());

    return assetEntry;
  }
  @Override
  public Locale getLocale() {
    if (_locale == null) {
      _locale = LocaleUtil.getSiteDefault();
    }

    return _locale;
  }
  protected Locale getDefaultLocale(HttpServletRequest httpServletRequest) {
    String defaultLanguageId = ParamUtil.getString(httpServletRequest, "defaultLanguageId");

    if (Validator.isNull(defaultLanguageId)) {
      return LocaleUtil.getSiteDefault();
    }

    return LocaleUtil.fromLanguageId(defaultLanguageId);
  }
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public AssetVocabulary addVocabulary(
      long userId,
      long groupId,
      String title,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      String settings,
      ServiceContext serviceContext)
      throws PortalException {

    // Vocabulary

    User user = userPersistence.findByPrimaryKey(userId);
    String name = titleMap.get(LocaleUtil.getSiteDefault());

    validate(groupId, name);

    long vocabularyId = counterLocalService.increment();

    AssetVocabulary vocabulary = assetVocabularyPersistence.create(vocabularyId);

    vocabulary.setUuid(serviceContext.getUuid());
    vocabulary.setGroupId(groupId);
    vocabulary.setCompanyId(user.getCompanyId());
    vocabulary.setUserId(user.getUserId());
    vocabulary.setUserName(user.getFullName());
    vocabulary.setName(name);

    if (Validator.isNotNull(title)) {
      vocabulary.setTitle(title);
    } else {
      vocabulary.setTitleMap(titleMap);
    }

    vocabulary.setDescriptionMap(descriptionMap);
    vocabulary.setSettings(settings);

    assetVocabularyPersistence.update(vocabulary);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

      addVocabularyResources(
          vocabulary,
          serviceContext.isAddGroupPermissions(),
          serviceContext.isAddGuestPermissions());
    } else {
      addVocabularyResources(
          vocabulary, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return vocabulary;
  }
  @Override
  public String getDefaultLanguageId() {
    String xml = getTitle();

    if (xml == null) {
      return StringPool.BLANK;
    }

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    return LocalizationUtil.getDefaultLanguageId(xml, defaultLocale);
  }
  @Override
  public void updateFileEntryType(
      long userId,
      long fileEntryTypeId,
      String name,
      String description,
      long[] ddmStructureIds,
      ServiceContext serviceContext)
      throws PortalException {

    Map<Locale, String> nameMap = new HashMap<>();

    nameMap.put(LocaleUtil.getSiteDefault(), name);

    Map<Locale, String> descriptionMap = new HashMap<>();

    descriptionMap.put(LocaleUtil.getSiteDefault(), description);

    updateFileEntryType(
        userId, fileEntryTypeId, nameMap, descriptionMap, ddmStructureIds, serviceContext);
  }
  @Before
  @Override
  public void setUp() throws Exception {
    super.setUp();

    SimpleAction simpleAction = new AddDefaultDocumentLibraryStructuresAction();

    String companyIdString = String.valueOf(TestPropsValues.getCompanyId());

    simpleAction.run(new String[] {companyIdString});

    List<DLFileEntryType> dlFileEntryTypes =
        DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(
            PortalUtil.getCurrentAndAncestorSiteGroupIds(group.getGroupId()));

    for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
      String name = dlFileEntryType.getName(LocaleUtil.getSiteDefault());

      if (name.equals(DLFileEntryTypeConstants.NAME_CONTRACT)) {
        _contractDLFileEntryTypeId = dlFileEntryType.getFileEntryTypeId();
      }
    }

    ExpandoTable expandoTable =
        ExpandoTableLocalServiceUtil.addDefaultTable(
            PortalUtil.getDefaultCompanyId(), DLFileEntry.class.getName());

    ExpandoColumnLocalServiceUtil.addColumn(
        expandoTable.getTableId(),
        _EXPANDO_ATTRIBUTE_NAME,
        ExpandoColumnConstants.STRING,
        StringPool.BLANK);

    _serviceContext = getServiceContext();

    FileEntry fileEntry =
        DLAppServiceUtil.addFileEntry(
            group.getGroupId(),
            parentFolder.getFolderId(),
            _SOURCE_FILE_NAME,
            ContentTypes.APPLICATION_OCTET_STREAM,
            _TITLE,
            StringPool.BLANK,
            StringPool.BLANK,
            _DATA_VERSION_1,
            _serviceContext);

    _fileVersion =
        DLFileVersionLocalServiceUtil.getFileVersion(
            fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT);
  }
  @Override
  public String getDefaultLanguageId() {
    Document document = getDocument();

    if (document == null) {
      Locale locale = LocaleUtil.getSiteDefault();

      return locale.toString();
    }

    Element rootElement = document.getRootElement();

    return rootElement.attributeValue("default-locale");
  }
  @Override
  @SuppressWarnings("unused")
  public void prepareLocalizedFieldsForImport(Locale defaultImportLocale) throws LocaleException {
    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String modelDefaultLanguageId = getDefaultLanguageId();

    String title = getTitle(defaultLocale);

    if (Validator.isNull(title)) {
      setTitle(getTitle(modelDefaultLanguageId), defaultLocale);
    } else {
      setTitle(getTitle(defaultLocale), defaultLocale, defaultLocale);
    }
  }
  protected Set<Locale> getAvailableLocales(String[] availableLanguageIds) {
    Set<Locale> availableLocales = new HashSet<>();

    for (String availableLanguageId : availableLanguageIds) {
      Locale availableLocale = LocaleUtil.fromLanguageId(availableLanguageId);

      availableLocales.add(availableLocale);
    }

    if (availableLocales.isEmpty()) {
      availableLocales.add(LocaleUtil.getSiteDefault());
    }

    return availableLocales;
  }
  @Before
  public void setUp() throws Exception {
    SimpleAction simpleAction = new AddDefaultDocumentLibraryStructuresAction();

    String companyIdString = String.valueOf(TestPropsValues.getCompanyId());

    simpleAction.run(new String[] {companyIdString});

    _group = GroupTestUtil.addGroup();

    _folder =
        DLAppLocalServiceUtil.addFolder(
            TestPropsValues.getUserId(),
            _group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            "Folder A",
            "",
            ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

    _subfolder =
        DLAppLocalServiceUtil.addFolder(
            TestPropsValues.getUserId(),
            _group.getGroupId(),
            _folder.getFolderId(),
            "SubFolder AA",
            "",
            ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

    _basicDocumentDLFileEntryType =
        DLFileEntryTypeLocalServiceUtil.getFileEntryType(
            DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT);

    _dlFileEntryTypes =
        DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(
            PortalUtil.getCurrentAndAncestorSiteGroupIds(_group.getGroupId()));

    for (DLFileEntryType dlFileEntryType : _dlFileEntryTypes) {
      String name = dlFileEntryType.getName(LocaleUtil.getSiteDefault());

      if (name.equals(DLFileEntryTypeConstants.NAME_CONTRACT)) {
        _contractDLFileEntryType = dlFileEntryType;
      } else if (name.equals(DLFileEntryTypeConstants.NAME_MARKETING_BANNER)) {

        _marketingBannerDLFileEntryType = dlFileEntryType;
      }
    }
  }
Beispiel #16
0
  protected void visitLayout(Element element, Layout layout, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    if (!PortalUtil.isLayoutSitemapable(layout)
        || !GetterUtil.getBoolean(typeSettingsProperties.getProperty("sitemap-include"), true)) {

      return;
    }

    String layoutFullURL = PortalUtil.getLayoutFullURL(layout, themeDisplay);

    layoutFullURL = PortalUtil.getCanonicalURL(layoutFullURL, themeDisplay, layout);

    addURLElement(
        element,
        layoutFullURL,
        typeSettingsProperties,
        layout.getModifiedDate(),
        layoutFullURL,
        getAlternateURLs(layoutFullURL, themeDisplay, layout));

    Locale[] availableLocales = LanguageUtil.getAvailableLocales(layout.getGroupId());

    if (availableLocales.length > 1) {
      Locale defaultLocale = LocaleUtil.getSiteDefault();

      for (Locale availableLocale : availableLocales) {
        if (availableLocale.equals(defaultLocale)) {
          continue;
        }

        String alternateURL =
            PortalUtil.getAlternateURL(layoutFullURL, themeDisplay, availableLocale, layout);

        addURLElement(
            element,
            alternateURL,
            typeSettingsProperties,
            layout.getModifiedDate(),
            layoutFullURL,
            getAlternateURLs(layoutFullURL, themeDisplay, layout));
      }
    }
  }
Beispiel #17
0
  public static String[] getThreadPriority(
      MBSettings mbSettings, String languageId, double value, ThemeDisplay themeDisplay)
      throws Exception {

    String[] priorities = mbSettings.getPriorities(languageId);

    String[] priorityPair = _findThreadPriority(value, themeDisplay, priorities);

    if (priorityPair == null) {
      String defaultLanguageId = LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault());

      priorities = mbSettings.getPriorities(defaultLanguageId);

      priorityPair = _findThreadPriority(value, themeDisplay, priorities);
    }

    return priorityPair;
  }
  @Override
  public AssetVocabulary addDefaultVocabulary(long groupId) throws PortalException {

    Group group = groupLocalService.getGroup(groupId);

    long defaultUserId = userLocalService.getDefaultUserId(group.getCompanyId());

    Map<Locale, String> titleMap = new HashMap<>();

    titleMap.put(LocaleUtil.getSiteDefault(), PropsValues.ASSET_VOCABULARY_DEFAULT);

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setScopeGroupId(groupId);

    return assetVocabularyLocalService.addVocabulary(
        defaultUserId, groupId, StringPool.BLANK, titleMap, null, StringPool.BLANK, serviceContext);
  }
  @Override
  public AssetVocabulary addVocabulary(
      long userId, long groupId, String title, ServiceContext serviceContext)
      throws PortalException {

    Map<Locale, String> titleMap = new HashMap<>();

    Locale locale = LocaleUtil.getSiteDefault();

    titleMap.put(locale, title);

    Map<Locale, String> descriptionMap = new HashMap<>();

    descriptionMap.put(locale, StringPool.BLANK);

    return assetVocabularyLocalService.addVocabulary(
        userId, groupId, title, titleMap, descriptionMap, null, serviceContext);
  }
  protected Locale getDefaultLocale(long companyId) throws Exception {
    try (PreparedStatement ps =
        connection.prepareStatement(
            "select languageId from User_ where companyId = ? and " + "defaultUser = ?")) {

      ps.setLong(1, companyId);
      ps.setBoolean(2, true);

      try (ResultSet rs = ps.executeQuery()) {
        if (rs.next()) {
          String languageId = rs.getString("languageId");

          return LocaleUtil.fromLanguageId(languageId);
        }
      }
    }

    return LocaleUtil.getSiteDefault();
  }
Beispiel #21
0
  @Override
  public Map<Locale, String> getEmailFileEntryUpdatedBodyMap(PortletPreferences preferences) {

    Map<Locale, String> map =
        LocalizationUtil.getLocalizationMap(preferences, "emailFileEntryUpdatedBody");

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultValue = map.get(defaultLocale);

    if (Validator.isNotNull(defaultValue)) {
      return map;
    }

    map.put(
        defaultLocale, ContentUtil.get(PropsUtil.get(PropsKeys.DL_EMAIL_FILE_ENTRY_UPDATED_BODY)));

    return map;
  }
  @Test
  public void testAddFileEntryType() throws Exception {
    ServiceContext serviceContext = new ServiceContext();

    byte[] testFileBytes = FileUtil.getBytes(getClass(), _TEST_DDM_STRUCTURE);

    serviceContext.setAttribute("xsd", new String(testFileBytes));

    User user = TestPropsValues.getUser();

    serviceContext.setLanguageId(LocaleUtil.toLanguageId(user.getLocale()));

    DLFileEntryType dlFileEntryType =
        DLFileEntryTypeLocalServiceUtil.addFileEntryType(
            TestPropsValues.getUserId(),
            _group.getGroupId(),
            "Test Structure",
            StringPool.BLANK,
            new long[0],
            serviceContext);

    List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures();

    Assert.assertEquals(1, ddmStructures.size());

    DDMStructure ddmStructure = ddmStructures.get(0);

    Locale[] availableLocales = LocaleUtil.fromLanguageIds(ddmStructure.getAvailableLanguageIds());

    boolean hasDefaultLocale = ArrayUtil.contains(availableLocales, LocaleUtil.getSiteDefault());

    Assert.assertTrue(hasDefaultLocale);

    boolean hasHungarianLocale = ArrayUtil.contains(availableLocales, LocaleUtil.HUNGARY);

    Assert.assertTrue(hasHungarianLocale);

    boolean hasUserLocale = ArrayUtil.contains(availableLocales, user.getLocale());

    Assert.assertTrue(hasUserLocale);

    DLFileEntryTypeLocalServiceUtil.deleteDLFileEntryType(dlFileEntryType);
  }
  @Override
  protected Document doGetDocument(Calendar calendar) throws Exception {
    Document document = getBaseModelDocument(CLASS_NAME, calendar);

    document.addLocalizedText(Field.DESCRIPTION, calendar.getDescriptionMap());
    document.addLocalizedText(Field.NAME, calendar.getNameMap());
    document.addKeyword("calendarId", calendar.getCalendarId());

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    document.addText("defaultLanguageId", defaultLanguageId);

    CalendarResource calendarResource = calendar.getCalendarResource();

    document.addLocalizedText("resourceName", calendarResource.getNameMap());

    return document;
  }
Beispiel #24
0
  public static String[] getThreadPriority(
      PortletPreferences preferences, String languageId, double value, ThemeDisplay themeDisplay)
      throws Exception {

    String[] priorities =
        LocalizationUtil.getPreferencesValues(preferences, "priorities", languageId);

    String[] priorityPair = _findThreadPriority(value, themeDisplay, priorities);

    if (priorityPair == null) {
      String defaultLanguageId = LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault());

      priorities =
          LocalizationUtil.getPreferencesValues(preferences, "priorities", defaultLanguageId);

      priorityPair = _findThreadPriority(value, themeDisplay, priorities);
    }

    return priorityPair;
  }
  @Override
  public void postProcess(
      long companyId, PortletRequest portletRequest, PortletPreferences portletPreferences)
      throws SystemException {

    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailFromAddress",
        LoginUtil.getEmailFromName(portletPreferences, companyId));
    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailFromName",
        LoginUtil.getEmailFromName(portletPreferences, companyId));

    String languageId = LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault());

    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailPasswordResetBody_" + languageId,
        ContentUtil.get(PropsValues.ADMIN_EMAIL_PASSWORD_RESET_BODY));
    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailPasswordResetSubject_" + languageId,
        ContentUtil.get(PropsValues.ADMIN_EMAIL_PASSWORD_RESET_SUBJECT));
    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailPasswordSentBody_" + languageId,
        ContentUtil.get(PropsValues.ADMIN_EMAIL_PASSWORD_SENT_BODY));
    removeDefaultValue(
        portletRequest,
        portletPreferences,
        "emailPasswordSentSubject_" + languageId,
        ContentUtil.get(PropsValues.ADMIN_EMAIL_PASSWORD_SENT_SUBJECT));
  }
  @Override
  protected StagedModel addStagedModel(long groupId, Date createdDate) throws Exception {

    String title = RandomTestUtil.randomString();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId);

    serviceContext.setCommand(Constants.ADD);
    serviceContext.setCreateDate(createdDate);
    serviceContext.setLayoutFullURL("http://localhost");
    serviceContext.setModifiedDate(createdDate);

    return JournalTestUtil.addArticle(
        groupId,
        JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
        JournalArticleConstants.CLASSNAME_ID_DEFAULT,
        title,
        title,
        RandomTestUtil.randomString(),
        LocaleUtil.getSiteDefault(),
        false,
        false,
        serviceContext);
  }
  protected void updateJournalArticleDefaultLanguageId() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer();
        PreparedStatement ps1 =
            connection.prepareStatement("select id_, title from JournalArticle");
        PreparedStatement ps2 =
            AutoBatchPreparedStatementUtil.concurrentAutoBatch(
                connection, "update JournalArticle set defaultLanguageId = ? where " + "id_ = ?");
        ResultSet rs = ps1.executeQuery()) {

      Locale defaultLocale = LocaleUtil.getSiteDefault();

      while (rs.next()) {
        String defaultLanguageId =
            LocalizationUtil.getDefaultLanguageId(rs.getString(2), defaultLocale);

        ps2.setString(1, defaultLanguageId);
        ps2.setLong(2, rs.getLong(1));

        ps2.addBatch();
      }

      ps2.executeBatch();
    }
  }
 public void setDescriptionMap(Map<Locale, String> descriptionMap) {
   setDescriptionMap(descriptionMap, LocaleUtil.getSiteDefault());
 }
 public void setDescription(String description, Locale locale) {
   setDescription(description, locale, LocaleUtil.getSiteDefault());
 }
 public void setNameMap(Map<Locale, String> nameMap) {
   setNameMap(nameMap, LocaleUtil.getSiteDefault());
 }