« Back

Auditing document-downloads via Document Library Record plugin

General Blogs September 9, 2011 By Jonas Yuan

As you have been noticed, the version 6.1 adds a lot of CMS (Document Library) features. The following is a list of these features, not the full list.

  • Capability to manage different document types: basic document, image (Image Gallery is merged into Document Library), video, audio, etc.
  • Providing Dynamic Data List (DDL) and Dynamic Data Mapping (DDM) - see blogs Dynamic Data Lists I and Dynamic Data Lists II
  • Ability to mount different repositories via CMIS (see blogs Mounting Multiple CMIS Repositories on Liferay 6.1)
  • Capability to define custom document types in the runtime
  • Capability to define custom meta-data of document types in the runtime
  • Ability to make custom document types and their meta-data searchable
  • Ability to apply Workflow on document-type-level
  • Ability to set up asset-links among assets (like Blogs Entry, Comments, Message Boards Message, Web Content, Calendar Event, Document Library Document, Wiki Page)
  • And more.

This article will introduce an additiona feature: tracking who downloaded documents in Liferay portal 6.1 via Document Library Record plugin.

Use cases

The plugin (Document Library Record plugin) will consider following use cases.

  • Audit document-downloads: who downloaded the document and when the document got downloaded.
  • Define resources to be audited:  only defined resources will get audited
  • Distinguish auditing condition: trace non-signed-in required resource and trace sign-in required resource 
  • Report document-downloads: reporting by group, by user, by resource instance, by document-type, by date (weekly, monthly, yearly).

Abstracted from the book: Liferay Portal Systems Development (A Liferay cookbook for developers using version 6.1 or above)

Possible implementation

The plugin could be implemented in the following steps

  • Specify two entities for Document Library Record: DLRecord and DLRecordLog.

The entity DLRecord is defined as follows.

<!-- PK fields -->
<column name="definitionId" type="long" primary="true" />
<!-- Audit fields -->
<column name="folderId" type="long" />
<column name="documentType" type="String" />
<column name="companyId" type="long" />
<column name="groupId" type="long" />
<column name="userId" type="long" />
<column name="createDate" type="Date" />
<column name="modifiedBy" type="long" />
<column name="modifiedDate" type="Date" />
<!-- Other fields -->
<column name="name" type="String" />
<column name="title" type="String" />
<column name="signinRequired" type="boolean" />

The entity DLRecordLog is defined as follows.

<!-- PK fields -->
<column name="logId" type="long" primary="true" />
<!-- Audit fields -->
<column name="definitionId" type="long" />
<column name="documentType" type="String" />
<column name="companyId" type="long" />
<column name="groupId" type="long" />
<column name="userId" type="long" />
<column name="createDate" type="Date" />

  • Record document-downloads.

The following is sample code.

try {
DLRecordDefinition dLRecordDefinition =
DLRecordDefinitionLocalServiceUtil.findByF_N(folderId, name);
if (dLRecordDefinition != null) {

ThemeDisplay themeDisplay =
(ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
if (dLRecordDefinition.isSigninRequired()
&& !themeDisplay.isSignedIn()) {
response.sendRedirect(themeDisplay.getURLSignIn());
}
long companyId = themeDisplay.getCompanyId();
long groupId = themeDisplay.getScopeGroupId();
long userId = themeDisplay.getUserId();

DLRecordLogLocalServiceUtil.addDLRecordLog(
dLRecordDefinition.getDefinitionId(), companyId,
groupId, userId);
}
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Results

Here I share a few screenshots from the version 6.1 (revision 88826).

Resource search

Trace definitions

List records

When downloading a document (basic document, image, video, audio, etc.), audit it.

Summary

The plugin provided capability to audit document-downloads. It did work fine in the version 6.1. Of course, the plugin did also work well in the version 6 (like 6.0.6 CE, 6.0 EE SP1, 6.0 EE SP2, etc.). In addition, I would send a ton of thanks to Liferay development team who created the draft version of Document Library Record portlet.

Download URLs

6.0.12

6.0.11

6.0.10

6.0.6

6.1.0

Threaded Replies Author Date
Hey Jonas, is this plugin available to download... James Falkner September 9, 2011 7:01 PM
Hello, I think is wonderful, is here a svn or... Andrés Cerezo September 10, 2011 12:17 AM
Thanks Jonas !!! I think this is nice feature... Jignesh Vachhani September 12, 2011 2:54 AM
@James @Andres, The download link (for both... Jonas Yuan September 12, 2011 5:18 PM
Hi Jonas, Thanks for sharing. Been looking... Pius Onobhayedo September 14, 2011 1:02 AM
Download URL for 6.0.12 is ready. Download... Jonas Yuan September 16, 2011 10:40 AM
Hi Pius, The plugin - a "full featured"... Jonas Yuan September 25, 2011 9:06 PM
[...] Hooks are a feature to catch hold of the... Anonymous November 30, 2011 12:34 PM
mmmh, the download link 6.0.12 links back to... Thomas Adams December 1, 2011 11:22 PM
Hi Tomas, it seems that it is working fine... Jonas Yuan December 2, 2011 11:33 AM
Hello, I was wondering how must I do the... Jordi Buendia December 14, 2011 2:43 AM
Hi Jordi, The same feature (plugin) is... Jonas Yuan December 15, 2011 7:44 AM
Hi, Jonas, This is cool! Do you know when I... Xinsheng Robert Chen February 5, 2012 3:23 PM
Hi Jonas, I can't deploy it succesfully on... Firas BD February 29, 2012 3:38 AM
Hi Firas, the war was generated in the 6.0.12.... Jonas Yuan March 27, 2012 3:09 PM
Hi Jonas, thanks for your reply, really I need... Firas BD March 28, 2012 1:17 AM
Hi Firas, do you use this for your web site /... Jonas Yuan March 28, 2012 1:28 PM
Hi Jonas, yes it is for my Intranet portal... Firas BD March 29, 2012 1:18 AM
Hi Firas, You can drop an email to... Jonas Yuan March 31, 2012 5:17 PM
I guess the download links has been removed :(... lou cat November 28, 2012 2:32 AM

Hey Jonas, is this plugin available to download (either in binary or source code form)?
Posted on 9/9/11 7:01 PM.
Hello, I think is wonderful, is here a svn or something similar of this plugin?
Posted on 9/10/11 12:17 AM in reply to James Falkner.
Thanks Jonas !!!
I think this is nice feature and eager to see ASAP emoticon
Posted on 9/12/11 2:54 AM.
@James @Andres,

The download link (for both 6.0 CE, 6.0 EE ) will be added shortly. The download link would be ready for 6.1 when 6.1 was released.

Thanks

Jonas
Posted on 9/12/11 5:18 PM in reply to Jignesh Vachhani.
Hi Jonas,

Thanks for sharing. Been looking forward to such on LR.
Is the plugin a "full featured" record management system?
Posted on 9/14/11 1:02 AM in reply to Jonas Yuan.
Download URL for 6.0.12 is ready.

Download URLs for 6.0.10, 6.0.11, 6.0.6, and 6.1.0 would be ready in request.
Posted on 9/16/11 10:40 AM in reply to Pius Onobhayedo.
Hi Pius,

The plugin - a "full featured" record management system - is available in the book.

Liferay Portal Systems Development (A Liferay cookbook for developers using version 6.1 or above):
http://www.amazon.com/Liferay-Portal-Systems-Development/dp/1849515980

Tha­nks,

Jonas
Posted on 9/25/11 9:06 PM in reply to Jonas Yuan.
[...] Hooks are a feature to catch hold of the properties and JSP files into an instance of the portal, as if catching them with a hook. Hook plugins are more powerful plugins that come to complement... [...] Read More
Posted on 11/30/11 12:34 PM.
mmmh, the download link 6.0.12 links back to this page,
any ideas?

c. Thomas
Posted on 12/1/11 11:22 PM in reply to .
Hi Tomas, it seems that it is working fine after signed in. Thanks, Jonas
Posted on 12/2/11 11:33 AM in reply to Thomas Adams.
Hello,

I was wondering how must I do the request for the 6.1 plugin, or if it isn't ready for the moment.

Thanks a lot!

Jordi
Posted on 12/14/11 2:43 AM in reply to Jonas Yuan.
Hi Jordi,

The same feature (plugin) is available in the 6.1. Once the 6.1 CE version is ready, you may use this plugin.

Thanks

Jonas
Posted on 12/15/11 7:44 AM in reply to Jordi Buendia.
Hi, Jonas,

This is cool! Do you know when I can download the source code for this? I have tried sourceForge, Liferay download site and Liferay svn.
Posted on 2/5/12 3:23 PM in reply to Jonas Yuan.
Hi Jonas,

I can't deploy it succesfully on Liferay 6.1, I got this error:

Loading file:/D:/Liferay-6.1/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/temp/11-document-­library-record-portlet/WEB-INF/classes/service.properties
11:10:19,405 ERROR [PortletApplicationContext:87] org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Bea
n class [com.liferay.dlrecord.service.impl.DLRecordDefinitionLocalServiceImpl] not found
Offending resource: ServletContext resource [/WEB-INF/classes/META-INF/portlet-spring.xml]
Bean 'com.liferay.dlrecord.service.DLRecordDefinitionLocalService'; nested exception is java.lang.ClassNotFoundException: com.liferay.dlrecord.service
.impl.DLRecordDefinitionLocalServiceImpl
org.springfr­amework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Bean class [com.liferay.dlrecord.service.impl.DLRecor
dDefinitionLocalServiceImpl] not found
Offending resource: ServletContext resource [/WEB-INF/classes/META-INF/portlet-spring.xml]
Bean 'com.liferay.dlrecord.service.DLRecordDefinitionLocalService'; nested exception is java.lang.ClassNotFoundException: com.liferay.dlrecord.service
.impl.DLRecordDefinitionLocalServiceImpl
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFast­ProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java­:85)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDef­initionParserDelegate.java:291)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefi­nitionElement(BeanDefinitionParserDelegate.java:491)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefi­nitionElement(BeanDefinitionParserDelegate.java:396)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefi­nitionElement(BeanDefinitionParserDelegate.java:365)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.proces­sBeanDefinition(DefaultBeanDefinitionDocumentReader.java:25
8)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseD­efaultElement(DefaultBeanDefinitionDocumentReader.java:153)

at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseB­eanDefinitions(DefaultBeanDefinitionDocumentReader.java:132
)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.regist­erBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:
93)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefini­tions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefiniti­ons(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinition­s(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinition­s(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanD­efinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanD­efinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanD­efinitions(AbstractBeanDefinitionReader.java:149)
Posted on 2/29/12 3:38 AM in reply to Xinsheng Robert Chen.
Hi Firas, the war was generated in the 6.0.12. For 6.1, the war has to be re-generated. Please let me know if you still need this plugin for 6.1.

Thanks

Jonas Yuan
Posted on 3/27/12 3:09 PM in reply to Firas BD.
Hi Jonas, thanks for your reply, really I need it but I don't know how to re-generate the plugin for Liferay6.1.

Best Regards,
Firas BD
Posted on 3/28/12 1:17 AM in reply to Jonas Yuan.
Hi Firas, do you use this for your web site / project? if yes, I could generate free WAR for version 6.1.

Thanks

Jonas
Posted on 3/28/12 1:28 PM in reply to Firas BD.
Hi Jonas, yes it is for my Intranet portal project, I need also your help in others issues, could you please send me your email adress, this is my email adress:

zangar.firas@gmail.com

Best Regards,
Firas BD
Posted on 3/29/12 1:18 AM in reply to Jonas Yuan.
Hi Firas,

You can drop an email to jonasliferay@gmail.com.

Thanks

Jonas
Posted on 3/31/12 5:17 PM in reply to Firas BD.
I guess the download links has been removed emoticon
I'd need to do something similar in 6.0.6 CE (well, actually a very basic version) and seeing the code would be useful.
I'd need to do something when a document is downloaded, but I guess the normal methods associated to a Model Listener don't include the simple download...
Posted on 11/28/12 2:32 AM in reply to Jonas Yuan.