0

I have a problem with Dynamic Query in Liferay 6. I'm trying to make a query to get images (from the Liferay Documents and Media repository) that have a title determined, are in a folder specific, and that are in a particular category.

For the query to get the images that have a title and are in a folder specific, I have this:

...
DynamicQuery dynamicQueryFile = DynamicQueryFactoryUtil.forClass(DLFileEntry.class);
dynamicQueryFile.add(RestrictionsFactoryUtil.eq("groupId", groupId) );
dynamicQueryFile.add(RestrictionsFactoryUtil.ilike("title", "%"+titlefilter+"%") );
dynamicQueryFile.add(RestrictionsFactoryUtil.in("folderId", toArray(folders)));

List resultsFiles = new ArrayList();                    

resultsFiles.addAll(DLFileEntryLocalServiceUtil.dynamicQuery(dynamicQueryFile));

This works!.

For the query to get the images that are in a particular category, I have this:

...
AssetEntryQuery queryCategoriesFilter = new AssetEntryQuery();
long[] groupIds = {groupId};
queryCategoriesFilter.setGroupIds(groupIds);
ClassName nameClass = ClassNameLocalServiceUtil.getClassName(DLFileEntry.class.getName());
long classNameIdDLFileEntry = nameClass.getClassNameId();
long[] types = {classNameIdDLFileEntry};
queryCategoriesFilter.setClassNameIds(types);
queryCategoriesFilter.setAllCategoryIds(StringtoLongArray(categoryIds));
List<AssetEntry> results = AssetEntryLocalServiceUtil.getEntries(queryCategoriesFilter);

This works!.

And now, I need to combine the results of two queries, but as one of the results is with DynamicQuery and the other is with AssetEntryQuery, them I don't know how to do this.

It is possible to make two queries only with DynamicQuery? => How do I add the restrictions of the categories?

It is possible to make two queries only with AssetEntryQuery? => How do I add the restrictions of the title and folder?

user998871
  • 113
  • 1
  • 1
  • 13
  • 1
    Can you have assetEntryQuery to filter "classpk" based on title and asset-categories and then filter this "classpk"[using in clause with fileEntryID] using dynamicQuery with constraint of folder filtration ? – Pankaj Kathiriya Feb 25 '14 at 06:35
  • Hi Pankaj Kathiriya!. Please, can you put an example with code? – user998871 Feb 25 '14 at 08:56
  • 1
    You have already provided code snippet here. I missed that you have to create list of classpk from AssetEntryQuery's result you have written and then use in clause in dynamicQuery. For example in your case assetEntryIds are list of classpk you got from assetEntryQuery, then use below code `dynamicQueryFile.add(RestrictionsFactoryUtil.in("fileEntryId", assetEntryIds))` – Pankaj Kathiriya Feb 25 '14 at 09:04
  • But how can I get the list of classpk from AssetEntryQuery's result?. This is the part of code that I need. I don't is how to get the list assetEntryIds from variable 'result' (List). – user998871 Feb 25 '14 at 09:24
  • You can simply iterate over list using for loop and make other list of classpk – Pankaj Kathiriya Feb 25 '14 at 10:29

0 Answers0