Showing posts with label tag name. Show all posts
Showing posts with label tag name. Show all posts

Sunday, April 13, 2014

Find Liferay Journal Atticles By Type and Tag Name

Find Liferay Latest Journal Atticles By Type with Dynamic Query

Here I am sharing with you some knowledge about liferay dynamic query to get journal articles by type.
Actually to get journalArticles list by its type, I was not able to find any service call in liferay, so I have to customized it.

First of all, In Liferay portal.properties which contains Types of Web content. You can override below property and add more customize types from here...

    #
    # Set the list of article types. The display text of each of the article
    # types is set in content/Language.properties.
    #
    journal.article.types=announcements,blogs,general,news,press-release,test

Here I am adding method to get latest articles by its type.

private List<JournalArticle> getArticleByType(long scopeGroupId,
String value) throws PortalException, SystemException {
//maxVersionArticle : Query will find the article with its latest version

DynamicQuery maxVersionArticle = DynamicQueryFactoryUtil.forClass(
JournalArticle.class, "maxVersionArticle",
PortalClassLoaderUtil.getClassLoader()).add(
PropertyFactoryUtil.forName("articleId").eqProperty(
"articleByType.articleId")).setProjection(
ProjectionFactoryUtil.max("id"));

//articleByType : Query will find the articles by its type and appended the maxVersionArticle query so it will track only latest versions

DynamicQuery articleByType = DynamicQueryFactoryUtil.forClass(
JournalArticle.class, "articleByType",
PortalClassLoaderUtil.getClassLoader()).add(
PropertyFactoryUtil.forName("id").eq(maxVersionArticle)).add(
PropertyFactoryUtil.forName("groupId").eq(scopeGroupId)).add(
PropertyFactoryUtil.forName("type").eq(value)).addOrder(
OrderFactoryUtil.desc("createDate"));

articleByType.setLimit(0, 5);

LOG.info("Query -- "+articleByType.toString());

List<JournalArticle> ja = (List<JournalArticle>) JournalArticleLocalServiceUtil.dynamicQuery(articleByType);
return ja;

}

Find Liferay Latest Journal Atticles By Tag Name

Here I am adding one more function to get the journal article by tagname

public List<JournalArticle> getArticleByTags(long groupId, String tagName)
throws PortalException, SystemException {
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
long[] anyTagIds = AssetTagLocalServiceUtil.getTagIds(groupId,
new String[] { "alllocation", tagName });
assetEntryQuery.setAnyTagIds(anyTagIds);
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil
.getEntries(assetEntryQuery);
List<JournalArticle> journalArticleList = new ArrayList<JournalArticle>();
for (AssetEntry ae : assetEntryList) {
JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil
.getJournalArticleResource(ae.getClassPK());
JournalArticle journalArticleObj = JournalArticleLocalServiceUtil
.getArticle(groupId, journalArticleResourceObj
.getArticleId());
journalArticleList.add(journalArticleObj);
}
return journalArticleList;

}


Hope this might save your development time!!