Foren
How to get MBThread from AssetEntry object
Bhavik Shah, geändert vor 8 Jahren.
How to get MBThread from AssetEntry object
Junior Member Beiträge: 64 Beitrittsdatum: 21.05.15 Neueste Beiträge
Hello Liferay Experts,
I just want to fetch MBThread object from AssetEntry.
Right now I am using following code to get MBMessage from AssetEntry.
ThemeDisplay themeDisplay = (ThemeDisplay) req
.getAttribute(WebKeys.THEME_DISPLAY);
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllCategoryIds(assetEntryQuery.getAllCategoryIds());
assetEntryQuery.setGroupIds(new long[] {themeDisplay.getScopeGroupId()});
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
for (AssetEntry assetEntry : assetEntryList) {
if(assetEntry.getAssetRenderer().getClassName() == "com.liferay.portlet.messageboards.model.MBMessage"){
try {
MBMessage msg = MBMessageLocalServiceUtil.getMBMessageByUuidAndGroupId(assetEntry.getClassUuid(), assetEntry.getGroupId());
if(msg.isRoot()){
System.out.println("Subject : "+msg.getSubject());
System.out.println("Subject : "+msg.getUserName());
MBThread thread = msg.getThread();
System.out.println("Last Post Date :"+thread.getLastPostDate());
User user = UserLocalServiceUtil.getUser(thread.getLastPostByUserId());
System.out.println("User Name :"+user.getFullName());
System.out.println("view count :"+thread.getViewCount());
}
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I just want to fetch MBThread object from AssetEntry.
Right now I am using following code to get MBMessage from AssetEntry.
ThemeDisplay themeDisplay = (ThemeDisplay) req
.getAttribute(WebKeys.THEME_DISPLAY);
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllCategoryIds(assetEntryQuery.getAllCategoryIds());
assetEntryQuery.setGroupIds(new long[] {themeDisplay.getScopeGroupId()});
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
for (AssetEntry assetEntry : assetEntryList) {
if(assetEntry.getAssetRenderer().getClassName() == "com.liferay.portlet.messageboards.model.MBMessage"){
try {
MBMessage msg = MBMessageLocalServiceUtil.getMBMessageByUuidAndGroupId(assetEntry.getClassUuid(), assetEntry.getGroupId());
if(msg.isRoot()){
System.out.println("Subject : "+msg.getSubject());
System.out.println("Subject : "+msg.getUserName());
MBThread thread = msg.getThread();
System.out.println("Last Post Date :"+thread.getLastPostDate());
User user = UserLocalServiceUtil.getUser(thread.getLastPostByUserId());
System.out.println("User Name :"+user.getFullName());
System.out.println("view count :"+thread.getViewCount());
}
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Shinn Lok, geändert vor 8 Jahren.
RE: How to get MBThread from AssetEntry object
Junior Member Beiträge: 89 Beitrittsdatum: 14.01.11 Neueste Beiträge
You can specify the class name in the query instead of checking all the asset entries.
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllCategoryIds(assetEntryQuery.getAllCategoryIds());
assetEntryQuery.setGroupIds(new long[] {themeDisplay.getScopeGroupId()});
assetEntryQuery.setClassName("com.liferay.portlet.messageboards.model.MBThread");
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllCategoryIds(assetEntryQuery.getAllCategoryIds());
assetEntryQuery.setGroupIds(new long[] {themeDisplay.getScopeGroupId()});
assetEntryQuery.setClassName("com.liferay.portlet.messageboards.model.MBThread");
Bhavik Shah, geändert vor 8 Jahren.
RE: How to get MBThread from AssetEntry object
Junior Member Beiträge: 64 Beitrittsdatum: 21.05.15 Neueste Beiträge
Hi Shinn,
I have tried this option but I am not able to get directly MBThread object from AssetEntry.
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllCategoryIds(assetEntryQuery.getAllCategoryIds());
assetEntryQuery.setGroupIds(new long[] {themeDisplay.getScopeGroupId()});
assetEntryQuery.setClassName("com.liferay.portlet.messageboards.model.MBThread");
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
By doing this, I am getting [] blank list of assetEntryList.
But by doing following, I am able to get assetEntryList.
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllCategoryIds(assetEntryQuery.getAllCategoryIds());
assetEntryQuery.setGroupIds(new long[] {themeDisplay.getScopeGroupId()});
assetEntryQuery.setClassName("com.liferay.portlet.messageboards.model.MBMessage");
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
So I came to conclusion that I can get directly MBMessage Object from AssetEntry
but can not get directly MBThread object from AssetEntry.
Let me know if I am incorrect.
Thanks,
Bhavik
I have tried this option but I am not able to get directly MBThread object from AssetEntry.
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllCategoryIds(assetEntryQuery.getAllCategoryIds());
assetEntryQuery.setGroupIds(new long[] {themeDisplay.getScopeGroupId()});
assetEntryQuery.setClassName("com.liferay.portlet.messageboards.model.MBThread");
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
By doing this, I am getting [] blank list of assetEntryList.
But by doing following, I am able to get assetEntryList.
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
assetEntryQuery.setAllCategoryIds(assetEntryQuery.getAllCategoryIds());
assetEntryQuery.setGroupIds(new long[] {themeDisplay.getScopeGroupId()});
assetEntryQuery.setClassName("com.liferay.portlet.messageboards.model.MBMessage");
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
So I came to conclusion that I can get directly MBMessage Object from AssetEntry
but can not get directly MBThread object from AssetEntry.
Let me know if I am incorrect.
Thanks,
Bhavik
Shinn Lok, geändert vor 8 Jahren.
RE: How to get MBThread from AssetEntry object
Junior Member Beiträge: 89 Beitrittsdatum: 14.01.11 Neueste Beiträge
Add the following line and it should work:
assetEntryQuery.setVisible(null);
assetEntryQuery.setVisible(null);