Community Tip - You can change your system assigned username to something more personal in your community settings. X
I'm looking to create an event in Audit logs when I download a set of files using a custom action.
Just like how an event gets created when you download an object. This is totally new to me, so please help me from the basics. If it's feasible please explain me how it should be done programmatically.
Solved! Go to Solution.
Just example 😄
try
{
WTPart eventPart = UtilWTPart.getPartLatestIteration("0000000105210.ASM"); // this is my own method to search WTPart by number
WTPrincipalReference userref = SessionHelper.manager.getPrincipalReference();
WTPrincipal user = (WTPrincipal) userref.getObject();
AuditRecord record = new AuditRecord();
record.setEventKey(ContentServiceEvent.POST_DOWNLOAD);
record.setEventLabel("Custom Download");
record.setTargetReference(wt.fc.ObjectReference.newObjectReference(eventPart));
record.setUserOrgName(user.getOrganization().getName());
record.setOrgContainerName(eventPart.getContainerName());
record.setTargetType(eventPart.getType());
record.setEventTime(new Timestamp(System.currentTimeMillis()));
record.setDomainRef(user.getDomainRef());
record.setDomainPath(user.getDomainRef().getName());
PersistenceHelper.manager.save(record);
} catch (WTPropertyVetoException e)
{
throw new RuntimeException(e);
}
The event is in the report
Be sure to set all attributes that you can identify who/when/fromwhere the event was recorded.
PetrH
Hi @MV_10441462
I would advice to find what type of object is the Audit event
Then I would find and use API of the type to create a event object
set all attributes what you need and save to a database by a PersistenceHelper
It can not be so complicated.
All actions what I described you should perform in the end of your custom action method.
PetrH
Just example 😄
try
{
WTPart eventPart = UtilWTPart.getPartLatestIteration("0000000105210.ASM"); // this is my own method to search WTPart by number
WTPrincipalReference userref = SessionHelper.manager.getPrincipalReference();
WTPrincipal user = (WTPrincipal) userref.getObject();
AuditRecord record = new AuditRecord();
record.setEventKey(ContentServiceEvent.POST_DOWNLOAD);
record.setEventLabel("Custom Download");
record.setTargetReference(wt.fc.ObjectReference.newObjectReference(eventPart));
record.setUserOrgName(user.getOrganization().getName());
record.setOrgContainerName(eventPart.getContainerName());
record.setTargetType(eventPart.getType());
record.setEventTime(new Timestamp(System.currentTimeMillis()));
record.setDomainRef(user.getDomainRef());
record.setDomainPath(user.getDomainRef().getName());
PersistenceHelper.manager.save(record);
} catch (WTPropertyVetoException e)
{
throw new RuntimeException(e);
}
The event is in the report
Be sure to set all attributes that you can identify who/when/fromwhere the event was recorded.
PetrH