Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Bernardo Puglia Lima
Dynamic Query order by Custom Field
October 11, 2012 10:40 AM
Answer

Bernardo Puglia Lima

Rank: Junior Member

Posts: 41

Join Date: January 25, 2012

Recent Posts

Hello everyone!

I have the following query:

DynamicQuery dlFileQuery = DynamicQueryFactoryUtil.forClass(DLFileEntry.class, PortalClassLoaderUtil.getClassLoader())
.add(PropertyFactoryUtil.forName("groupId").eq(currentFolder.getGroupId()))
.add(PropertyFactoryUtil.forName("folderId").eq(selectedFolderId));

Which returns me all the files I want. And I have a custom field called "reference-date", searchable by this keyword, for Document Library files which I'd like to use to order the results. Does anyone have any idea on how I could do it? I see there's the ExpandoBridge attribute for DLFileEntry, but I can't figure how to use it properly, or should I make another query for the expando values, or what?

Thanks in advance!
Gustavo Fernandes
RE: Dynamic Query order by Custom Field
October 17, 2012 9:56 AM
Answer

Gustavo Fernandes

Rank: Junior Member

Posts: 26

Join Date: October 3, 2011

Recent Posts

Bernardo Puglia Lima:
Hello everyone!

I have the following query:

DynamicQuery dlFileQuery = DynamicQueryFactoryUtil.forClass(DLFileEntry.class, PortalClassLoaderUtil.getClassLoader())
.add(PropertyFactoryUtil.forName("groupId").eq(currentFolder.getGroupId()))
.add(PropertyFactoryUtil.forName("folderId").eq(selectedFolderId));

Which returns me all the files I want. And I have a custom field called "reference-date", searchable by this keyword, for Document Library files which I'd like to use to order the results. Does anyone have any idea on how I could do it? I see there's the ExpandoBridge attribute for DLFileEntry, but I can't figure how to use it properly, or should I make another query for the expando values, or what?

Thanks in advance!


Hello,

I believe you can use expando brige from the DLFileEntry object. Although i have used it with journal article objects, as the following snippet:

 1JournalArticleResource articleResource  = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(resourcePrimKey);
 2                        JournalArticle article  = JournalArticleLocalServiceUtil.getArticle(articleResource.getGroupId(), articleResource.getArticleId());
 3                        
 4                        if(article.getStructureId().equals(structureId)){
 5                            String articleContent = JournalArticleLocalServiceUtil.getArticleContent(groupId, articleResource.getArticleId(), "", templateId , languageId , themeDisplay);
 6                           
 7                            if(article.getExpandoBridge().getAttribute(customFieldName)!=null ){                               
 8                                System.out.println("toString custom field "+ article.getExpandoBridge().getAttribute(customFieldName).toString());
 9                                    if((Boolean)[b] article.getExpandoBridge().getAttribute(customFieldName)[/b] ){
10                                        resultAllContents.addContent(new WebContentArticle(articleResource.getArticleId(), articleContent));
11                                    } else {
12                                        contentListInactiveCustomField.add(new WebContentArticle(articleResource.getArticleId(), articleContent));
13                                    }
14                            }


Perhaps you could try it, using the DLFileEntry in your case.
Please report your results.
Bernardo Puglia Lima
RE: Dynamic Query order by Custom Field
October 26, 2012 10:14 AM
Answer

Bernardo Puglia Lima

Rank: Junior Member

Posts: 41

Join Date: January 25, 2012

Recent Posts

Hi Gustavo,

The problem is that I don't have access to the ExpandoBridge object when creating the dynamic query, so I can't do something like

1 dlFileQuery.addOrder(OrderFactoryUtil.asc("expandoBridge.referenceDate"));


or something like that. I wish I could, would certainly be the way to go!

I was looking for a way to join the expando tables into the DLFIleEntry, as they are a bunch of tables condensed on the ExpandoBridge object on the result set, which means the query is already executed.

Has anyone ever done it?
Gaurav Jain
RE: Dynamic Query order by Custom Field
October 26, 2012 1:25 PM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 144

Join Date: January 31, 2011

Recent Posts

One other idea: You my also try Boolean Query for this.