フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
ruchi sharma
How to get webcontents with specific tags using dynamic query.
2012/05/03 8:58
答え

ruchi sharma

ランク: Junior Member

投稿: 95

参加年月日: 2011/03/24

最近の投稿

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.
2012/05/04 2:09
答え

ruchi sharma

ランク: Junior Member

投稿: 95

参加年月日: 2011/03/24

最近の投稿

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.
2012/05/04 3:33
答え

Tejas Kanani

ランク: Liferay Master

投稿: 653

参加年月日: 2009/01/06

最近の投稿

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.
2012/05/04 8:46
答え

Prakash Khanchandani

ランク: Expert

投稿: 291

参加年月日: 2011/02/10

最近の投稿

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.
2012/05/04 12:28
答え

Hiral Ramavat

ランク: Regular Member

投稿: 101

参加年月日: 2012/02/13

最近の投稿

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.
2012/05/11 7:46
答え

ruchi sharma

ランク: Junior Member

投稿: 95

参加年月日: 2011/03/24

最近の投稿

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.
2012/05/14 1:25
答え

ruchi sharma

ランク: Junior Member

投稿: 95

参加年月日: 2011/03/24

最近の投稿

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.
2012/05/21 1:34
答え

ruchi sharma

ランク: Junior Member

投稿: 95

参加年月日: 2011/03/24

最近の投稿

Using custom query I solved my problem.
Thanks
Ruchi
Habib Zare
RE: How to get webcontents with specific tags using dynamic query.
2013/04/15 12:06
答え

Habib Zare

ランク: Junior Member

投稿: 43

参加年月日: 2012/10/28

最近の投稿

how?
Javier Vera
RE: How to get webcontents with specific tags using dynamic query.
2014/08/21 14:59
答え

Javier Vera

ランク: New Member

投稿: 18

参加年月日: 2014/08/01

最近の投稿

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!