Foros de discusión

Document Library hook

santhosh kumar, modificado hace 11 años.

Document Library hook

New Member Mensajes: 19 Fecha de incorporación: 11/04/11 Mensajes recientes
Hi,

I have a requirement in which i need to update a user defined table on every deletion of Docuement.
In order to achive it ,i used Document libarary Hook but its throwing class not found exception

dl.hook.impl=com.doc.action.Documents


Regards
Santhosh
thumbnail
Prakash Khanchandani, modificado hace 11 años.

RE: Document Library hook

Expert Mensajes: 329 Fecha de incorporación: 10/02/11 Mensajes recientes
I understand why you didn't get any replies, because you didn't mention the requirement in detail.

The filesystem hook can be developed in a variety of ways to customize different aspects of the Document & Media portlet.

But since you requirement is:

santhosh kumar:
Actually my requirement is to update a user defined table on every document delete


we would focus on achieving this.

Here is what I think you should do:
1) For user-defined table I suppose you must have already built code to add,update or delete from the table through service-builder (this is the best way to work with database entities in liferay) or someother way.

2) So now every time a document is deleted you need to update the custom table. So you need to have a method which would be executed when a document is deleted and in that method you can call the code to update your custom table (this code you might have already built).

3) So now there are two ways to hook your functionality when the document is deleted either use ServiceWrappers or you can use ModelListeners.

4) So if you go with the ServiceWrapper way (nice guide for implementing this) then you can either override the DLFileEntryService or DLFileEntryLocalService using the wrapper like DLFileEntryServiceWrapper. Then you can just include the delete() (there might be more than one of them) method and put your custom code in that delete method but don't forget to include the call to super.delete() so that the actual method runs and your custom method also runs.

5) Now if you go the ModelListeners which is better since you won't have to worry about how many method you need to override in a wrapper or which class you need to override etc etc. So here is how to do it with ModelListener.

A short tutorial (assuming you are using Liferay 6+) you can also go through this short guide:
1) Edit your liferay-hook.xml as follows:

<hook>
	<portal-properties>portal.properties</portal-properties>
</hook>


2) Add portal.properties file in src folder of WEB-INF.
3) Edit the portal.properties as follows:
value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileEntry=com.my.custom.hook.CustomFileSystemListener

This property is of the type value.object.listener.[the full path to the Model being added]
4) Now create a class com.my.custom.hook.CustomFileSystemListener and then create a method in this class which implements ModelListener<DLFileEntry>.
5) Override any of the two methods based on your requirement: onAfterRemove(DLFileEntry fileEntry) or onBeforeRemove(DLFileEntry fileEntry).
6) Write your custom code in any of the two methods using the full object of the file entry you are removing.
7) Ok it is done, now please deploy and have fun.

Hope this helps. Let me know if you face any issues.

Note: I could have developed a full-fledged example as you wanted but you know this way it is so much more fun isn't it! (building your own stuff) ... what! No! please don't curse me for this emoticon
santhosh kumar, modificado hace 11 años.

RE: Document Library hook

New Member Mensajes: 19 Fecha de incorporación: 11/04/11 Mensajes recientes
Hi Prakash,

Thank you for providing me a solution.

I tired as per your suggesion but after deleting a document the code which i have written is not working .emoticonemoticon

package com.my.custom.hook;

import com.liferay.portal.ModelListenerException;
import com.liferay.portal.model.ModelListener;
import com.liferay.portlet.documentlibrary.model.DLFileEntry;

public class CustomFileSystemListener implements ModelListener<DLFileEntry> {

@Override
public void onAfterAddAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException {
// TODO Auto-generated method stub

}

@Override
public void onAfterCreate(DLFileEntry arg0) throws ModelListenerException {
// TODO Auto-generated method stub

}

@Override
public void onAfterRemove(DLFileEntry arg0) throws ModelListenerException {
System.out.println("File deletion *****onAfterRemove");

}

@Override
public void onAfterRemoveAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException {
// TODO Auto-generated method stub

}

@Override
public void onAfterUpdate(DLFileEntry arg0) throws ModelListenerException {
// TODO Auto-generated method stub

}

@Override
public void onBeforeAddAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException {
// TODO Auto-generated method stub

}

@Override
public void onBeforeCreate(DLFileEntry arg0) throws ModelListenerException {
// TODO Auto-generated method stub

}

@Override
public void onBeforeRemove(DLFileEntry arg0) throws ModelListenerException {
System.out.println("File deletion *****onBeforeRemove");

}

@Override
public void onBeforeRemoveAssociation(Object arg0, String arg1, Object arg2) throws ModelListenerException {
// TODO Auto-generated method stub

}

@Override
public void onBeforeUpdate(DLFileEntry arg0) throws ModelListenerException {
// TODO Auto-generated method stub

}
}
santhosh kumar, modificado hace 11 años.

RE: Document Library hook

New Member Mensajes: 19 Fecha de incorporación: 11/04/11 Mensajes recientes
Hi Prakash,

Its working as expected.Thank you very much emoticon

There are few more requirements which has to be implemented ,so i will be bugging you. emoticon

Regards
Santhosh
santhosh kumar, modificado hace 11 años.

RE: Document Library hook

New Member Mensajes: 19 Fecha de incorporación: 11/04/11 Mensajes recientes
Hi Prakash,

In new /Edit Document page i need to add two user defined field (not a custom field).
I have need to store these value in separate tables.if it is a custom filed then i can make use of Expando and get those values after CRUD opration.
please help me how to get the user define values ModelListener<DLFileEntry>

ex:
Link: :<input type="text" name="Link" value=""/>

Regards
Santhosh
thumbnail
Prakash Khanchandani, modificado hace 11 años.

RE: Document Library hook

Expert Mensajes: 329 Fecha de incorporación: 10/02/11 Mensajes recientes
wow! You are true to your word ..
so i will be bugging you


In the model Listener you only have access to the DLFileEntry object and nothing else. So I don't think so your ModelListener approach would work in this case. Though if you use custom-attributes (expando) then you can get those values inside the listener method by using fileEntry.getExpandoBridge(). This would be much cleaner approach.

But if you are bent upon going with the approach of using a hook to modify the Document & Media portlet and adding two new fields in the JSP then here is what I think you can do:
1. Use struts-action hook (only available from 6.1+)
2. Override the delete-action through this hook
3. Now you will get your custom fields in the action method you have overriden, since you have control of the action request object.
4. Call your custom method from this action method and then let the control flow to the original struts action method.
5. So with this approach you don't need a ModelListener at all. But the drawback of this approach is that if there is an error while deleting the file then also there would be a record added in your custom table since that was executed before the delete call.

Or another approach I can think of is:
1. Follow the steps till 3 from above
2. Create a custom method which will call the delete method for the file and also call the custom method of yours in a transaction.
3. In this way you can be relieved of the drawback mentioned in the point (5) above.
4. Now with this method you would need to handle the redirect yourself.

I have not analysed much, whatever I thought might be possible I have shared. I have not tried any of the above methods so it might turn out that they may not work.

May be some more experienced member would be able to guide you on this.

Hope this helps
Atul Patel, modificado hace 11 años.

RE: Document Library hook

New Member Mensajes: 18 Fecha de incorporación: 12/01/12 Mensajes recientes
I believe the struts-action hook is available in 6.0 starting with 6.0 sp2...
santhosh kumar, modificado hace 11 años.

RE: Document Library hook

New Member Mensajes: 19 Fecha de incorporación: 11/04/11 Mensajes recientes
Hi,

Thanks guys

Regards
Santhosh
santhosh kumar, modificado hace 11 años.

RE: Document Library hook

New Member Mensajes: 19 Fecha de incorporación: 11/04/11 Mensajes recientes
Hi Prakash,


sorry to bother you once agian.
I have a requirement in DL portlet ,i.e i need to interduce a new menu called 'CHECK' .On click of it i need to display new portlet as a popup.

Please guide me .



Regards
Santhosh
thumbnail
Prakash Khanchandani, modificado hace 11 años.

RE: Document Library hook

Expert Mensajes: 329 Fecha de incorporación: 10/02/11 Mensajes recientes
This is not related to this topic, it would be good if you created a new thread and gave the relevant tags.

Will continue in the new thread.

Thank You
santhosh kumar, modificado hace 11 años.

RE: Document Library hook

New Member Mensajes: 19 Fecha de incorporación: 11/04/11 Mensajes recientes
Hi Prakash,


I have moved it to new thread.Please find the link.


https://www.liferay.com/community/forums/-/message_boards/message/18938876


Regards
Santhosh
santhosh kumar, modificado hace 11 años.

RE: Document Library hook

New Member Mensajes: 19 Fecha de incorporación: 11/04/11 Mensajes recientes
Hi Prakash,

I have another requirement which is related to DL.
I as mentioned earlier i need to introduce new fields to Add/Edit document entry.As per your suggestion i have used customfields and its working fine,the problem is i need to display only one field at different location.For ex:URL is a customfield which should appear on the right corner of the Add/Edit document entry rest of the customfield should appear by the way it is defined.

Thanks in advance.


Regards
Santhosh
Alex Voronin, modificado hace 9 años.

RE: Document Library hook

New Member Mensajes: 17 Fecha de incorporación: 7/02/13 Mensajes recientes
How do I can get user id which downloads the document in onAfterUpdate?