Package com.isomorphic.datasource

# Class AuditDSGenerator

java.lang.Object
com.isomorphic.datasource.AuditDSGenerator

All Implemented Interfaces:
  `DynamicDSGenerator`, `com.isomorphic.datasource.FrameworkDynamicDSGenerator`

public class AuditDSGenerator extends Object implements com.isomorphic.datasource.FrameworkDynamicDSGenerator
This class implements a `DynamicDSGenerator` which generates an audit `DataSource` based on a `DataSource` which has auditing enabled.

An audit `DataSource` is a `DataSource` which basically inherits from the original `DataSource` and adds some additional metadata which allows storing the timestamp, revision, user and operation type in addition to record field values on each add, update and remove operations.

In order to enable audit for a `DataSource` you have to specify the audit=true property.

There are additional properties which can be specified in order to control how the new fields are named:

- auditUserFieldName - specify the field name used to store the user who performed the operation. If empty string is specified as value, then this field won't be created. Default value is user.
- auditRevisionFieldName - specify the field name used to store the revision information. If empty string is specified as value, then this field won't be created. Default value is revision.
- auditTimeStampFieldName - specify the field name used to store the timestamp of the operation. If empty string is specified as value, then this field won't be created. Default value is timestamp.
- auditTypeFieldName - specify the field name used to store the operation type. If empty string is specified as value, then this field won't be created. Default value is type.
- auditDataSourceID - the id of the generated `DataSource`. Default value is audit_[OriginalDSID].

In addition to this, setting audit=false property on a field will disable tracking on that field. In effect, the field won't be stored in the audit `DataSource`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addMapping(String auditDSID, String dsID)`
  Add a mapping between an audit `DataSource` and audited `DataSource`
  `static Integer`
  `getAuditChangedFieldsFieldLength(DataSource ds)`
  Get the "changed fields" field length configured for the given `DataSource`.
  `static String`
  `getAuditChangedFieldsFieldName(DataSource ds)`
  Get the "changed fields" field name configured for the given `DataSource`.
  `static String`
  `getAuditDSConstructor(DataSource ds)`
  Get the serverConstructor configured for the given `DataSource`
  `static String`
  `getAuditRevisionFieldName(DataSource ds)`
  Get the revision field name configured for the given `DataSource`.
  `static String`
  `getAuditSchemaName(DataSource ds)`
  Get the audit schema configured for the given `DataSource`
  `static String`
  `getAuditTimestampFieldName(DataSource ds)`
  Get the timestamp field name configured for the given `DataSource`.
  `static String`
  `getAuditTypeFieldName(DataSource ds)`
  Get the type field name configured for the given `DataSource`.
  `static String`
  `getAuditUserFieldName(DataSource ds)`
  Get the user field name configured for the given `DataSource`.
  `boolean`
  `hasMappingFor(String auditDSID)`
  Returns true if the specified audit `DataSource` is already mapped inside the `AuditDSGenerator`

- ## Method Details

  - ### getAuditRevisionFieldName

    public static String getAuditRevisionFieldName(DataSource ds)
    Get the revision field name configured for the given `DataSource`.
    Parameters:
      `ds` - the audit `DataSource` for which we want to retrieve the revision field name.
    Returns:
      the field name representing the revision field configured for the audit `DataSource` passed as parameter.

  - ### getAuditChangedFieldsFieldName

    public static String getAuditChangedFieldsFieldName(DataSource ds)
    Get the "changed fields" field name configured for the given `DataSource`.
    Parameters:
      `ds` - the audit `DataSource` for which we want to retrieve the "changed fields" field name.
    Returns:
      the field name representing the "changed fields" field configured for the audit `DataSource` passed as parameter.

  - ### getAuditChangedFieldsFieldLength

    public static Integer getAuditChangedFieldsFieldLength(DataSource ds)
    Get the "changed fields" field length configured for the given `DataSource`.
    Parameters:
      `ds` - the audit `DataSource` for which we want to retrieve the "changed fields" field length.
    Returns:
      the configured or default length to use for the "changed fields" field for the audit `DataSource` passed as parameter.

  - ### getAuditTimestampFieldName

    public static String getAuditTimestampFieldName(DataSource ds)
    Get the timestamp field name configured for the given `DataSource`.
    Parameters:
      `ds` - the audit `DataSource` for which we want to retrieve the timestamp field name.
    Returns:
      the field name representing the timestamp field configured for the audit `DataSource` passed as parameter.

  - ### getAuditTypeFieldName

    public static String getAuditTypeFieldName(DataSource ds)
    Get the type field name configured for the given `DataSource`.
    Parameters:
      `ds` - the audit `DataSource` for which we want to retrieve the type field name.
    Returns:
      the field name representing the type field configured for the audit `DataSource` passed as parameter.

  - ### getAuditUserFieldName

    public static String getAuditUserFieldName(DataSource ds)
    Get the user field name configured for the given `DataSource`.
    Parameters:
      `ds` - the audit `DataSource` for which we want to retrieve the user field name.
    Returns:
      the field name representing the user field configured for the audit `DataSource` passed as parameter.

  - ### getAuditSchemaName

    public static String getAuditSchemaName(DataSource ds)
    Get the audit schema configured for the given `DataSource`
    Parameters:
      `ds` - the audit `DataSource` for which we want to retrieve schema name.
    Returns:
      the schema name configured for the audit `DataSource` passed as parameter.

  - ### getAuditDSConstructor

    public static String getAuditDSConstructor(DataSource ds)
    Get the serverConstructor configured for the given `DataSource`
    Parameters:
      `ds` - the audit `DataSource` for which we want to retrieve the serverConstructor.
    Returns:
      the serverConstructor configured for the audit `DataSource` passed as parameter.

  - ### addMapping

    public void addMapping(String auditDSID, String dsID)
    Add a mapping between an audit `DataSource` and audited `DataSource`
    Parameters:
      `auditDSID` - the audit `DataSource` to be generated
      `dsID` - the audited `DataSource` for which we need to generate the audit DataSource

  - ### hasMappingFor

    public boolean hasMappingFor(String auditDSID)
    Returns true if the specified audit `DataSource` is already mapped inside the `AuditDSGenerator`
    Parameters:
      `auditDSID` - auditDSID the audit `DataSource` to be generated
    Returns:
      true if the audit `DataSource` is already mapped by the `AuditDSGenerator`