Fórum
How to get MBThread from AssetEntry object
Bhavik Shah, modificado 8 Anos atrás.
How to get MBThread from AssetEntry object
Junior Member Postagens: 64 Data de Entrada: 21/05/15 Postagens Recentes
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, modificado 8 Anos atrás.
RE: How to get MBThread from AssetEntry object
Junior Member Postagens: 89 Data de Entrada: 14/01/11 Postagens Recentes
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, modificado 8 Anos atrás.
RE: How to get MBThread from AssetEntry object
Junior Member Postagens: 64 Data de Entrada: 21/05/15 Postagens Recentes
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, modificado 8 Anos atrás.
RE: How to get MBThread from AssetEntry object
Junior Member Postagens: 89 Data de Entrada: 14/01/11 Postagens Recentes
Add the following line and it should work:
assetEntryQuery.setVisible(null);
assetEntryQuery.setVisible(null);