RE: How search DLFileEntry/DLFileVersion with specific metadata values?

thumbnail
Marco Azzalini, modified 6 Years ago. Regular Member Posts: 146 Join Date: 11/18/14 Recent Posts
Hi, I have a text field in my custom type that it is not indexed.
Is it possible to issue a query (Dynamic query) based on that field? 

I mean something similar to this (pseudo-)code:
DynamicQuery q=DynamicQueryFactoryUtil.forClass(DLFileVersion.class);
q.add(PropertyFactoryUtil.forName("my-custom-field").like(likeCriteria));
List<dlfileversion> fvList = DLFileVersionLocalServiceUtil.dynamicQuery(q);</dlfileversion>
If not, how can I search for those documents?

thanks in advance,
Marco
thumbnail
Jorge Díaz, modified 6 Years ago. Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Hi Marco,

DLFileEntry metadata is not stored in same table, so it is not possible to do that dynamic query.

You can query the search index or you have to query the tables were data is stored.

More information see following links:
thumbnail
Marco Azzalini, modified 6 Years ago. Regular Member Posts: 146 Join Date: 11/18/14 Recent Posts
Jorge DíazHi Marco,

DLFileEntry metadata is not stored in same table, so it is not possible to do that dynamic query.

You can query the search index or you have to query the tables were data is stored.

More information see following links:


Hi Jorge, thank you very much for your suggestions. Unfortunately that field is not indexed so I can't use the the indexer.
Another approach I am trying is to query the ddmcontent.xml column where the metadata are stored, this works fine and I am able to get the ddmContent ids but my second query on DLFileEntryMetadata:

DynamicQuery q=DynamicQueryFactoryUtil.forClass(DLFileEntryMetadata.class);
q.add(PropertyFactoryUtil.forName("ddmstorageid").in(ddmContentsIdsArray));
List<dlfileentrymetadata> fileEntryMetadataList= DLFileEntryMetadataLocalServiceUtil.dynamicQuery(q);</dlfileentrymetadata>

fails raising this exception (??)

org.hibernate.QueryException: could not resolve property: ddmstorageid of: com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataImpl

Do you have any idea why the ddmstorageid property is not found?

My last chance could be process a large bunch of FileVersions and analyze their FieldMaps but I would really prefer to be able to make Database engine do the work for me ;-)
​​​​​​​

regards,
Marco
thumbnail
Jorge Díaz, modified 6 Years ago. Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Hi Marco,

I think you have some problem with classloaders.
See following link: https://community.liferay.com/forums/-/message_boards/message/98752117#_com_liferay_message_boards_web_portlet_MBPortlet_message_92981243


Try replacing DynamicQueryFactoryUtil.forClass({className}.class) with
{className}LocalServiceUtil.dynamicQuery()
That will avoid classloader issues

For examine, in case of DLFileEntryMetadata, replace DynamicQueryFactoryUtil.forClass(DLFileEntryMetadata.class) with:
DLFileEntryMetadataLocalServiceUtil.dynamicQuery()

More info see:
thumbnail
Marco Azzalini, modified 6 Years ago. Regular Member Posts: 146 Join Date: 11/18/14 Recent Posts
Hi Jorge, I did what you suggested me and now my code is:
q=DLFileEntryMetadataLocalServiceUtil.dynamicQuery();
q.add(PropertyFactoryUtil.forName("ddmstorageid").in(ddmContentsIdsArray));
List<dlfileentrymetadata> fileEntryMetadataList= DLFileEntryMetadataLocalServiceUtil.dynamicQuery(q);</dlfileentrymetadata>

but the same exception is raised :-(
I did also more investigation and the error occours with any property so I am agree with you that the problem could be something related with class loading but I really can't figure out  what difference could be between DDMContent (where the same query run smootly) and DLFileentryMetadata ...

This is really weird...
thumbnail
Jorge Díaz, modified 6 Years ago. Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Did you tried using camel case in the property name?

I mean to use "ddmStorageId" instead of "ddmstorageid"
thumbnail
Marco Azzalini, modified 6 Years ago. Regular Member Posts: 146 Join Date: 11/18/14 Recent Posts
No, never tried before...

but same result  :-(

SystemException: org.hibernate.QueryException: could not resolve property: ddmStorageId of: com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataImpl
thumbnail
Jorge Díaz, modified 6 Years ago. Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Hi Marco,

com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataImpl extends com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl


I have checked that class and it seems property is called DDMStorageId,  with DDM in uppercase, see:
Can you try using that property name?

I hope that solves your problem, as I am running out of ideas.

In case that doesn't solve your issue, can you attach your whole log file with the error?

Regards,
Jorge Díaz
thumbnail
Marco Azzalini, modified 6 Years ago. Regular Member Posts: 146 Join Date: 11/18/14 Recent Posts
Jorge DíazHi Marco,

com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataImpl extends com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl


I have checked that class and it seems property is called DDMStorageId,  with DDM in uppercase, see:
Can you try using that property name?

I hope that solves your problem, as I am running out of ideas.

In case that doesn't solve your issue, can you attach your whole log file with the error?

Regards,
Jorge Díaz
Jorge, with DDMStorageId it works!!

I think this should be definly better documented, but thank you very much for all your support! 

regards,
Marco