Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Andrea Baglio
get metadata form fileEntry
30 de Maio de 2012 04:57
Resposta

Andrea Baglio

Ranking: New Member

Mensagens: 3

Data de entrada: 30 de Maio de 2012

Mensagens recentes

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
18 de Dezembro de 2012 03:56
Resposta

Ketan Savaliya

Ranking: Junior Member

Mensagens: 77

Data de entrada: 3 de Março de 2011

Mensagens recentes

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
23 de Novembro de 2014 17:37
Resposta

Matej Šípka

Ranking: New Member

Mensagens: 7

Data de entrada: 20 de Outubro de 2014

Mensagens recentes

Thank you Ketan, it is a very helpful advice. emoticon
Eric Smith
RE: get metadata form fileEntry
5 de Janeiro de 2015 14:49
Resposta

Eric Smith

Ranking: Junior Member

Mensagens: 64

Data de entrada: 28 de Agosto de 2012

Mensagens recentes

Check Eduardo's post:

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

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