Foren
Safe groupID for creating categories via code
Jan Tošovský, geändert vor 12 Jahren.
Safe groupID for creating categories via code
Liferay Master Beiträge: 566 Beitrittsdatum: 22.07.10 Neueste Beiträge
Hello Everyone,
I can create category/vocabulary from JSP as there is no problem access the groupID of the current layout. In Java code this procedure fails because of inappropriate GroupID. The only object I have is WikiNode node. When node.getGroupId() is used, the created category is visible only if that wiki is not scoped. Otherwise it is created without errors, but not accessible/visible anywhere.
When the zero value is used instead, I am getting error No Group exists with the primary key 0.
Is there any safe groupId number which could be used for this. Otherwise I will have to pass it as parameter...
Regards,
Jan
I can create category/vocabulary from JSP as there is no problem access the groupID of the current layout. In Java code this procedure fails because of inappropriate GroupID. The only object I have is WikiNode node. When node.getGroupId() is used, the created category is visible only if that wiki is not scoped. Otherwise it is created without errors, but not accessible/visible anywhere.
When the zero value is used instead, I am getting error No Group exists with the primary key 0.
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);
Map<locale, string> titleMap = new HashMap<locale, string>();
titleMap.put(LocaleUtil.getDefault(), vocabularyName);
AssetVocabularyLocalServiceUtil.addVocabulary(userId, StringPool.BLANK, titleMap, null, null, serviceContext);
</locale,></locale,>
Is there any safe groupId number which could be used for this. Otherwise I will have to pass it as parameter...
Regards,
Jan
Amos Fong, geändert vor 12 Jahren.
RE: Safe groupID for creating categories via code (Antwort)
Liferay Legend Beiträge: 2047 Beitrittsdatum: 07.10.08 Neueste Beiträge
Hi Jan,
I think what you can do is this. If the group is scoped, get the group of the actual community/organization. isLayout() checks if it is scoped or not.
I think what you can do is this. If the group is scoped, get the group of the actual community/organization. isLayout() checks if it is scoped or not.
group = GroupLocalServiceUtil.getGroup(groupId);
if (group.isLayout()) {
long parentGroupId = group.getParentGroupId();
if (parentGroupId > 0) {
group = GroupLocalServiceUtil.getGroup(parentGroupId);
}
}
Jan Tošovský, geändert vor 12 Jahren.
RE: Safe groupID for creating categories via code
Liferay Master Beiträge: 566 Beitrittsdatum: 22.07.10 Neueste Beiträge
Great! It is exactly what I need! Works perfectly now. Thanks a lot.