Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
ruchi sharma
How to get webcontents with specific tags using dynamic query.
May 3, 2012 8:58 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hello Friends,

As in AssetEntryQuery we have a method
assetEntryQuery.setAllTagIds(assetTagIds);
using this method we can get the web contents having the some specific tags.
Due to some requirements I am using dynamic query not the AssetEntryQuery.
Just wondering how can I implement the same thing in dynamic query for getting the webcontents with specific tags.

Thanks
Ruchi
ruchi sharma
RE: How to get webcontents with specific tags using dynamic query.
May 4, 2012 2:09 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

This is my dynamic query for retriving web contents between the two dates :
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(AssetEntry.class, PortalClassLoaderUtil.getClassLoader());
Long[] testGroupId = ArrayUtil.toArray(groupIds);
dynamicQuery.add(PropertyFactoryUtil.forName("groupId").in(testGroupId));
Criterion criterion = null;
criterion = RestrictionsFactoryUtil.between("createDate", startDate, endDate);
dynamicQuery.add(criterion);
dynamicQuery.addOrder(OrderFactoryUtil.desc(orderByColumn1));
dynamicQuery.addOrder(OrderFactoryUtil.asc(orderByColumn2));
List<AssetEntry> results = AssetEntryLocalServiceUtil.dynamicQuery(dynamicQuery, scStart, scEnd);

Now I want to to add one more condition i.e webcontents with specific tags .
Any help would be appreciated.

Thanks
Ruchi
Tejas Kanani
RE: How to get webcontents with specific tags using dynamic query.
May 4, 2012 3:33 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 653

Join Date: January 6, 2009

Recent Posts

Hi Ruchi,

Not sure but check out below post. It might help you.

http://www.liferay.com/community/forums/-/message_boards/message/1817322#_19_message_1817471
Prakash Khanchandani
RE: How to get webcontents with specific tags using dynamic query.
May 4, 2012 8:46 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 291

Join Date: February 10, 2011

Recent Posts

Immediate ways I can think of is to do this:

1) fetch the assetentries for the web-contents using AssetEntryQuery for specific tags.
2) prepare a list of IDs of classPK (this would be web-content IDs) from the assetEntries retrieved.
3) give the list of IDs to your dynamicQuery, something like this: dynamicQuery.in(list_of_webcontent_ids);

OR

1) try to create a dynamicquery with projection on classPK for fetching the assetEntries for particular tags
2) use this as a sub-query with your dynamicquery.

Example of how to use sub-queries:
1) Liferay forum
2) A blog

Hope this helps.
Hiral Ramavat
RE: How to get webcontents with specific tags using dynamic query.
May 4, 2012 12:28 PM
Answer

Hiral Ramavat

Rank: Regular Member

Posts: 101

Join Date: February 13, 2012

Recent Posts

Hi,

You can not pass tag name directly to the argument to get the list of web content with specific tags.

It is the join query of journalarticle, tagasset, tagsassets_tagsentries and tagsentry tables.

First you need to get the tag id from the tagsentry table with specific tag name.
Then, get the assetId from the tagsassets_tagsentries which is the mapping table.
And map that assetId from the tagasset table to the journalarticle table. (journalarticle resourceprimKey is map to the ClassPK of the tagsasset)

Here this join query is regarding the Liferay 5.2.3.

Thanks,
Hiral
ruchi sharma
RE: How to get webcontents with specific tags using dynamic query.
May 11, 2012 7:46 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Thanks Tejas,Prakash and Hiral for your help.

After going through all your responses, I got an idea how to write the query.

1.getting the asset tag id from AssetTag table
DynamicQuery dynamicQueryTagId = DynamicQueryFactoryUtil.forClass(AssetTag.class, "assettag");
dynamicQueryTagId.setProjection(ProjectionFactoryUtil.property("assettag.classPK"));
dynamicQueryTagId.add(PropertyFactoryUtil.forName("assettag.name").in(tagNames));
List<AssetTag> assetTagsList = new ArrayList<AssetTag>();
assetTagsList = AssetTagLocalServiceUtil.dynamicQuery(dynamicQueryTagId);
2.Now I want to retrieve the entry id's from "assetentries_assettags" table which is the mapping table corresponding to the fetched tagid's list i.e assetTagsList .
here I am stuck how to get the entry ids coresponding to the tag ids, how to write the dynamic query for that.

3.Finally after getting the entry id's list I get the date from AssetEntry table.
This is what i am thinking for getting the webcontents with specific tags using dynamic query.
Thanks
Ruchi
ruchi sharma
RE: How to get webcontents with specific tags using dynamic query.
May 14, 2012 1:25 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hello ,
How to make a join with AssetTag, AssetEntry and assetentries_assettags(mapping table) tables using a dynamicquery.
Is it possible??
Or do I need to use custom query??
Any help would be appreciated.
Thanks
Ruchi
ruchi sharma
RE: How to get webcontents with specific tags using dynamic query.
May 21, 2012 1:34 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Using custom query I solved my problem.
Thanks
Ruchi
Habib Zare
RE: How to get webcontents with specific tags using dynamic query.
April 15, 2013 12:06 PM
Answer

Habib Zare

Rank: Junior Member

Posts: 43

Join Date: October 28, 2012

Recent Posts

how?
Javier Vera
RE: How to get webcontents with specific tags using dynamic query.
August 21, 2014 2:59 PM
Answer

Javier Vera

Rank: New Member

Posts: 18

Join Date: August 1, 2014

Recent Posts

yop, i can imagine this is a very freaking late reply but then again..
if you have added tags to a custom service.xml and you want to list them all on your page so you can start figuring how to filter you can use the following queries..

 1
 2    public List<AssetTag> _getTagsForClass() throws SystemException{
 3        long classNameId = PortalUtil.getClassNameId(<yourCustomClassInterface>.class.getName());
 4        DynamicQuery _queryT = DynamicQueryFactoryUtil.forClass(AssetEntry.class);
 5        _queryT.add(PropertyFactoryUtil.forName("classNameId").eq(classNameId));
 6        List<AssetTag> lstAssetTags = new ArrayList<AssetTag>();
 7        List<AssetEntry> lstAssetEntry = assetEntryLocalService.dynamicQuery(_queryT);
 8        //List<GmdContent> lstFull = this._getAllMarketForRole(iUser);
 9        for (AssetEntry assetEntry : lstAssetEntry) {
10            for (AssetTag assetTag : (AssetTagLocalServiceUtil.getEntryTags(assetEntry.getPrimaryKey()))) {
11                if(!(lstAssetTags.stream().filter(obj -> obj.getPrimaryKey() == assetTag.getPrimaryKey()).count() > 0))
12                    lstAssetTags.add(assetTag);
13            }
14        }
15        return lstAssetTags;   
16    }


if you have how to get stuff from the tag please reply. peace!