RE: Document library actions in a scheduler task

Sonia Castro, modified 4 Years ago. New Member Posts: 3 Join Date: 12/3/15 Recent Posts

I need to list document library files and delete some ones periodically.

I have a class that implements MessageListener to run this task, but the scheduler class does not have a request and I don't know how can I get the repositorId without it.

public class MyScheduler implements MessageListener {

    @Override
    public void receive(Message message) throws MessageListenerException {

       ...
       Long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
       Folder folder = DLAppServiceUtil.getFolder(repositoryId, parentFolderId, folderName);
       List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(repositoryId, folder.getFolderId());
       ...

    }
}

Is there any way to get repositoryid ?

Any alternative to run document library actions in sheduler task?

thumbnail
Vilmos Papp, modified 4 Years ago. Liferay Master Posts: 529 Join Date: 10/21/10 Recent Posts

You coud use other service util, or  service reference like DLFileEntryLocalServiceUtil:

https://github.com/vilmospapp/liferay-portal/blob/master/portal-kernel/src/com/liferay/document/library/kernel/service/DLFileEntryLocalServiceUtil.java#L703

There a methods with folderId without repositoryId, you can choose the one that meets your expectations.

Sonia Castro, modified 4 Years ago. New Member Posts: 3 Join Date: 12/3/15 Recent Posts

Thanks for the hint but I don't find any method that fits my requirements in other services.

I need to list files inside a folder and I only have the folder name and the parentFolderID.

 

thumbnail
Sushil Patidar, modified 4 Years ago. Expert Posts: 467 Join Date: 10/31/11 Recent Posts

Hi 

While sending message. In the message payload, it need to be sent .

How you are sending the message.

Regards

Sushil

thumbnail
Sushil Patidar, modified 4 Years ago. Expert Posts: 467 Join Date: 10/31/11 Recent Posts

Hi,

 

Check if you can pass the repositoryid in the message itself.

Hope it helps

 

Regards

Sushil

Sonia Castro, modified 4 Years ago. New Member Posts: 3 Join Date: 12/3/15 Recent Posts

I'm not sending a Message and I think that I can't do it.

My Scheduler is defined in liferay-portlet.xml:

<scheduler-entry>
    <scheduler-description>
        My scheduler to delete files
    </scheduler-description>
    <scheduler-event-listener-class>com.example.MyScheduler</scheduler-event-listener-class>
    <trigger>
        <simple>
            <property-key>10</property-key>
            <time-unit>minute</time-unit>
        </simple>
    </trigger>
</scheduler-entry>

To send the message, I would have to create it dynamically, right?

I want to avoid a programmatically scheduler, because I need to start the scheduler without user interaction.