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.

0 votes

3 answers

1214 views

ANSWER



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    }}
1 votes



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.

1 votes



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?

0 votes



Hi Yvan, if you haven't found a solution for this, my advice is to try to track the downloads by restricting them to a custom user action, so that users can only download by clicking this particular custom download button. Then you can attach a counter to that custom user action.
07/09/2019