Search code examples
liferay-6portlet

Unable to get DLFileEntry objects based on expando value in liferay


I have to display DLFileEntry records based on the expando value. I have followed the link https://www.liferay.com/community/wiki/-/wiki/Main/Search+for+objects+by+custom+attributes which I felt was clear enough.

When I implemented the same thing here...I get the 'no records availble'..

The primary key values I am getting from the loop are present in DLFileEntryMetadata but not in DLFileEntry table. So, the default message is getting displayed that no records are available.

    <liferay-ui:search-container delta="5"  emptyResultsMessage=
    "no-records-available-  for-employee"  deltaConfigurable="true" >
     <liferay-ui:search-container-results>
    <%
      long classNameId = ClassNameLocalServiceUtil.getClassNameId(DLFileEntry.class);
    long companyId = PortalUtil.getDefaultCompanyId();
    List<ExpandoValue> values = ExpandoValueLocalServiceUtil.getColumnValues(companyId,
            classNameId, ExpandoTableConstants.DEFAULT_TABLE_NAME, 
            "employeeId",String.valueOf(employeeId), -1, -1); 
    out.println(values.isEmpty());
    List<DLFileEntry> empFiles = new ArrayList<DLFileEntry>();

    DLFileEntry fileEntry;       


    for (int i = 0; i < values.size(); i++) {
     long fileId = values.get(i).getClassPK();
      try{
          out.println(userId);
        fileEntry =  DLAppLocalServiceUtil.getFileEntry(fileId);
        empFiles.add(fileEntry);

      }catch(Exception e ){ 

      }
    }

    searchContainer.setResults(empFiles);
    total = results.size(); 
    pageContext.setAttribute("results", results);
    pageContext.setAttribute("total", total);
    %>
</liferay-ui:search-container-results>
<liferay-ui:search-container-row  className="com.liferay.portlet.documentlibrary.model.DLFileEntry" modelVar="fileEntry"  rowVar="curRow" 
escapedModel="<%=true %>">
    <liferay-ui:search-container-column-text orderable="true" name="Name"
     property="name" />
    <liferay-ui:search-container-column-text orderable="true" name="Extension"
    property="extension"/>
    <liferay-ui:search-container-column-text orderable="true" name="Mime Type"
    property="mimeType"/>
    <liferay-ui:search-container-column-text orderable="true" name="Title"
     property="title"/>
    </liferay-ui:search-container-row>
<liferay-ui:search-iterator/>


Solution

  • the id you get in line:

    long fileId = values.get(i).getClassPK();
    

    is not file id but file version id. Try to replace your line:

     fileEntry =  DLAppLocalServiceUtil.getFileEntry(fileId);
    

    with following one:

     fileEntry = DLAppLocalServiceUtil.getFileVersion(fileId).getFileEntry();
    

    br, Pawel