When you fetch JournalAricle on the basis of Structure it will give you all the articles and not the latest articles. So in this blog we will see how to fetch latest version of web content/ Journal Article in Liferay.
You can use these two methods:-
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<JournalArticle> getAllArticle() { | |
List<JournalArticle>journalList = Collections.emptyList(); | |
String structureKey = "14904"; | |
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(JournalArticle.class, "journal",PortalClassLoaderUtil.getClassLoader()); | |
dynamicQuery.add(RestrictionsFactoryUtil.eq("journal.structureId", String.valueOf(structureKey))); | |
try { | |
journalList =JournalArticleLocalServiceUtil.dynamicQuery(dynamicQuery); | |
} catch (SystemException e) { | |
e.printStackTrace(); | |
} | |
return journalList; | |
} | |
public List<JournalArticle> getLatestVersionArticle(List<JournalArticle> totalArticles) { | |
List<JournalArticle> journalList = new ArrayList<JournalArticle>(); | |
JournalArticle latestArticle ; | |
for (JournalArticle journalArticle : totalArticles) { | |
try { | |
latestArticle = JournalArticleLocalServiceUtil.getLatestArticle(journalArticle.getResourcePrimKey()); | |
if (journalList.contains(latestArticle)) { | |
continue; | |
} else { | |
journalList.add(latestArticle); | |
} | |
} catch (PortalException | SystemException e) { | |
e.printStackTrace(); | |
} | |
} | |
return journalList; | |
} |
Here getAllArticles method give all the articles on the basis of StructureId and getLatestVersionArticles return the latest version articles when you pass List of articles.
Hope this will Help....
Related Post:-
No comments:
Post a Comment