You are viewing the documentation for Blueriq 17. Documentation for other versions is available in our documentation directory.

How to access the audit functionality in a service

In order to access auditing functionality one can retrieve an instance of an IAuditEngine from the IServiceContext passed to the handle method of a service implementation. 

Accessing the IAuditEngine in a service
@AquimaService("EXAMPLE_SERVICE")
public class ExampleService implements IService {
  @Override
  public IServiceResult handle(IServiceContext serviceContext) throws ServiceException, Exception {
 	 final IAuditEngine auditEngine = serviceContext.getAuditEngine();

     return new ServiceResult("Success");
   }
}

How to access the audit functionality in a container

In order to access auditing functionality one can retrieve an instance of an IAuditEngine from the IContainerContext passed to the expand method of a container implementation. 

Accessing the IAuditEngine in a container
@AquimaExpander("EXAMPLE_CONTAINER")
public class ExampleContainer implements IContainerExpander {
  @Override
  public Container expand(Container container, ContainerDefinition containerDefinition,
      IContainerContext containerContext) throws Exception {
    final IAuditEngine auditEngine = containerContext.getAuditEngine();

    return container;
  }
}

Logging an audit message

You can simply call the audit method on the IAuditEngine with an implementation of IAuditMessage.

The message object must be wrapped inside a Supplier object. The easiest way to do this is by instantiating your IAuditMessage instance inside a lamba.

Logging an audit message
@AquimaService("EXAMPLE_SERVICE")
public class ExampleService implements IService {
  @Override
  public IServiceResult handle(IServiceContext serviceContext) throws ServiceException, Exception {
 	 final var auditEngine = serviceContext.getAuditEngine();

     // This ExampleAuditMessage could for example set all required fields by itself from the profile.
     auditEngine.audit(() -> new ExampleAuditMessage(serviceContext.getProfile()));

     return new ServiceResult("Success");
   }
}

Structure of an audit message

With the audit engine you can log audit messages.

An implementation of the IAuditMessage interface is necessary in order to have your own audit message definition.

An alternative would be to use an existing implementation from Blueriq SDK.

The following fields are required on an audit message.

Field nameDescription
eventType
The type of the audit message. This field is meant to provide information about the context of the event. Was it for example a create, update, delete event?
processName
When the audit message was created in context of a certain process this field can be used to store the name of said process.
caseIdWhen the audit message was created in context of a certain case this field can be used to store the id of said case.
taskNameWhen the audit message was created in context of a certain task this field can be used to store the name of said task.
taskIdWhen the audit message was created in context of a certain task this field can be used to store the id of said task.
sourceTypeThis field can be used to store information about the source of the audit message. Such as the type of the service that this audit message was logged in.
sourceIdThis field can be used to store information about the source of the audit message. Can be used to specifically identify a certain service where the audit message was created.
contextAn string on string key/value map. Can be used to store any context specific information.

Dynamic case management auditing

When your application uses dynamic case management you might want to know how to access certain information such as process, case and task information.

The IAuditEngine interface contains a properties object that tells the user on what entity this information can be found.

Accessing the properties object
@AquimaService("EXAMPLE_SERVICE")
public class ExampleService implements IService {
  @Override
  public IServiceResult handle(IServiceContext context) throws ServiceException, Exception {
    final var auditEngine = serviceContext.getAuditEngine();
    final var auditDomainProperties = auditEngine.getDomainProperties();

    final var processNameAttributeReference = new AttributeReference(auditDomainProperties.getEntity(),
        auditDomainProperties.getProcessNameAttribute());
    final var caseIdAttributeReference = new AttributeReference(auditDomainProperties.getEntity(),
        auditDomainProperties.getCaseIdAttribute());
    final var taskNameAttributeReference = new AttributeReference(auditDomainProperties.getEntity(),
        auditDomainProperties.getTaskNameAttribute());
    final var taskIdAttributeReference = new AttributeReference(auditDomainProperties.getEntity(),
        auditDomainProperties.getTaskIdAttribute());
  }
}

Above example demonstrates how to get attribute references to gain access to the correct DCM related values.


  • No labels