cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Add Event in Audit logs

MV_10441462
10-Marble

Add Event in Audit logs

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. 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@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

View solution in original post

3 REPLIES 3

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

@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

Thankyou so much @HelesicPetr 

Top Tags