通过代码创建日历并在 Liferay 中添加权限模型

Create calendar by code and add Permissions model in Liferay

我有 Liferay 6.2 GA4... 我想通过代码在 portlet 中创建一个生日日历...所以我在我的 portlet 中创建了一个日历,代码如下:

long calendarId = CounterLocalServiceUtil.increment(Calendar.class.getName());
calendar =  CalendarLocalServiceUtil.createCalendar(calendarId);
calendar.setName(BIRTHDAYS_CALENDAR_NAME);
calendar.setGroupId(themeDisplay.getScopeGroupId());
calendar.setUserId(themeDisplay.getUserId());
calendar.setCreateDate(new Date());
calendar.setCompanyId(themeDisplay.getCompanyId());
calendar.setUserName(themeDisplay.getUser().getFullName());
calendar.setModifiedDate(new Date());
calendar.setCalendarResourceId(getCalendarDefault(themeDisplay.getScopeGroupId()).getCalendarResourceId());
calendar.setColor(6663561);
CalendarLocalServiceUtil.addCalendar(calendar);

这很好用,并且日历已创建...但在那之后我遇到了问题...

如果我尝试在 portlet 中(在站点中)设置对日历的权限,我会在日志中看到一个包含错误的空白页面:

java.lang.IllegalArgumentException: Permissioned model is null

所以我的问题是: 如何创建具有权限的日历? 我想使用默认权限创建它,当您在网站中创建日历时,显示的是这样,它们是:

权限

查看者:站点成员

我该怎么做?

谢谢!!

编辑

我在 liferay 论坛上问过同样的问题,但没有在那里得到答案...所以我在这里问,希望我能在这里得到答案:)

same question

您可以拨打:

CalendarLocalServiceUtil.addCalendar(long userId, long groupId, long calendarResourceId, java.util.Map<java.util.Locale, java.lang.String> nameMap, java.util.Map<java.util.Locale, java.lang.String> descriptionMap, java.lang.String timeZoneId, int color, boolean defaultCalendar, boolean enableComments, boolean enableRatings, com.liferay.portal.service.ServiceContext serviceContext)

它将创建资源权限。

法比奥.

我找到了答案,您只需在创建日历后调用 addModelResource 方法即可。

ResourceLocalServiceUtil.addModelResources(calendar, serviceContext);

希望对大家有所帮助!