How to sort page provider result by number of downloads ?
Hello,
What is the best solution to sort page provider result by number of downloads ?
Thanks.
Hi LaraGranite,
Thanks for your answer.
I was thinking to to that but I think that the the easiest way to do it is with a listener as said by Rodri.
Here is how I do that :
download-listener-contrib.xml :
<component name="fr.mycompany.listener" version="1.0"> <extension target="org.nuxeo.ecm.core.event.EventServiceComponent" point="listener"> <listener name="downloadListener" async="true" postCommit="true" class="fr.mycompany.listener.DownloadListener"> <event>download</event> </listener> </extension></component>
DownloadListener.java :
package fr.mycompany.listener;import org.nuxeo.ecm.core.event.Event;import org.nuxeo.ecm.core.event.EventContext;import org.nuxeo.ecm.core.event.EventListener;public class DownloadListener implements EventListener { @Override public void handleEvent(Event event) { // Incrementing download count property }}
You can sort the list of results based on a field. That mean, you can order only based on information you have stored. The number of downloads of a document is not stored by default, you will need to store that value in a custom field for example, and then sort results based on that field.
One way of doing it is by creating a listener that increases the value of the custom field every time someone downloads a file.
Hello,
Thanks for your answer.
That's what I was thinking to do with an event listener but I can not find event listener for download event.
Do you have any advice to create a listener on the download event?