Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andrea Baglio
get metadata form fileEntry
May 30, 2012 4:57 AM
Answer

Andrea Baglio

Rank: New Member

Posts: 3

Join Date: May 30, 2012

Recent Posts

Hi,
i've created a new document type and a metadata set throug the Documents and media plugin. Then i've created a new document. Now i would like to access to my custom metadata using Velocity variables in my theme template.
Googling and searching on your forum, i've produced this non-working code:

#set($service = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
#set($metadata = $serviceLocator.findService("com.liferay.portlet.dynamicdatamapping.service.DDMStructureLocalService"))
#set($metadata2 = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryMetadataLocalService"))

#set($gid = $getterUtil.getLong($request.get("theme-display").get("scope-group-id")))

$service.getBeanIdentifier()<br>

#set($doc = $fileSelection.getData())

#set ($fileTitle = "target_file")

#set ($tmp = {})
#set ($decoder = $tmp.class.forName("java.net.URLDecoder").newInstance())

#set ($fileTitle = $decoder.decode($fileTitle, "UTF-8"))

#set ($dlService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
#set ($fileEntry = $dlService.getFileEntry($gid, $fid, $fileTitle))

$fileEntry

#*{uuid=87dd34ac-f91d-4ad9-97ae-88cb27064b30, fileEntryId=12614, groupId=88, companyId=1, userId=2, userName=Test Test, versionUserId=2, versionUserName=Test Test, createDate=2012-05-30 11:33:56.974, modifiedDate=2012-05-30 11:33:56.974, repositoryId=88, folderId=0, name=201, extension=jpg, mimeType=image/jpeg, title=target_file, description=, extraSettings=, fileEntryTypeId=12613, version=1.0, size=8864, readCount=1, smallImageId=0, largeImageId=0, custom1ImageId=0, custom2ImageId=0} *#


#set($ddmstruct = $metadata.getDLFileEntryTypeStructures(12613))
#set($fileVersionId=$fileEntry.getFileVersion().getFileVersionId())
#set($structureId = $ddmstruct.getStructureId())
$metadata2.getFileEntryMetadata($structureId,$fileVersionId)

Everything works good instead last row, where the engine call the toString method on it and print out the row as is.

Any hints? thanks
Ketan Savaliya
RE: get metadata form fileEntry
December 18, 2012 3:56 AM
Answer

Ketan Savaliya

Rank: Junior Member

Posts: 77

Join Date: March 3, 2011

Recent Posts

Hi There,

below is some code statement that is help you to get dlfile metadata in your template.


#set ($dlService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
#set($metadata2 = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryMetadataLocalService"))
#set($type = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryTypeLocalService"))
#set($gid = $getterUtil.getLong($request.get("theme-display").get("scope-group-id")))


---Start---
#set($fileEntryTypeId = $fileEntry.getFileEntryTypeId())

#set ($dlFileEntryType = $type.getFileEntryType($fileEntryTypeId))

#set ($ddmStructures = $dlFileEntryType.getDDMStructures())

#foreach ($ddmStructure in $ddmStructures)
#set($dlFileEntryMetadata = $metadata2.getFileEntryMetadata($ddmStructure.getStructureId(), $fileEntry.getLatestFileVersion(true).getFileVersionId()))

<br/>

$dlFileEntryMetadata

#end

---END-----

NOTE : i assume you have $fileEntry objeect in vm
Matej Šípka
RE: get metadata form fileEntry
November 23, 2014 5:37 PM
Answer

Matej Šípka

Rank: New Member

Posts: 7

Join Date: October 20, 2014

Recent Posts

Thank you Ketan, it is a very helpful advice. emoticon
Eric Smith
RE: get metadata form fileEntry
January 5, 2015 2:49 PM
Answer

Eric Smith

Rank: Junior Member

Posts: 63

Join Date: August 28, 2012

Recent Posts

Check Eduardo's post:

https://www.liferay.com/community/forums/-/message_boards/message/27159995

Using getFieldsMap is a lot easier:
fileEntry.getFieldsMap(dlFileVersion.getFileVersionId())