我使用Liferay 6.0.6,我需要以编程方式从我的自定义Portlet或预定作业中插入博客条目。
我找到了 BlogsEntryLocalServiceUtil 这个类,但不知道如何使用它。
谢谢。
答案 0 :(得分:0)
这是解决方案:
Company company = CompanyLocalServiceUtil.getCompanyById(MY_COMPANY_ID);
Role adminRole = RoleLocalServiceUtil.getRole(company.getCompanyId(),"Administrator");
List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());
//GET USER ADMIN
User adminUser = null;
for (User user : adminUsers){
if (user.getEmailAddress().equals(MY_ADMIN_EMAIL)){
adminUser = user;
break;
}
}
if (adminUser!=null) {
long userID = adminUser.getUserId();
long groudID = adminUser.getGroupIds()[0];
PrincipalThreadLocal.setName(userID);
PermissionChecker permissionChecker=PermissionCheckerFactoryUtil.create(adminUser, true);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
Calendar displayDate =CalendarFactoryUtil.getCalendar(TimeZone.getTimeZone(StringPool.UTC));
boolean allowPingbacks = true;
boolean allowTrackbacks = true;
int actionPublish = WorkflowConstants.ACTION_PUBLISH;
ServiceContext serviceContext = new ServiceContext();
serviceContext.setWorkflowAction(actionPublish);
serviceContext.setAssetCategoryIds(new long[]{category});
serviceContext.setCreateDate(displayDate.getTime());
serviceContext.getExpandoBridgeAttributes().put("key1", value1);
serviceContext.getExpandoBridgeAttributes().put("key2", value2);
serviceContext.setAddGuestPermissions(true);
serviceContext.setScopeGroupId(groudID);
//INSERT BLOGS ENTRY
BlogsEntryLocalServiceUtil.addEntry(userID, title, content, displayDate.get(Calendar.MONTH), displayDate.get(Calendar.DAY_OF_MONTH), displayDate.get(Calendar.YEAR), displayDate.get(Calendar.HOUR), displayDate.get(Calendar.MINUTE), allowPingbacks, allowTrackbacks, new String[]{}, serviceContext);
}
答案 1 :(得分:0)
您提到的类中有addEntry方法,即BlogsEntryLocalServiceUtil,只需传递所需的参数,您就可以创建博客条目。
但不知道如何使用它。
为此,您可以尝试查看liferay源的portal-impl文件夹,并找到那里可用的所有Java源代码,以找到如何实现它们。