From 8539efa40cac26ccd7b4ebbcd0f1d3704d26e704 Mon Sep 17 00:00:00 2001 From: Victor Galan Date: Tue, 5 Dec 2023 11:09:44 +0100 Subject: [PATCH] LPS-203220 Adapt usages --- .../AssetVocabularyCTDisplayRenderer.java | 4 +- .../AssetCategoriesDisplayContext.java | 5 +- .../resources/edit_vocabulary_settings.jspf | 2 +- .../CardinalityAssetEntryValidator.java | 10 ++-- .../taglib/AssetCategoriesSelectorTag.java | 6 ++- .../impl/test/AssetVocabularyImplTest.java | 46 +++++++++++++------ .../v1_0/TaxonomyVocabularyResourceImpl.java | 9 ++-- .../DLItemSelectorViewDisplayContext.java | 3 +- .../display/context/DLViewDisplayContext.java | 4 +- .../context/LayoutsAdminDisplayContext.java | 6 ++- .../context/AddGroupDisplayContext.java | 16 ++++--- 11 files changed, 73 insertions(+), 38 deletions(-) diff --git a/modules/apps/asset/asset-categories-admin-web/src/main/java/com/liferay/asset/categories/admin/web/internal/change/tracking/spi/display/AssetVocabularyCTDisplayRenderer.java b/modules/apps/asset/asset-categories-admin-web/src/main/java/com/liferay/asset/categories/admin/web/internal/change/tracking/spi/display/AssetVocabularyCTDisplayRenderer.java index 2b7aef479f5942..0e1dd398da38c3 100644 --- a/modules/apps/asset/asset-categories-admin-web/src/main/java/com/liferay/asset/categories/admin/web/internal/change/tracking/spi/display/AssetVocabularyCTDisplayRenderer.java +++ b/modules/apps/asset/asset-categories-admin-web/src/main/java/com/liferay/asset/categories/admin/web/internal/change/tracking/spi/display/AssetVocabularyCTDisplayRenderer.java @@ -166,7 +166,9 @@ else if (classTypePK == AssetCategoryConstants.ALL_CLASS_TYPE_PK) { sb.append(name); - if (assetVocabulary.isRequired(classNameId, classTypePK)) { + if (assetVocabulary.isRequired( + classNameId, classTypePK, assetVocabulary.getGroupId())) { + sb.append(StringPool.SPACE); sb.append(StringPool.STAR); } diff --git a/modules/apps/asset/asset-categories-admin-web/src/main/java/com/liferay/asset/categories/admin/web/internal/display/context/AssetCategoriesDisplayContext.java b/modules/apps/asset/asset-categories-admin-web/src/main/java/com/liferay/asset/categories/admin/web/internal/display/context/AssetCategoriesDisplayContext.java index 7f8e91c30659f2..8e42b3b3a3b882 100644 --- a/modules/apps/asset/asset-categories-admin-web/src/main/java/com/liferay/asset/categories/admin/web/internal/display/context/AssetCategoriesDisplayContext.java +++ b/modules/apps/asset/asset-categories-admin-web/src/main/java/com/liferay/asset/categories/admin/web/internal/display/context/AssetCategoriesDisplayContext.java @@ -203,7 +203,10 @@ public String getAssetType(AssetVocabulary vocabulary) { sb.append(name); - if (vocabulary.isRequired(classNameId, classTypePK)) { + if (vocabulary.isRequired( + classNameId, classTypePK, + _themeDisplay.getScopeGroupId())) { + sb.append(StringPool.SPACE); sb.append(StringPool.STAR); sb.append(StringPool.OPEN_PARENTHESIS); diff --git a/modules/apps/asset/asset-categories-admin-web/src/main/resources/META-INF/resources/edit_vocabulary_settings.jspf b/modules/apps/asset/asset-categories-admin-web/src/main/resources/META-INF/resources/edit_vocabulary_settings.jspf index ee8f9036e4e0b0..8662afd1d8946f 100644 --- a/modules/apps/asset/asset-categories-admin-web/src/main/resources/META-INF/resources/edit_vocabulary_settings.jspf +++ b/modules/apps/asset/asset-categories-admin-web/src/main/resources/META-INF/resources/edit_vocabulary_settings.jspf @@ -111,7 +111,7 @@ if (vocabulary != null) { - + diff --git a/modules/apps/asset/asset-categories-service/src/main/java/com/liferay/asset/categories/internal/validator/CardinalityAssetEntryValidator.java b/modules/apps/asset/asset-categories-service/src/main/java/com/liferay/asset/categories/internal/validator/CardinalityAssetEntryValidator.java index 6bf7efb317f961..1e17e247aec241 100644 --- a/modules/apps/asset/asset-categories-service/src/main/java/com/liferay/asset/categories/internal/validator/CardinalityAssetEntryValidator.java +++ b/modules/apps/asset/asset-categories-service/src/main/java/com/liferay/asset/categories/internal/validator/CardinalityAssetEntryValidator.java @@ -49,13 +49,15 @@ public void validate( _assetVocabularyLocalService.getGroupsVocabularies( _portal.getCurrentAndAncestorSiteGroupIds(groupId))) { - validate(classNameId, classTypePK, categoryIds, assetVocabulary); + validate( + groupId, classNameId, classTypePK, categoryIds, + assetVocabulary); } } protected void validate( - long classNameId, long classTypePK, long[] categoryIds, - AssetVocabulary assetVocabulary) + long groupId, long classNameId, long classTypePK, + long[] categoryIds, AssetVocabulary assetVocabulary) throws PortalException { if (!assetVocabulary.isAssociatedToClassNameIdAndClassTypePK( @@ -65,7 +67,7 @@ protected void validate( } if (assetVocabulary.isMissingRequiredCategory( - classNameId, classTypePK, categoryIds)) { + classNameId, classTypePK, categoryIds, groupId)) { throw new AssetCategoryException( assetVocabulary, AssetCategoryException.AT_LEAST_ONE_CATEGORY); diff --git a/modules/apps/asset/asset-taglib/src/main/java/com/liferay/asset/taglib/servlet/taglib/AssetCategoriesSelectorTag.java b/modules/apps/asset/asset-taglib/src/main/java/com/liferay/asset/taglib/servlet/taglib/AssetCategoriesSelectorTag.java index 9504ad92ca1410..e1825f6f5334ed 100644 --- a/modules/apps/asset/asset-taglib/src/main/java/com/liferay/asset/taglib/servlet/taglib/AssetCategoriesSelectorTag.java +++ b/modules/apps/asset/asset-taglib/src/main/java/com/liferay/asset/taglib/servlet/taglib/AssetCategoriesSelectorTag.java @@ -358,7 +358,8 @@ protected List> getVocabularies() throws Exception { ).put( "required", vocabulary.isRequired( - PortalUtil.getClassNameId(_className), _classTypePK) && + PortalUtil.getClassNameId(_className), _classTypePK, + themeDisplay.getScopeGroupId()) && _showRequiredLabel ).put( "selectedCategories", selectedCategoryIds @@ -517,7 +518,8 @@ private List _getVocabularies() { vocabulary -> { if (_showOnlyRequiredVocabularies && !vocabulary.isRequired( - PortalUtil.getClassNameId(_className), _classTypePK)) { + PortalUtil.getClassNameId(_className), _classTypePK, + themeDisplay.getScopeGroupId())) { return false; } diff --git a/modules/apps/asset/asset-test/src/testIntegration/java/com/liferay/asset/model/impl/test/AssetVocabularyImplTest.java b/modules/apps/asset/asset-test/src/testIntegration/java/com/liferay/asset/model/impl/test/AssetVocabularyImplTest.java index 31cc968be9c90e..e2add98a7fcf98 100644 --- a/modules/apps/asset/asset-test/src/testIntegration/java/com/liferay/asset/model/impl/test/AssetVocabularyImplTest.java +++ b/modules/apps/asset/asset-test/src/testIntegration/java/com/liferay/asset/model/impl/test/AssetVocabularyImplTest.java @@ -118,7 +118,8 @@ public void testIsMissingRequiredCategory() throws Exception { Assert.assertFalse( vocabulary.isMissingRequiredCategory( - 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, new long[] {1})); + 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, new long[] {1}, + _group.getGroupId())); vocabulary = AssetTestUtil.addVocabulary( _group.getGroupId(), 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, @@ -126,21 +127,24 @@ public void testIsMissingRequiredCategory() throws Exception { Assert.assertTrue( vocabulary.isMissingRequiredCategory( - 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, new long[] {1})); + 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, new long[] {1}, + _group.getGroupId())); Assert.assertFalse( vocabulary.isMissingRequiredCategory( - 2, AssetCategoryConstants.ALL_CLASS_TYPE_PK, new long[0])); + 2, AssetCategoryConstants.ALL_CLASS_TYPE_PK, new long[0], + _group.getGroupId())); AssetCategory category = AssetTestUtil.addCategory( _group.getGroupId(), vocabulary.getVocabularyId()); Assert.assertTrue( vocabulary.isMissingRequiredCategory( - 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, new long[] {1})); + 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, new long[] {1}, + _group.getGroupId())); Assert.assertFalse( vocabulary.isMissingRequiredCategory( 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, - new long[] {category.getCategoryId()})); + new long[] {category.getCategoryId()}, _group.getGroupId())); } @Test @@ -150,36 +154,52 @@ public void testIsRequired() throws Exception { AssetCategoryConstants.ALL_CLASS_TYPE_PK, false); Assert.assertFalse( - vocabulary.isRequired(1, AssetCategoryConstants.ALL_CLASS_TYPE_PK)); + vocabulary.isRequired( + 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, + _group.getGroupId())); Assert.assertFalse( - vocabulary.isRequired(2, AssetCategoryConstants.ALL_CLASS_TYPE_PK)); + vocabulary.isRequired( + 2, AssetCategoryConstants.ALL_CLASS_TYPE_PK, + _group.getGroupId())); vocabulary = AssetTestUtil.addVocabulary( _group.getGroupId(), AssetCategoryConstants.ALL_CLASS_NAME_ID, AssetCategoryConstants.ALL_CLASS_TYPE_PK, true); Assert.assertTrue( - vocabulary.isRequired(1, AssetCategoryConstants.ALL_CLASS_TYPE_PK)); + vocabulary.isRequired( + 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, + _group.getGroupId())); Assert.assertTrue( - vocabulary.isRequired(2, AssetCategoryConstants.ALL_CLASS_TYPE_PK)); + vocabulary.isRequired( + 2, AssetCategoryConstants.ALL_CLASS_TYPE_PK, + _group.getGroupId())); vocabulary = AssetTestUtil.addVocabulary( _group.getGroupId(), 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, false); Assert.assertFalse( - vocabulary.isRequired(1, AssetCategoryConstants.ALL_CLASS_TYPE_PK)); + vocabulary.isRequired( + 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, + _group.getGroupId())); Assert.assertFalse( - vocabulary.isRequired(2, AssetCategoryConstants.ALL_CLASS_TYPE_PK)); + vocabulary.isRequired( + 2, AssetCategoryConstants.ALL_CLASS_TYPE_PK, + _group.getGroupId())); vocabulary = AssetTestUtil.addVocabulary( _group.getGroupId(), 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, true); Assert.assertTrue( - vocabulary.isRequired(1, AssetCategoryConstants.ALL_CLASS_TYPE_PK)); + vocabulary.isRequired( + 1, AssetCategoryConstants.ALL_CLASS_TYPE_PK, + _group.getGroupId())); Assert.assertFalse( - vocabulary.isRequired(2, AssetCategoryConstants.ALL_CLASS_TYPE_PK)); + vocabulary.isRequired( + 2, AssetCategoryConstants.ALL_CLASS_TYPE_PK, + _group.getGroupId())); } @DeleteAfterTestRun diff --git a/modules/apps/bulk/bulk-rest-impl/src/main/java/com/liferay/bulk/rest/internal/resource/v1_0/TaxonomyVocabularyResourceImpl.java b/modules/apps/bulk/bulk-rest-impl/src/main/java/com/liferay/bulk/rest/internal/resource/v1_0/TaxonomyVocabularyResourceImpl.java index ff18bda5b5294f..6bf7879313f5fd 100644 --- a/modules/apps/bulk/bulk-rest-impl/src/main/java/com/liferay/bulk/rest/internal/resource/v1_0/TaxonomyVocabularyResourceImpl.java +++ b/modules/apps/bulk/bulk-rest-impl/src/main/java/com/liferay/bulk/rest/internal/resource/v1_0/TaxonomyVocabularyResourceImpl.java @@ -62,7 +62,7 @@ public Page postSiteTaxonomyVocabulariesCommonPage( transform( assetCategoriesMap.entrySet(), entry -> _toTaxonomyVocabulary( - entry.getValue(), entry.getKey()))); + entry.getValue(), entry.getKey(), siteId))); } private Set _getAssetCategories( @@ -169,15 +169,16 @@ private long _getClassNameId() { } private TaxonomyVocabulary _toTaxonomyVocabulary( - List assetCategories, AssetVocabulary assetVocabulary) { + List assetCategories, AssetVocabulary assetVocabulary, + long siteId) { return new TaxonomyVocabulary() { { multiValued = assetVocabulary.isMultiValued(); name = assetVocabulary.getName(); required = assetVocabulary.isRequired( - _getClassNameId(), - AssetCategoryConstants.ALL_CLASS_TYPE_PK); + _getClassNameId(), AssetCategoryConstants.ALL_CLASS_TYPE_PK, + siteId); taxonomyCategories = transformToArray( assetCategories, assetCategory -> new TaxonomyCategory() { diff --git a/modules/apps/document-library/document-library-item-selector-web/src/main/java/com/liferay/document/library/item/selector/web/internal/display/context/DLItemSelectorViewDisplayContext.java b/modules/apps/document-library/document-library-item-selector-web/src/main/java/com/liferay/document/library/item/selector/web/internal/display/context/DLItemSelectorViewDisplayContext.java index 38dbc9e4d17344..188ae6c6639ea0 100644 --- a/modules/apps/document-library/document-library-item-selector-web/src/main/java/com/liferay/document/library/item/selector/web/internal/display/context/DLItemSelectorViewDisplayContext.java +++ b/modules/apps/document-library/document-library-item-selector-web/src/main/java/com/liferay/document/library/item/selector/web/internal/display/context/DLItemSelectorViewDisplayContext.java @@ -330,7 +330,8 @@ public PortletURL getUploadURL( for (AssetVocabulary assetVocabulary : assetVocabularies) { if (assetVocabulary.isRequired( - classNameId, defaultFileEntryTypeId)) { + classNameId, defaultFileEntryTypeId, + _themeDisplay.getScopeGroupId())) { return null; } diff --git a/modules/apps/document-library/document-library-web/src/main/java/com/liferay/document/library/web/internal/display/context/DLViewDisplayContext.java b/modules/apps/document-library/document-library-web/src/main/java/com/liferay/document/library/web/internal/display/context/DLViewDisplayContext.java index 5cc1f1f4dbea09..4c53747ffceeed 100644 --- a/modules/apps/document-library/document-library-web/src/main/java/com/liferay/document/library/web/internal/display/context/DLViewDisplayContext.java +++ b/modules/apps/document-library/document-library-web/src/main/java/com/liferay/document/library/web/internal/display/context/DLViewDisplayContext.java @@ -429,8 +429,8 @@ public boolean isUploadable() throws PortalException { for (AssetVocabulary assetVocabulary : assetVocabularies) { if (assetVocabulary.isRequired( classNameId, - DLFileEntryTypeConstants. - FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT)) { + DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT, + themeDisplay.getScopeGroupId())) { return false; } diff --git a/modules/apps/layout/layout-admin-web/src/main/java/com/liferay/layout/admin/web/internal/display/context/LayoutsAdminDisplayContext.java b/modules/apps/layout/layout-admin-web/src/main/java/com/liferay/layout/admin/web/internal/display/context/LayoutsAdminDisplayContext.java index 52f5ab7bacd848..529c8e3f69a62a 100644 --- a/modules/apps/layout/layout-admin-web/src/main/java/com/liferay/layout/admin/web/internal/display/context/LayoutsAdminDisplayContext.java +++ b/modules/apps/layout/layout-admin-web/src/main/java/com/liferay/layout/admin/web/internal/display/context/LayoutsAdminDisplayContext.java @@ -1692,7 +1692,8 @@ public boolean hasRequiredVocabularies() { for (AssetVocabulary assetVocabulary : assetVocabularies) { if (assetVocabulary.isAssociatedToClassNameId(classNameId) && - assetVocabulary.isRequired(classNameId, 0)) { + assetVocabulary.isRequired( + classNameId, 0, themeDisplay.getScopeGroupId())) { return true; } @@ -1906,7 +1907,8 @@ public boolean isShowCategorization() { for (AssetVocabulary assetVocabulary : assetVocabularies) { if (assetVocabulary.isAssociatedToClassNameId(classNameId) && - assetVocabulary.isRequired(classNameId, 0)) { + assetVocabulary.isRequired( + classNameId, 0, themeDisplay.getScopeGroupId())) { int assetVocabularyCategoriesCount = AssetCategoryServiceUtil.getVocabularyCategoriesCount( diff --git a/modules/apps/site/site-admin-web/src/main/java/com/liferay/site/admin/web/internal/display/context/AddGroupDisplayContext.java b/modules/apps/site/site-admin-web/src/main/java/com/liferay/site/admin/web/internal/display/context/AddGroupDisplayContext.java index 7f557683e4ef20..8ead08f9777a9a 100644 --- a/modules/apps/site/site-admin-web/src/main/java/com/liferay/site/admin/web/internal/display/context/AddGroupDisplayContext.java +++ b/modules/apps/site/site-admin-web/src/main/java/com/liferay/site/admin/web/internal/display/context/AddGroupDisplayContext.java @@ -35,6 +35,9 @@ public AddGroupDisplayContext( _disablePrivateLayouts = disablePrivateLayouts; _httpServletRequest = httpServletRequest; _renderResponse = renderResponse; + + _themeDisplay = (ThemeDisplay)httpServletRequest.getAttribute( + WebKeys.THEME_DISPLAY); } public String getAddGroupURL() { @@ -65,11 +68,7 @@ public long[] getGroupIds() { return _groupsIds; } - ThemeDisplay themeDisplay = - (ThemeDisplay)_httpServletRequest.getAttribute( - WebKeys.THEME_DISPLAY); - - long[] groupsIds = {themeDisplay.getCompanyGroupId()}; + long[] groupsIds = {_themeDisplay.getCompanyGroupId()}; if (_getParentGroupId() > 0) { groupsIds = PortalUtil.getCurrentAndAncestorSiteGroupIds( @@ -89,7 +88,8 @@ public boolean hasRequiredVocabularies() { for (AssetVocabulary assetVocabulary : assetVocabularies) { if (assetVocabulary.isAssociatedToClassNameId(classNameId) && - assetVocabulary.isRequired(classNameId, 0)) { + assetVocabulary.isRequired( + classNameId, 0, _themeDisplay.getScopeGroupId())) { return true; } @@ -106,7 +106,8 @@ public boolean isShowCategorization() { for (AssetVocabulary assetVocabulary : assetVocabularies) { if (assetVocabulary.isAssociatedToClassNameId(classNameId) && - assetVocabulary.isRequired(classNameId, 0)) { + assetVocabulary.isRequired( + classNameId, 0, _themeDisplay.getScopeGroupId())) { int assetVocabularyCategoriesCount = AssetCategoryServiceUtil.getVocabularyCategoriesCount( @@ -153,5 +154,6 @@ private long _getParentGroupId() { private final HttpServletRequest _httpServletRequest; private Long _parentGroupId; private final RenderResponse _renderResponse; + private final ThemeDisplay _themeDisplay; } \ No newline at end of file