ipkiss
ipkiss

Reputation: 13651

How to filter AssetType from AssetEntry in liferay 6.1?

I used the following code to retrieve all the journal articles based on a specific category:

long catId = category.getCategoryId(); 
AssetEntryQuery assetEntryQuery = new AssetEntryQuery(); 
long[] anyCatIds = {catId};  

assetEntryQuery.setAnyCategoryIds(anyCatIds);  

// Line A         
List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);  
for(AssetEntry ae : assetEntryList)
{  
    // Line B
    JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(ae.getClassPK()); 

    JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(themeDisplay.getParentGroupId(), journalArticleResourceObj.getArticleId());  
    journalArticleList.add(journalArticleObj.getArticleId()); 

} 

Howver, since the AssetEntry will fetch all the entries, including Blogs, and so on, the above code will throw an exception at Line B if I add a blog entry that uses the same category, since the blog entry does not have JournalArticleResource.

So, I was wondering if it is possible to filter only JournalArticle type will be fetch at Line A, then I don't have to worry about Line B anymore.

I have tried but no luck so far.

Does any one have some ideas?

Upvotes: 0

Views: 458

Answers (1)

Pankaj Kathiriya
Pankaj Kathiriya

Reputation: 4210

Use assetEntryQuery.setClassName(JournalArticle.class.getName());

Upvotes: 1

Related Questions