Fórumok

Problems in getting MetaData from resource in Document Library

thumbnail
Seref Eksi, módosítva 10 év-val korábban

Problems in getting MetaData from resource in Document Library

New Member Bejegyzések: 2 Csatlakozás dátuma: 2011.03.14. Legújabb bejegyzések
Hi together,

it seems an endless issue how difficult it is, to get MetaData from resources in Document Library.

System:
liferay-portal-6.1.1-ce-ga2 ( standard, without any patches or fixes )
Apache Tomcat/7.0.27
Database: MySQL

Here is my Scenario:

1. in the Document Library I've created a new metadata set for document types , e.g. MyMetaData ( simple fields like 2 inputFields for Text and 2 links to Document Lib )
2. I've created a new document type and assigned MyMetaData to this document type , so every time if a document of the mentioned document type is uploaded, this fields have to be filled from the user
3. for testing purposes I've uploaded three documents and filled out the metadata - works without problems - all metadatas saved for the resources

What i want to do ?
For a given folder id, i wanted to get all ressources of that folder with metadata for each ressource

Problem:
I've not found any working solution how to get metadata

Here is my code:

1. I am defining the folderid of the folder who has the three files with the custom meta data e.g. 20107 and iterating over the fileEntries

@Override
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {

List<FileEntry> dirContent = GeneralUtil.GET_DIRECTORY_CONTENT(renderRequest, 20107);

for (Iterator<FileEntry> iterator = dirContent.iterator(); iterator.hasNext();) {
FileEntry fileEntry = (FileEntry) iterator.next();
GeneralUtil.GET_FILEENTRY_METADATA(fileEntry, renderRequest.getLocale());
}

2. for each resource i am trying to get the custom metadata in my GET_FILEENTRY_METADATA Method but the field variable has always null values in his own table. Why ?

public static void GET_FILEENTRY_METADATA ( FileEntry fileEntry, Locale locale ) {

long fileEntryId = fileEntry.getFileEntryId();
long folderId = fileEntry.getFolderId();
String extension = fileEntry.getExtension();
String title = fileEntry.getTitle();
Folder folder = fileEntry.getFolder();

try {
FileVersion fileVersion = fileEntry.getFileVersion();
long fileVersionId = fileVersion.getFileVersionId();

long fileEntryTypeId = 0;

if (fileVersion.getModel() instanceof DLFileVersion) {
DLFileVersion dlFileVersion = (DLFileVersion)fileVersion.getModel();

fileEntryTypeId = dlFileVersion.getFileEntryTypeId();
}


if (fileEntryTypeId > 0) {
try {
DLFileEntryType fileEntryType = DLFileEntryTypeServiceUtil.getFileEntryType(fileEntryTypeId);

List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

for (DDMStructure ddmStructure : ddmStructures) {
Fields fields = null;

try {
DLFileEntryMetadata fileEntryMetadata = DLFileEntryMetadataLocalServiceUtil.getFileEntryMetadata(ddmStructure.getStructureId(), fileVersionId);

//fields tables has always empty/null entries Why ? --> This is my problem !!
fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId());

}
catch (Exception e) {
System.out.println(e);
}

}
}
catch (Exception e) {
System.out.println(e);
}
}



} catch (PortalException e) {
log.error("PortalException getting fileVersion",e);
} catch (SystemException e) {
log.error("SystemException getting fileVersion",e);
}


}
thumbnail
Seref Eksi, módosítva 10 év-val korábban

RE: Problems in getting MetaData from resource in Document Library

New Member Bejegyzések: 2 Csatlakozás dátuma: 2011.03.14. Legújabb bejegyzések
May be someone of you has already tried getting metadata from a resource in document library and could share a working code snippet ?
Pierre Morin, módosítva 10 év-val korábban

RE: Problems in getting MetaData from resource in Document Library

Junior Member Bejegyzések: 70 Csatlakozás dátuma: 2011.05.17. Legújabb bejegyzések
I had the same problem. I wanted to get the "position" field of my document, so I did it (where file is a DLFileEntry object) :


try {
	Map<string, fields> fieldsMap = file.getFieldsMap(file.getLatestFileVersion(true).getFileVersionId());
	Iterator<string> fieldsMapI = fieldsMap.keySet().iterator();
	boolean continuer = true;
	while(fieldsMapI.hasNext()) {
		Fields fields = fieldsMap.get(fieldsMapI.next());
		Iterator<field> fieldsI = fields.iterator();
		while(fieldsI.hasNext()) {
			Field field = fieldsI.next();
			if(field.getDataType().toLowerCase().equals("integer")
					&amp;&amp; field.getName().toLowerCase().equals("position")) {
				String fieldValue = field.getValue().toString();
				if(fieldValue.matches("^[0-9]+$")) {
					position = Integer.parseInt(fieldValue);
					continuer = false;
					break;
				}
			}
		}
		if(!continuer) break;
	}
} catch (Exception e) {
	e.printStackTrace();
}
</field></string></string,>


I hope this would help somebody (I don't think it'll help you, so far after).
thumbnail
Dave Weitzel, módosítva 9 év-val korábban

RE: Problems in getting MetaData from resource in Document Library

Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2009.11.18. Legújabb bejegyzések
were you ever able to solve this?
I am writing an Application Display Template in Freemarker for asset publisher to list documents including custom meta data from the document type record.

From what I can see I have to use StorageEngineUtil but cannot get an instance of it even using utilLocator.

I am not sure what the example posted about fileNtry.getFieldsMap() is about as that doesnt work in Freemarker either but pretty sure it is not getting the DDM data.

Thanks
thumbnail
Tina Agrawal, módosítva 9 év-val korábban

RE: Problems in getting MetaData from resource in Document Library

Expert Bejegyzések: 297 Csatlakozás dátuma: 2008.01.03. Legújabb bejegyzések
I dont see an issue with your code because I have similar code and it works good.
Can you check your db and run the query and see whether you get any records or not.

Tina