[CLOSED] How can I reference DLFile custom data in ADT?

thumbnail
Mirto Silvio Busico, modified 8 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts
The thread continues at
https://web.liferay.com/community/forums/-/message_boards/message/82458841


I have the problem that I am not able to reference document type custom metadata fields.

In Content -> Documents and Media I have defined a new document type (eg MIO) with two metadata fields (eg MIOUsage and MIONotes).

In an asset publisher that displays only MIO document type I was able to define an ADT that displays Name, description and small image; but Iwas not able to reference the two custom fields.

I tried
${assetRenderer.getMiousage()!"xxx"}

which gives an "evaluated to null or missing" error

and
${entry.getMiousage()!"xxx"}

which gives the same error

How can I refer to metadata fields defined for a document type?
thumbnail
Mirto Silvio Busico, modified 8 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts
One step ahead.
Inserting this code in ADT

<#assign className = assetRenderer.getClassName()!"x" />
<#if className == "com.liferay.document.library.kernel.model.DLFileEntry">

<#assign metaf = stringUtil.split(metadataFields) !"x" />
<#list metaf as metaf1>
    ${metaf1}
<!--#list-->

        <!--#if-->


I can list the metadata thea are enabled in the Asset Publisher configuration

The document is a DLFile so I changed the thread title

Still I don't know how to reference the custom data.

Seems I have to use DLFileEntryLocalServiceUtil but I don't know how
thumbnail
Mirto Silvio Busico, modified 8 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts
I've found an old article at http://platinumbed-liferay.blogspot.ch/2014/12/application-display-template-documents.html

I've put
freemarker.engine.restricted.variables=

in portal.properties. Then tried this code:

&lt;#if entries?has_content&gt;
	&lt;#list entries as curEntry&gt;
		${curEntry.getTitle(locale)}
&lt;#assign dlFileEntryService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService")&gt;
<hr>
	<!--#list-->
<!--#if-->


But I receive the error that serviceLocator is not found

The following has evaluated to null or missing:
==&gt; serviceLocator  [in template "20116#20160#66884" at line 5, column 31]


Anyone knows how to manage this error?
thumbnail
Mirto Silvio Busico, modified 8 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts
A little step ahead.
Trying to follow the instructions at http://platinumbed-liferay.blogspot.it/2014/12/application-display-template-documents.html (that is for LR 6)
and https://web.liferay.com/it/community/forums/-/message_boards/message/73391506?_19_threadView=flat (to enable serviceLocator)

I came up with this adt:
&lt;#if entries?has_content&gt;
	&lt;#list entries as entry&gt;
        &lt;#assign curFileEntry = entry /&gt;
        &lt;#assign assetRenderer = curFileEntry.getAssetRenderer() /&gt;
        &lt;#assign className = assetRenderer.getClassName()!"x" /&gt;
        &lt;#if className == "com.liferay.document.library.kernel.model.DLFileEntry"&gt;
            &lt;#assign dlFileEntryService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")&gt;
            ${dlFileEntryService  }<br>
            &lt;#assign xx = curFileEntry.getFileEntryId() &gt;
            &lt;#assign dlFileEntry = dlFileEntryService.getFileEntry(xx)&gt;
        <!--#if-->
	<!--#list-->
<!--#if-->


This gives the error
The following has evaluated to null or missing:
==&gt; curFileEntry.getFileEntryId  [in template "20116#20160#66884" at line 9, column 27]

on getFileEntryId

Any hint on how to convert the code in the blog to LR 7?
thumbnail
Mirto Silvio Busico, modified 8 Years ago. Regular Member Posts: 240 Join Date: 1/18/12 Recent Posts
Another step ahead.

Now the problem is that entry.getExpandoBridge.getAttributeNames() returns an empty string

Here the code I used in the Asset Publisher ADT for a document type called "MIO" with two custom field: MIOUsage and MIONotes.

The code:
&lt;#if entries?has_content&gt;
	&lt;#list entries as entry&gt;
        &lt;#assign assetRenderer = entry.getAssetRenderer() /&gt;
        &lt;#assign entryTitle = htmlUtil.escape(assetRenderer.getTitle(locale)) /&gt;
        TITLE: ${entryTitle} <br>
        &lt;#assign className = assetRenderer.getClassName()!"x" /&gt;
        CLASSNAME: ${className} <br>
        &lt;#if className == "com.liferay.document.library.kernel.model.DLFileEntry"&gt;
            &lt;#assign myyy = entry.getExpandoBridge() /&gt;
            EXPANDOBRIDGE: ${myyy.toString()} <br>
            &lt;#assign yyy = myyy.getAttributeNames() /&gt;
            LIST ATTRIBUTES: ${yyy.toString() } <br>
            &lt;#list yyy&gt;
                &lt;#items as y&gt;
                    NAME ATTRIBUTE: ${y} <br>
                <!--#items-->
            &lt;#else&gt;
                THERE ARE NO ATTRIBUTE NAMES <br>
            <!--#list-->
            &lt;#assign xxx = myyy.getAttribute("	MIOUsage",false) !"FIELD NOT FOUND" /&gt;
            EXPANDOBRIDGE: MIOUsage-fieldname value = ${xxx} <br>
            &lt;#assign xxxl = myyy.getAttribute("	Usage",false) !"FIELD NOT FOUND" /&gt;
            EXPANDOBRIDGE: MIOUsage-label value = ${xxxl} <br>
        &lt;#else&gt;
            It is NOT a DLFileEntry
        <!--#if-->
        <hr>
	<!--#list-->
<!--#if-->


The result for an enty with all fields filled:
TITLE: a_few_oh_sht_situations_640_27.jpg
CLASSNAME: com.liferay.document.library.kernel.model.DLFileEntry
EXPANDOBRIDGE: com.liferay.portlet.expando.model.impl.ExpandoBridgeImpl@aa725
LIST ATTRIBUTES: java.util.Collections$3@3a4ee3aa
THERE ARE NO ATTRIBUTE NAMES
EXPANDOBRIDGE: MIOUsage-fieldname value = FIELD NOT FOUND
EXPANDOBRIDGE: MIOUsage-label value = FIELD NOT FOUND 


I tried to get field names and it returns an empty list.
I tried to access the fields with getAttribute using the field name or the field label: nothing is returned

How can I use getExpandoBridge.getAttributeNames() to get the attibute names?
ildar sl, modified 5 Years ago. Regular Member Posts: 158 Join Date: 12/12/11 Recent Posts
<#list entries as entry>
    <#assign
        entry = entry
        assetRenderer = entry.getAssetRenderer()
        entryTitle = htmlUtil.escape(assetRenderer.getTitle(locale))
        viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, assetRenderer, entry, !stringUtil.equals(assetLinkBehavior, "showFullContent"))
        className = assetRenderer.getClassName()!"x"
        dlFileEntryId = assetRenderer.getClassPK()
        fileEntry = DLAppLocalServiceUtil.getFileEntry(dlFileEntryId)
        fileVersion = fileEntry.getLatestFileVersion()
    />
    <#if className == "com.liferay.document.library.kernel.model.DLFileEntry">
        ${fileEntry.getExpandoBridge().getAttribute("nametext")}<br/>
    </#if>
</#list>