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); } }
@Override protected StagedModel addStagedModel( Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception { List<StagedModel> vocabularyDependentStagedModels = dependentStagedModelsMap.get(AssetVocabulary.class.getSimpleName()); AssetVocabulary vocabulary = (AssetVocabulary) vocabularyDependentStagedModels.get(0); List<StagedModel> categoryDependentStagedModels = dependentStagedModelsMap.get(AssetCategory.class.getSimpleName()); AssetCategory category = (AssetCategory) categoryDependentStagedModels.get(0); return AssetTestUtil.addCategory( group.getGroupId(), vocabulary.getVocabularyId(), category.getCategoryId()); }
@Override protected Map<String, List<StagedModel>> addDependentStagedModelsMap(Group group) throws Exception { Map<String, List<StagedModel>> dependentStagedModelsMap = new HashMap<>(); AssetVocabulary vocabulary = AssetTestUtil.addVocabulary(group.getGroupId()); addDependentStagedModel(dependentStagedModelsMap, AssetVocabulary.class, vocabulary); AssetCategory category = AssetTestUtil.addCategory(group.getGroupId(), vocabulary.getVocabularyId()); addDependentStagedModel(dependentStagedModelsMap, AssetCategory.class, category); return dependentStagedModelsMap; }
protected void validate( long classNameId, long classTypePK, final long[] categoryIds, AssetVocabulary assetVocabulary) throws PortalException { if (!assetVocabulary.isAssociatedToClassNameIdAndClassTypePK(classNameId, classTypePK)) { return; } if (assetVocabulary.isMissingRequiredCategory(classNameId, classTypePK, categoryIds)) { throw new AssetCategoryException( assetVocabulary, AssetCategoryException.AT_LEAST_ONE_CATEGORY); } if (!assetVocabulary.isMultiValued() && assetVocabulary.hasMoreThanOneCategorySelected(categoryIds)) { throw new AssetCategoryException(assetVocabulary, AssetCategoryException.TOO_MANY_CATEGORIES); } }
@Override protected void validateImport( Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception { List<StagedModel> categoryDependentStagedModels = dependentStagedModelsMap.get(AssetCategory.class.getSimpleName()); Assert.assertEquals(1, categoryDependentStagedModels.size()); AssetCategory category = (AssetCategory) categoryDependentStagedModels.get(0); AssetCategoryLocalServiceUtil.getAssetCategoryByUuidAndGroupId( category.getUuid(), group.getGroupId()); List<StagedModel> vocabularyDependentStagedModels = dependentStagedModelsMap.get(AssetVocabulary.class.getSimpleName()); Assert.assertEquals(1, vocabularyDependentStagedModels.size()); AssetVocabulary vocabulary = (AssetVocabulary) vocabularyDependentStagedModels.get(0); AssetVocabularyLocalServiceUtil.getAssetVocabularyByUuidAndGroupId( vocabulary.getUuid(), group.getGroupId()); }