Ejemplo n.º 1
0
  protected String addBasicWebContentStructureAndTemplate(long companyId) throws Exception {

    initJournalDDMCompositeModelsResourceActions();

    Group group = _groupLocalService.getCompanyGroup(companyId);

    long defaultUserId = _userLocalService.getDefaultUserId(companyId);

    Class<?> clazz = getClass();

    _defaultDDMStructureHelper.addDDMStructures(
        defaultUserId,
        group.getGroupId(),
        PortalUtil.getClassNameId(JournalArticle.class),
        clazz.getClassLoader(),
        "com/liferay/journal/internal/upgrade/v1_0_0/dependencies"
            + "/basic-web-content-structure.xml",
        new ServiceContext());

    String defaultLanguageId = UpgradeProcessUtil.getDefaultLanguageId(companyId);

    Locale defaultLocale = LocaleUtil.fromLanguageId(defaultLanguageId);

    List<Element> structureElements = getDDMStructures(defaultLocale);

    Element structureElement = structureElements.get(0);

    return StringUtil.toUpperCase(structureElement.elementText("name"));
  }
  protected void updateArticleType() throws Exception {
    if (!hasSelectedArticleTypes()) {
      return;
    }

    List<String> types = getArticleTypes();

    if (types.size() <= 0) {
      return;
    }

    Locale localeThreadLocalDefaultLocale = LocaleThreadLocal.getDefaultLocale();

    try {
      List<Company> companies = _companyLocalService.getCompanies();

      for (Company company : companies) {
        LocaleThreadLocal.setDefaultLocale(company.getLocale());

        Set<Locale> locales = LanguageUtil.getAvailableLocales(company.getGroupId());

        Locale defaultLocale =
            LocaleUtil.fromLanguageId(
                UpgradeProcessUtil.getDefaultLanguageId(company.getCompanyId()));

        Map<Locale, String> nameMap =
            LocalizationUtil.getLocalizationMap(locales, defaultLocale, "type");

        AssetVocabulary assetVocabulary =
            addAssetVocabulary(
                company.getGroupId(),
                company.getCompanyId(),
                "type",
                nameMap,
                new HashMap<Locale, String>());

        Map<String, Long> journalArticleTypesToAssetCategoryIds = new HashMap<>();

        for (String type : types) {
          AssetCategory assetCategory =
              addAssetCategory(
                  company.getGroupId(),
                  company.getCompanyId(),
                  type,
                  assetVocabulary.getVocabularyId());

          journalArticleTypesToAssetCategoryIds.put(type, assetCategory.getCategoryId());
        }

        updateArticles(company.getCompanyId(), journalArticleTypesToAssetCategoryIds);
      }
    } finally {
      LocaleThreadLocal.setDefaultLocale(localeThreadLocalDefaultLocale);
    }
  }
  protected void updateFileEntryTypeNamesAndDescriptions(
      long companyId,
      long dlFileEntryTypeId,
      String nameLanguageKey,
      String nameXML,
      String descriptionXML)
      throws Exception {

    boolean update = false;

    Locale defaultLocale =
        LocaleUtil.fromLanguageId(UpgradeProcessUtil.getDefaultLanguageId(companyId));

    String defaultValue = LanguageUtil.get(defaultLocale, nameLanguageKey);

    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(nameXML);
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(descriptionXML);

    for (Locale locale : LanguageUtil.getSupportedLocales()) {
      String value = LanguageUtil.get(locale, nameLanguageKey);

      if (!locale.equals(defaultLocale) && value.equals(defaultValue)) {
        continue;
      }

      String description = descriptionMap.get(locale);

      if (description == null) {
        descriptionMap.put(locale, value);

        update = true;
      }

      String name = nameMap.get(locale);

      if (name == null) {
        nameMap.put(locale, value);

        update = true;
      }
    }

    if (update) {
      updateFileEntryTypeNamesAndDescriptions(
          dlFileEntryTypeId, nameXML, descriptionXML, nameMap, descriptionMap, defaultLocale);
    }
  }