留言板

getting value from DLFileEntry fieldsMap

thumbnail
Jack Bakker,修改在9 年前。

getting value from DLFileEntry fieldsMap

Liferay Master 帖子: 978 加入日期: 10-1-3 最近的帖子
what would be the most direct way to get the "captchaValue" that I am logging in the below ?


            long globalGroupId = (GroupLocalServiceUtil.getCompanyGroup(PortalUtil.getDefaultCompanyId())).getGroupId();
            long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

            Folder folder = DLAppLocalServiceUtil.getFolder(globalGroupId, parentFolderId, dlFolderName);
            long repositoryId = globalGroupId;
            //List<fileentry> fileEntries = DLAppServiceUtil.getFileEntries(repositoryId, folder.getFolderId());
            List<dlfileentry> fileEntries = DLFileEntryLocalServiceUtil.getFileEntries(globalGroupId,folder.getFolderId());

            int randId = new Random().nextInt(fileEntries.size());

            DLFileEntry fileEntry = fileEntries.get(randId);

            Map fieldsMap = fileEntry.getFieldsMap(fileEntry.getFileVersion().getFileVersionId());

            Set<string> keys = fieldsMap.keySet();
            for(String key : keys){
                log.info("key: " + key);
                Collection<fields> fields = fieldsMap.values();
                for(Fields curFields : fields){
                    Field curField = curFields.get("captchaValue");
                    log.info("value: " + curField.getValue());
                }
            }
</fields></string></dlfileentry></fileentry>
thumbnail
David H Nebinger,修改在9 年前。

RE: getting value from DLFileEntry fieldsMap

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
Jack Bakker:

Map fieldsMap = fileEntry.getFieldsMap(fileEntry.getFileVersion().getFileVersionId());

Set<String> keys = fieldsMap.keySet();

// for each key in the map
for(String key : keys){
log.info("key: " + key);
Collection<Fields> fields = fieldsMap.values();
// for each field in the map
for(Fields curFields : fields){
Field curField = curFields.get("captchaValue");
log.info("value: " + curField.getValue());
}
}


Well it won't be through the double iteration... Isn't it just:


Fields fields;
Field field;
for (String key : keys) {
  fields = fieldsMap.get(key);
  field = fields.get("captchaValue");
  if (field != null) {
    // have value
  }
}


I mean, maybe I'm missing something not included in the context?
thumbnail
Jack Bakker,修改在9 年前。

RE: getting value from DLFileEntry fieldsMap

Liferay Master 帖子: 978 加入日期: 10-1-3 最近的帖子
It is not iterating over Set or Collection that is the challenge... my original post is intentionally coding-verbose as I learn/share more about Liferay 6.2 documents and media including getting values per metadata fields of a custom Document Type.

Really, I am looking for less lines of code (sets/collection iteration aside for the moment) to get such values which will be useful as number of fields for a Document Type increases.

As a related but somewhat separate is that I read it is better to use DLAppServiceUtil so to cater to multiple types of repositories. However I commented out using that Util because the implementation of FileEntry returned is LiferayFileEntry and I needed a DLFileEntry to get field values.

I see posts on ADT/freemarker to get at the same data, yet given I am new at this, I am finding best practices in this area elusive.
Abdul Kareem,修改在8 年前。

RE: getting value from DLFileEntry fieldsMap

Junior Member 帖子: 30 加入日期: 14-9-4 最近的帖子
Hi Jack,

What is capchavalue in this "Field curField = curFields.get("captchaValue");" statement?

Thanks,
Abdul
thumbnail
David H Nebinger,修改在8 年前。

RE: getting value from DLFileEntry fieldsMap

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
I think Jack had a captcha in his DDL and was getting the value to verify the captcha result.
thumbnail
Jack Bakker,修改在8 年前。

RE: getting value from DLFileEntry fieldsMap

Liferay Master 帖子: 978 加入日期: 10-1-3 最近的帖子
David H Nebinger:
I think Jack had a captcha in his DDL and was getting the value to verify the captcha result.


correct