5/23/2011

Retrieving Blogs Comments

If you need to retrieve all comments that have been made to blogsentries (com.liferay.portlet.blogs.model.BlogsEntry), you need to know that Liferay stores all comments as message board messages. So you need to do the following to get all comments:


table: mbMessage


Properties:


classNameId: ClassNameId of BlogsEntry
parentMessageId: Not 0
classPK: Primary Key of your BlogsEntry
categoryId: must be -1

DynamicQuery mbMessageQuery = DynamicQueryFactoryUtil.forClass(MBMessage.class, PortalClassLoaderUtil.getClassLoader());

long blogsEntryClassNameId = ClassNameLocalServiceUtil.getClassNameId(BlogsEntry.class.getName());
mbMessageQuery.add(RestrictionsFactoryUtil.eq("classNameId", blogsEntryClassNameId));
mbMessageQuery.add(PropertyFactoryUtil.forName("parentMessageId").ne(0l));
mbMessageQuery.add(PropertyFactoryUtil.forName("classNameId").ne(0l));
mbMessageQuery.add(PropertyFactoryUtil.forName("classPK").ne(0l));
mbMessageQuery.add(PropertyFactoryUtil.forName("categoryId").eq(-1l));
List dynamicQuery = MBMessageLocalServiceUtil.dynamicQuery(mbMessageQuery);


If you like this post it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.