Forums de discussion

getting value from DLFileEntry fieldsMap

thumbnail
Jack Bakker, modifié il y a 9 années.

getting value from DLFileEntry fieldsMap

Liferay Master Publications: 978 Date d'inscription: 03/01/10 Publications récentes
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, modifié il y a 9 années.

RE: getting value from DLFileEntry fieldsMap

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
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, modifié il y a 9 années.

RE: getting value from DLFileEntry fieldsMap

Liferay Master Publications: 978 Date d'inscription: 03/01/10 Publications récentes
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, modifié il y a 8 années.

RE: getting value from DLFileEntry fieldsMap

Junior Member Publications: 30 Date d'inscription: 04/09/14 Publications récentes
Hi Jack,

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

Thanks,
Abdul
thumbnail
David H Nebinger, modifié il y a 8 années.

RE: getting value from DLFileEntry fieldsMap

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
I think Jack had a captcha in his DDL and was getting the value to verify the captcha result.
thumbnail
Jack Bakker, modifié il y a 8 années.

RE: getting value from DLFileEntry fieldsMap

Liferay Master Publications: 978 Date d'inscription: 03/01/10 Publications récentes
David H Nebinger:
I think Jack had a captcha in his DDL and was getting the value to verify the captcha result.


correct