There are number of customers who have requirements to start using the audit function, and many of them are concerned it would affect the entire Alfresco repository performance, which maybe true. Actually we don’t have to enable it since most of the user activities are already tracked by the other out of the function named activity_feed. That is already running. I would like to talk about what the differences are, what event items we can get for each of them from the APIs, and Database point of view. And how we should maintain the records to prevent them from having the performance issue.
5. Learn. Connect. Collaborate.
# SiteServiceImpl.java
// Add the user to the new permission group
String newGroup = getSiteRoleGroup(shortName, role, true);
authorityService.addAuthority(newGroup, authorityName);
return null;
...
activityService.postActivity(
ActivityType.SITE_USER_JOINED, shortName,
ACTIVITY_TOOL, getActivityUserData(authorityDisplayName, role)
, authorityName);
1
How to capture the user events
- Audit (Disabled)
Set “Annotation” as @Auditable
# SiteService.java
@Auditable
(parameters = {"shortName", "authorityName", "role"})
void setMembership(String shortName, String authorityName, String role);
- Activity_feed (Running)
It adds the method
acvititySerivce.postActivity
to each action in each Java class.
Event list is predefined in
ActivityType.java
6. Learn. Connect. Collaborate.
How to capture the user events
- Audit (Disabled)
Set “Annotation” as @Auditable
# SiteService.java
@Auditable
(parameters = {"shortName", "authorityName", "role"})
void setMembership(String shortName, String authorityName, String role);
- Activity_feed (Running)
It adds the method
acvititySerivce.postActivity
to each action in each Java class.
Event list is predefined in
ActivityType.java
# SiteServiceImpl.java
// Add the user to the new permission group
String newGroup = getSiteRoleGroup(shortName, role, true);
authorityService.addAuthority(newGroup, authorityName);
return null;
...
activityService.postActivity(
ActivityType.SITE_USER_JOINED, shortName,
ACTIVITY_TOOL, getActivityUserData(authorityDisplayName, role)
, authorityName);
7. Learn. Connect. Collaborate.
The pre-defined events list
public interface ActivityType{
// pre-defined alfresco activity types
public static final String SITE_USER_JOINED = "org.alfresco.site.user-joined";
public static final String SITE_USER_REMOVED = "org.alfresco.site.user-left";
public static final String SITE_USER_ROLE_UPDATE = "org.alfresco.site.user-role-changed";
public static final String SITE_GROUP_ADDED = "org.alfresco.site.group-added";
public static final String SITE_GROUP_REMOVED = "org.alfresco.site.group-removed";
public static final String SITE_GROUP_ROLE_UPDATE = "org.alfresco.site.group-role-changed";
public static final String SUBSCRIPTIONS_SUBSCRIBE = "org.alfresco.subscriptions.subscribed";
public static final String SUBSCRIPTIONS_FOLLOW = "org.alfresco.subscriptions.followed";
public static final String FILE_ADDED = "org.alfresco.documentlibrary.file-added";
public static final String FILE_UPDATED = "org.alfresco.documentlibrary.file-updated";
public static final String FILE_DELETED = "org.alfresco.documentlibrary.file-deleted";
public static final String FILES_ADDED = "org.alfresco.documentlibrary.files-added";
public static final String FILES_UPDATED = "org.alfresco.documentlibrary.files-updated";
public static final String FILES_DELETED = "org.alfresco.documentlibrary.files-deleted";
public static final String FOLDER_ADDED = "org.alfresco.documentlibrary.folder-added";
public static final String FOLDER_DELETED = "org.alfresco.documentlibrary.folder-deleted";
public static final String FOLDERS_ADDED = "org.alfresco.documentlibrary.folders-added";
public static final String FOLDERS_DELETED = "org.alfresco.documentlibrary.folders-deleted";
public static final String FILE_LIKED = "org.alfresco.documentlibrary.file-liked";
public static final String FOLDER_LIKED = "org.alfresco.documentlibrary.folder-liked";
public static final String COMMENT_CREATED = "org.alfresco.comments.comment-created";
public static final String DOCLINK_CREATED = "org.alfresco.doclink.link-created";}
8. Learn. Connect. Collaborate.
#alf_audit_entry
#alf_audit_app
#alf_prop_value
#alf_prop_link
#alf_prop_string_value
#alf_activity_feed
The differences between Audit and Activity_feed
SELECT
entry.id as Id,
entry.audit_time as Time,
user_string.string_value as User,
act_string.string_value as Application,
sv.string_value as Value
FROM alf_audit_entry as entry
INNER JOIN alf_prop_value user_prop ON (entry.audit_user_id = user_prop.id)
INNER JOIN alf_prop_string_value user_string ON ((user_prop.persisted_type = 3 OR user_prop.persisted_type
= 5) AND user_prop.long_value = user_string.id)
INNER JOIN alf_audit_app app ON (entry.audit_app_id = app.id)
INNER JOIN alf_prop_value act ON (app.app_name_id = act.id)
INNER JOIN alf_prop_link pl on (pl.root_prop_id = entry.audit_values_id)
INNER JOIN alf_prop_value pv on (pl.value_prop_id = pv.id)
INNER JOIN alf_prop_string_value act_string ON (act_string.id in (select ALF_PROP_STRING_VALUE.id from
ALF_PROP_STRING_VALUE where string_value like '%/alfresco-access/%'))
LEFT JOIN alf_prop_string_value sv on (sv.id = pv.long_value and (pv.persisted_type = 3 OR pv.persisted_type =
5))
WHERE sv.string_value is NOT NULL
ORDER BY entry.audit_time;
select * from alf_activity_feed where activity_type like '%file-deleted%' and feed_date like '%2018-11-13%'
Complicated Query
Simple Query
- audit
uses multiple database tables
VS
- activity_feed
uses just one table.
9. Learn. Connect. Collaborate.
#alf_audit_entry
#alf_audit_app
#alf_prop_value
#alf_prop_link
#alf_prop_string_value
#alf_activity_feed
The differences between Audit and Activity_feed
SELECT
entry.id as Id,
entry.audit_time as Time,
user_string.string_value as User,
act_string.string_value as Application,
sv.string_value as Value
FROM alf_audit_entry as entry
INNER JOIN alf_prop_value user_prop ON (entry.audit_user_id = user_prop.id)
INNER JOIN alf_prop_string_value user_string ON ((user_prop.persisted_type = 3 OR user_prop.persisted_type
= 5) AND user_prop.long_value = user_string.id)
INNER JOIN alf_audit_app app ON (entry.audit_app_id = app.id)
INNER JOIN alf_prop_value act ON (app.app_name_id = act.id)
INNER JOIN alf_prop_link pl on (pl.root_prop_id = entry.audit_values_id)
INNER JOIN alf_prop_value pv on (pl.value_prop_id = pv.id)
INNER JOIN alf_prop_string_value act_string ON (act_string.id in (select ALF_PROP_STRING_VALUE.id from
ALF_PROP_STRING_VALUE where string_value like '%/alfresco-access/%'))
LEFT JOIN alf_prop_string_value sv on (sv.id = pv.long_value and (pv.persisted_type = 3 OR pv.persisted_type =
5))
WHERE sv.string_value is NOT NULL
ORDER BY entry.audit_time;
select * from alf_activity_feed where activity_type like '%file-deleted%' and feed_date like '%2018-11-13%'
Complicated Query
Simple Query
- audit
uses multiple database tables
VS
- activity_feed
uses just one table.
2
10. Learn. Connect. Collaborate.
Another difference
- Audit
• Filenames, Event Names, Paths, dateTime, UserID.
- activity_feed
• Filenames, Event Names, Paths, dateTime, UserID, NodeRefs
VS
select activity_type as EventName, feed_date as dateTime, feed_user_id as UserID, activity_summary as nodeRef from alf_activity_feed where feed_date like '%2018-11-13%';
+--------------------------------------------------------------------------------------------------------------------------------------------
|EventName. |dateTime |UserID |nodeRef
+--------------------------------------------------------------------------------------------------------------------------------------------
| org.alfresco.documentlibrary.file-deleted | 2018-11-13 09:45:30 | admin | {"firstName":"Administrator","lastName":"","parentNodeRef":"workspace://SpacesStore/ad556167-cb16-
433c-bd1b-f71886e83e85","nodeRef":"workspace://SpacesStore/4505c224-2567-4713-8674-b4c852aa88e6","page":"documentlibrary?path=/","title":"ChangesSimpleStyle.css"}
Stores NodeRefs
| Id | Time | User | Application | Value
| 137 | 1542678927538 | admin | /alfrescoaccess/transaction/aspects/delete |updateNodeProperties |
| 137 | 1542678927538 | admin | /alfresco-access/transaction/aspects/delete |/sys:system/sys:people/cm:admin |
| 137 | 1542678927538 | admin | /alfresco-access/transaction/aspects/delete | updateNodeProperties |
| 137 | 1542678927538 | admin | /alfresco-access/transaction/aspects/delete | cm:person |
No nodeRefs
to be stored
11. Learn. Connect. Collaborate.
Another difference
- Audit
• Filenames, Event Names, Paths, dateTime, UserID.
- activity_feed
• Filenames, Event Names, Paths, dateTime, UserID, NodeRefs
VS
select activity_type as EventName, feed_date as dateTime, feed_user_id as UserID, activity_summary as nodeRef from alf_activity_feed where feed_date like '%2018-11-13%';
+--------------------------------------------------------------------------------------------------------------------------------------------
|EventName. |dateTime |UserID |nodeRef
+--------------------------------------------------------------------------------------------------------------------------------------------
| org.alfresco.documentlibrary.file-deleted | 2018-11-13 09:45:30 | admin | {"firstName":"Administrator","lastName":"","parentNodeRef":"workspace://SpacesStore/ad556167-cb16-
433c-bd1b-f71886e83e85","nodeRef":"workspace://SpacesStore/4505c224-2567-4713-8674-b4c852aa88e6","page":"documentlibrary?path=/","title":"ChangesSimpleStyle.css"}
Stores NodeRefs
| Id | Time | User | Application | Value
| 137 | 1542678927538 | admin | /alfrescoaccess/transaction/aspects/delete |updateNodeProperties |
| 137 | 1542678927538 | admin | /alfresco-access/transaction/aspects/delete |/sys:system/sys:people/cm:admin |
| 137 | 1542678927538 | admin | /alfresco-access/transaction/aspects/delete | updateNodeProperties |
| 137 | 1542678927538 | admin | /alfresco-access/transaction/aspects/delete | cm:person |
No nodeRefs
to be stored
20. Learn. Connect. Collaborate.
How to use Activity Feed for an audit purpose
+-------------------------------------------------------------------------------------|
org.alfresco.documentlibrary.file-deleted | 2018-11-13 09:45:30 | admin |
{"firstName":"Administrator","lastName":"","parentNodeRef":"workspace://Sp
acesStore/ad556167-cb16-433c-bd1b-
f71886e83e85","nodeRef":"workspace://SpacesStore/4505c224-2567-4713-
8674-
b4c852aa88e6","page":"documentlibrary?path=/","title":"ChangesSimpleStyle.
css"}
#alf_activity_feed
2018
Oct
GET
/alfresco/service/api/activities/
feed/user/{userId}?format=json
21. Learn. Connect. Collaborate.
How to use Activity Feed for an audit purpose
+-------------------------------------------------------------------------------------|
org.alfresco.documentlibrary.file-deleted | 2018-11-13 09:45:30 | admin |
{"firstName":"Administrator","lastName":"","parentNodeRef":"workspace://Sp
acesStore/ad556167-cb16-433c-bd1b-
f71886e83e85","nodeRef":"workspace://SpacesStore/4505c224-2567-4713-
8674-
b4c852aa88e6","page":"documentlibrary?path=/","title":"ChangesSimpleStyle.
css"}
#alf_activity_feed
2018
Oct
GET
/alfresco/service/api/activities/
feed/user/{userId}?format=json
22. How to track user activities
without using the audit
functions.
Thank you!