我创建了一个文档类型,并且我使用Asset Publisher来显示这类文档 我想查看与自定义文档关联的值,这是我使用文档库创建的。 用速度做这个的方法是什么?
我找到了这个java代码
long classPK = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK))
long fileEntryTypeId = DLFileVersionLocalServiceUtil.getFileVersion(classPK).getFileEntry().getFileEntryTypeId()
DLFileEntryType dlFileEntryType = DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);
List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures();
DDMStructure ddmStructure = ddmStructures.get(0);
DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.etStructureId(), classPK);
Fields fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId());
String value = GetterUtil.getString(fields.get("radio6255").getValue());
我尝试以速度
进行此操作#set($actualDoc = $curEntry.get(0))
#set($dlFileUtil = $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")))
#set($fileEntry = $dlFileUtil.getFileEntryByUuidAndGroupId($actualDoc.classUuid, $actualDoc.groupId))
#set($fileEntryTypeId = $fileEntry.getFileEntryTypeId())
#set ($dlFileEntryType = $type.getFileEntryType($fileEntryTypeId))
#set ($ddmStructures = $dlFileEntryType.getDDMStructures())
#set ($ddmStructure = $ddmStructures.get(0))
#set($dlFileEntryMetadata = $metadata2.getFileEntryMetadata($ddmStructure.getStructureId(), $fileEntry.getLatestFileVersion(true).getFileVersionId()))
##set ($storageUtil = $portal.getClass().forName("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil").newInstance())
#set($storageUtil = $serviceLocator.findService("com.liferay.portlet.dynamicdatamapping.storage.StorageEngineUtil"))
#set($dDMStorageId = $dlFileEntryMetadata.getDDMStorageId())
#set($fields = $storageUtil.getFields($dDMStorageId))
<br> fields> $fields
但$storageUtil.getFields($dDMStorageId))
为空
答案 0 :(得分:2)
我建议你尝试一种避免使用StorageEngineUtil
的不同方法。
我的模板是用Freemarker编写的,但我相信你可以快速将它翻译成Velocity语法。
第一个函数将DLFileEntry
的实例作为参数并返回字段map:
<#function getDLFileEntryFieldsMap dlFileEntry>
<#assign fileVersionId = dlFileEntry.getLatestFileVersion(true).getFileVersionId() />
<#return dlFileEntry.getFieldsMap(fileVersionId) />
</#function>
返回的字段映射是Map<String, com.liferay.portlet.dynamicdatamapping.storage.Fields>
的实例。
第二个函数在字段映射中搜索给定字段:
<#function getDLFileEntryFieldValue fieldsMap fieldName>
<#list fieldsMap?keys as structureKey>
<#list fieldsMap[structureKey].iterator() as field>
<#if field.getName() = fieldName>
<#return field.getValue()>
</#if>
</#list>
</#list>
<#return "">
</#function>
该函数遍历字段映射中的结构,并尝试查找包含给定字段的第一个结构。
答案 1 :(得分:2)
我已经使用文档实现了portlet操作......也许部分源代码可以帮助您解决这个问题。
收集所有文件结构:
public Set<DDMStructure> findStructureOfEntry(DLFileEntry entry) {
LOGGER.log(Level.INFO, "Finding file entry structures.");
Set<DDMStructure> dLMSDddmStructures = new HashSet<DDMStructure>();
DLFileEntryType type = null;
try {
type = DLFileEntryTypeLocalServiceUtil.getFileEntryType(entry
.getFileEntryTypeId());
} catch (PortalException | SystemException e1) {
LOGGER.log(Level.SEVERE,
"Exception while getting DLFileEntry TYPE." + e1);
e1.printStackTrace();
}
try {
dLMSDddmStructures.addAll(type.getDDMStructures());
} catch (SystemException e) {
LOGGER.log(Level.SEVERE,
"Exception while getting DLFileEntry structures." + e);
e.printStackTrace();
}
LOGGER.log(Level.INFO, "Success.");
return dLMSDddmStructures;
}
现在从结构中获取字段:
Field field;
DLFileEntryMetadata dlFileEntryMetadata = null;
Fields fields = null;
try {
dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil
.getFileEntryMetadata(structure.getStructureId(), entry
.getFileVersion().getFileVersionId());
} catch (PortalException | SystemException e) {
LOGGER.log(Level.SEVERE,
"Exception while getting DLFileEntry metadata sets."
+ e);
e.printStackTrace();
}
try {
fields = StorageEngineUtil.getFields(dlFileEntryMetadata
.getDDMStorageId());
} catch (StorageException e) {
LOGGER.log(Level.SEVERE,
"Exception while getting fields of DLFileEntry DDMStructures."
+ e);
e.printStackTrace();
}
然后你可以通过它的名字得到你想要的任何字段:
field = fields.get(name);
我认为你的getFileEntryMetadata方法中有错误的参数......那就是它为空的原因。
答案 2 :(得分:1)
我可以使用此Freemarker模板获取自定义文档中自定义字段值的值:
<#assign fileEntry = dlFileEntryService.getDLFileEntryByUuidAndCompanyId(entry.getClassUuid() , entry.getCompanyId() ) />
<#assign fileEntryTypeId = fileEntry.getFileEntryTypeId() />
<#if fileEntryTypeId gt 0 >
<#assign fileEntryType = dlFileEntryTypeService.getDLFileEntryType(fileEntryTypeId) />
<#assign dlFileVersion = dlFileVersionService.getLatestFileVersion(fileEntry.getUserId(), fileEntry.getFileEntryId()) />
<#assign fieldsMap = fileEntry.getFieldsMap(dlFileVersion.getFileVersionId()) />
<#list fieldsMap?keys as structureKey>
<#list fieldsMap[structureKey].iterator() as field>
<#if field.getName() == 'nameOfYourCustomField'>
<#assign nameOfYourCustomField = field.getValue() />
</#if>
</#list>
</#list>
<#-- Print the value of your custom field -->
${nameOfYourCustomField}
</#if>