Message Boards

Intercept checkout of DLFileEntry with model listener

David Bonomels Bonomels, modified 4 Years ago.

Intercept checkout of DLFileEntry with model listener

New Member Posts: 10 Join Date: 1/10/17 Recent Posts
Hi to everybody,

I need to intercept the checkOut/checkIn operation on a DLFIleEntry.

I tought to use a Listener like this but when I checkout a file, with debug I get "false" instead of expected "true" value!
public MyListener extends BaseModelListener<dlfileentry> {

    @Override
    public void onAfterUpdate(DLFileEntry model) throws ModelListenerException {
        model.isCheckedOut(); // this is false
    }

}
</dlfileentry>

Anyoune can help me?

Thanks in advance!
David
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: Intercept checkout of DLFileEntry with model listener

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey David, 

Not sure if you are stiull stuck on this or not so I thought I might reply all the same. Model listeners are among my favourite things to use, but sometimes it can be confusing to decide between a model listener or a service wrapper. The rule of thumb that I try to use is IF the thing I am changing has a cascading effect on other models in my system, then I use a model listener. If I am trying to intercept the thing that is itself changing then I try to intercept with either a Command override (if there is one) or a ServiceWrapper. 

In your case, I can see that the DLFileEntryLocalService has several checkout methods --
public DLFileVersion cancelCheckOut(long userId, long fileEntryId)
   throws PortalException;

public void checkInFileEntry(long userId, long fileEntryId,
   boolean majorVersion, String changeLog, ServiceContext serviceContext)
   throws PortalException;

public void checkInFileEntry(long userId, long fileEntryId,
   String lockUuid, ServiceContext serviceContext)
   throws PortalException;

public DLFileEntry checkOutFileEntry(long userId, long fileEntryId,
   long fileEntryTypeId, ServiceContext serviceContext)
   throws PortalException;

public DLFileEntry checkOutFileEntry(long userId, long fileEntryId,
   long fileEntryTypeId, String owner, long expirationTime,
   ServiceContext serviceContext) throws PortalException;

public DLFileEntry checkOutFileEntry(long userId, long fileEntryId,
   ServiceContext serviceContext) throws PortalException;

public DLFileEntry checkOutFileEntry(long userId, long fileEntryId,
   String owner, long expirationTime, ServiceContext serviceContext)
   throws PortalException;

.. I would be inclined therefor to define a CustomDLFileEntryLocalServiceOverride class that uses the wrapper class and then @Override the methods you need to "intercept". 

The added benefit here in that, in some cases, you will also have the ServiceContext that will contain a lot of details that you don't readily have available in the ModelListeners. That may not be advantageous for you in this case, but it's something to keep in mind because you may encounter scenarios where it is helpful.
David Bonomels Bonomels, modified 4 Years ago.

RE: Intercept checkout of DLFileEntry with model listener

New Member Posts: 10 Join Date: 1/10/17 Recent Posts
Hi Andrew, sorry about the late of my response.
The problem is that I already use the methods of DLFileEntryLocalService, but for certain reason I need to use the listener for some updates. So when I receive this event I must be sure that is an update of the document  and not the creation of a PWC version from the checkout operations.
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: Intercept checkout of DLFileEntry with model listener

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey David,If you are already using a service wrapper, then why can't you continue to use it for this scenario? Perhaps I am missing something -- can you give me a little more detail (maybe the scenario and execution steps if it's not too much to list out) so that I can better understand the problem you are trying to solve?