Skip to content

Commit

Permalink
LPS-203220 Adapt usages
Browse files Browse the repository at this point in the history
  • Loading branch information
victorg1991 authored and brianchandotcom committed Dec 8, 2023
1 parent 9c06eb7 commit 8539efa
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ if (vocabulary != null) {
</div>
</c:if>

<aui:input inlineLabel="right" label="required" labelCssClass="simple-toggle-switch" name='<%= "required" + index %>' type="toggle-switch" value="<%= (vocabulary != null) ? vocabulary.isRequired(classNameId, classTypePK) : false %>" />
<aui:input inlineLabel="right" label="required" labelCssClass="simple-toggle-switch" name='<%= "required" + index %>' type="toggle-switch" value="<%= (vocabulary != null) ? vocabulary.isRequired(classNameId, classTypePK, scopeGroupId) : false %>" />
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ protected List<Map<String, Object>> getVocabularies() throws Exception {
).put(
"required",
vocabulary.isRequired(
PortalUtil.getClassNameId(_className), _classTypePK) &&
PortalUtil.getClassNameId(_className), _classTypePK,
themeDisplay.getScopeGroupId()) &&
_showRequiredLabel
).put(
"selectedCategories", selectedCategoryIds
Expand Down Expand Up @@ -517,7 +518,8 @@ private List<AssetVocabulary> _getVocabularies() {
vocabulary -> {
if (_showOnlyRequiredVocabularies &&
!vocabulary.isRequired(
PortalUtil.getClassNameId(_className), _classTypePK)) {
PortalUtil.getClassNameId(_className), _classTypePK,
themeDisplay.getScopeGroupId())) {

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,33 @@ 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,
true);

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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Page<TaxonomyVocabulary> postSiteTaxonomyVocabulariesCommonPage(
transform(
assetCategoriesMap.entrySet(),
entry -> _toTaxonomyVocabulary(
entry.getValue(), entry.getKey())));
entry.getValue(), entry.getKey(), siteId)));
}

private Set<AssetCategory> _getAssetCategories(
Expand Down Expand Up @@ -169,15 +169,16 @@ private long _getClassNameId() {
}

private TaxonomyVocabulary _toTaxonomyVocabulary(
List<AssetCategory> assetCategories, AssetVocabulary assetVocabulary) {
List<AssetCategory> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ public PortletURL getUploadURL(

for (AssetVocabulary assetVocabulary : assetVocabularies) {
if (assetVocabulary.isRequired(
classNameId, defaultFileEntryTypeId)) {
classNameId, defaultFileEntryTypeId,
_themeDisplay.getScopeGroupId())) {

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public AddGroupDisplayContext(
_disablePrivateLayouts = disablePrivateLayouts;
_httpServletRequest = httpServletRequest;
_renderResponse = renderResponse;

_themeDisplay = (ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
}

public String getAddGroupURL() {
Expand Down Expand Up @@ -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(
Expand All @@ -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;
}
Expand All @@ -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(
Expand Down Expand Up @@ -153,5 +154,6 @@ private long _getParentGroupId() {
private final HttpServletRequest _httpServletRequest;
private Long _parentGroupId;
private final RenderResponse _renderResponse;
private final ThemeDisplay _themeDisplay;

}

0 comments on commit 8539efa

Please sign in to comment.