Skip to main content
12-Amethyst
March 2, 2023
Solved

Add Event in Audit logs

  • March 2, 2023
  • 1 reply
  • 1663 views

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. 

 

Best answer by HelesicPetr

@MV_10441462 

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 

HelesicPetr_0-1677831122892.png

 

Be sure to set all attributes that you can identify who/when/fromwhere the event was recorded.

 

PetrH

1 reply

HelesicPetr
22-Sapphire II
22-Sapphire II
March 3, 2023

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

PetrH
HelesicPetr
22-Sapphire II
22-Sapphire II
March 3, 2023

@MV_10441462 

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 

HelesicPetr_0-1677831122892.png

 

Be sure to set all attributes that you can identify who/when/fromwhere the event was recorded.

 

PetrH

PetrH
12-Amethyst
March 3, 2023

Thankyou so much @HelesicPetr