Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
erik carl candela
How to get List journalarticle filter by Tags ? Asset Publisher
January 25, 2010 4:31 PM
Answer

erik carl candela

Rank: New Member

Posts: 20

Join Date: April 24, 2009

Recent Posts

hi! , that's my question , How to get List journalarticle filter by Tags ? , I even don't find any relation in the data base , please,

if get all the journalarticles by doing this : JournalArticleLocalServiceUtil.getArticles();

but how Can I filer by the tags !, please , it's urgen , thank you ....
Alessandro Cosenza
RE: How to get List journalarticle filter by Tags ? Asset Publisher
January 26, 2010 12:36 AM
Answer

Alessandro Cosenza

Rank: Junior Member

Posts: 83

Join Date: November 18, 2009

Recent Posts

If you want to use the "tagging" functionality, you should use TagsAsset object.
First you can filter assets by type so you can obtain only asset objects which are journal articles like that
1List<TagsAsset> results = TagsAssetLocalServiceUtil.getAssets(scopeGroupId, new long[]{journalArticleClassNameId}, entryIds, notEntryIds, andOperator, orderByColumn1, orderByColumn2, orderByType1, orderByType2, excludeZeroViewCount, now, now, searchContainer.getStart(), searchContainer.getEnd());


you can see an array of long which contains ids of asset types. In your case you want only
journal articles so
1journalArticleClassNameId = ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class);


this way you got it! you use TagsAsset objects (so you can filter by tags), but you're sure that they're journal articles.
Hope that helps you.
Regards.
erik carl candela
RE: How to get List journalarticle filter by Tags ? Asset Publisher
January 26, 2010 7:13 AM
Answer

erik carl candela

Rank: New Member

Posts: 20

Join Date: April 24, 2009

Recent Posts

Thank you Cosenza,

the service TagsAssetLocalServiceUtil.getAssets has a lot of parameter and I just want to list JournalArticles , how do I avoid filters andOperator, orderByColumn1, orderByColumn2, orderByType1, orderByType2 ? , and I just wnat to filer betwen dates, no just one date like in these service , thank you for your future answer !!!emoticon
Elena Fernandez
RE: How to get List journalarticle filter by Tags ? Asset Publisher
May 16, 2011 5:07 AM
Answer

Elena Fernandez

Rank: New Member

Posts: 17

Join Date: February 7, 2011

Recent Posts

Hi Erik:

I know it's been a long time since you posted your answer, but now I'm with something similar.
Would you mind to explain to me how did you do that finally? It would help me so much.

Thank you very much.
Rajeeva Lochana .B.R
RE: How to get List journalarticle filter by Tags ? Asset Publisher
December 1, 2012 3:34 AM
Answer

Rajeeva Lochana .B.R

Rank: Junior Member

Posts: 58

Join Date: January 4, 2010

Recent Posts

Hi Erik

I am trying the same function, finally i achieved this function.

Liferay version : 6.1.20EE

To get List of journal Article filter by Tags use the below code.

 1
 2public void doView(RenderRequest renderRequest,
 3            RenderResponse renderResponse) throws IOException, PortletException {
 4
 5        ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest
 6                .getAttribute(WebKeys.THEME_DISPLAY);
 7        try {
 8            List<JournalArticle> journalArticles = getArticleByTags(themeDisplay.getScopeGroupId(), "help");
 9            renderRequest.setAttribute("journalArticles", journalArticles);
10        } catch (SystemException e) {
11            e.getMessage();
12        } catch (PortalException e) {
13            e.getMessage();
14}
15
16 public List<JournalArticle> getArticleByTags(long groupId, String tagName)
17            throws PortalException, SystemException {
18        AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
19        long[] anyTagIds = AssetTagLocalServiceUtil.getTagIds(groupId, new String[] { "alllocation", tagName });
20        assetEntryQuery.setAnyTagIds(anyTagIds);
21        List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
22        List<JournalArticle> journalArticleList = new ArrayList<JournalArticle>();
23        for (AssetEntry ae : assetEntryList) {
24                               JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil
25                    .getJournalArticleResource(ae.getClassPK());
26                    JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(groupId,
27                    journalArticleResourceObj.getArticleId());
28            journalArticleList.add(journalArticleObj);
29        }
30        return journalArticleList;
31    }


In jsp file add this
 1
 2<%
 3    List<JournalArticle> journalArticles =(List<JournalArticle>) renderRequest.getAttribute("journalArticles");
 4    for(JournalArticle journalArticle : journalArticles){   
 5%>            
 6    <%=journalArticle.getTitle("en_US") %>
 7<%
 8    }
 9%>



I hope its help in future any one face this similar issues .

Thanks and Regards,
Rajeeva Lochana.B.R