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

