Class AuditServiceImpl

java.lang.Object
com.codebarrel.automation.api.service.AuditServiceImpl
All Implemented Interfaces:
AuditService

@Component public class AuditServiceImpl extends Object implements AuditService
  • Constructor Details

  • Method Details

    • addEntry

      public long addEntry(TenantContext context, AuditItemBean item)
      Description copied from interface: AuditService
      Stores an audit item for the given tenant.

      The AuditItemBean must contain an ObjectItem which is the rule that executed. It can also contain a list of AssociatedItems (the things affected by the automation rule) and ItemChanges. (the actual changes carried out by the automation rule actions.

      Specified by:
      addEntry in interface AuditService
      Parameters:
      context - the tenant database context
      item - the actual audit item to store
    • addEntry

      public long addEntry(TenantContext context, AuditItemBean item, AutomationEvent automationEvent, com.codebarrel.automation.api.config.RuleConfigBean ruleConfigBean)
      Description copied from interface: AuditService
      Stores an audit item for the given tenant. automationEvent and ruleConfig bean are used in the case of a rule execution. automationEvent is used to store extra meta data about the item. ruleConfig determines what counts are incremented
      Specified by:
      addEntry in interface AuditService
    • getItemsWithDetails

      public Items getItemsWithDetails(TenantContext context, AuditItemFilter filter, long limit)
      Description copied from interface: AuditService
      Retrieves all audit items for the tenant context for the specified filter.

      This method will return items with details (associated items, change items, component changes). It is written for getting logs to write them to the file. Use it wisely as it can influence performance.

      Specified by:
      getItemsWithDetails in interface AuditService
      Parameters:
      context - the tenant database context
      filter - filter to constrict query
      limit - the maximum number of records to be returned from database
      Returns:
      Items object containing all matching audit items
    • getItems

      public Items getItems(TenantContext context, AuditItemFilter filter, long offset, long limit)
      Description copied from interface: AuditService
      Retrieves all audit items for the tenant context in the project specified.

      This method will only return items as specified by the offset (page start) and maxResults (max items to return in one call in reverse order (by created date).

      Specified by:
      getItems in interface AuditService
      Parameters:
      context - the tenant database context
      offset - the audit item created offset to retrieve items from
      limit - the maximum number of items to return
      Returns:
      Items object containing all matching audit items
    • updateEntry

      public void updateEntry(TenantContext context, long ruleId, AuditItemBean update)
      Description copied from interface: AuditService
      Updates an existing audit item with new associated items and item changes. This method also updates end of execution time
      Specified by:
      updateEntry in interface AuditService
      Parameters:
      context - the tenant database context
      ruleId - the rule id that just executed
      update - the completed audit item to update
    • getItem

      public Optional<AuditItemBean> getItem(TenantContext tenantContext, AuditItemFilter filter, long auditId)
      Description copied from interface: AuditService
      Tries to lookup full item details including all component changes, associated items and item changes.
      Specified by:
      getItem in interface AuditService
      Parameters:
      tenantContext - the tenant database context
      auditId - the id of the audit item
      Returns:
      empty if can't be found
    • getLastAuditItem

      public Optional<AuditItemBean> getLastAuditItem(TenantContext context, long ruleId)
      Description copied from interface: AuditService
      Looks up the last audit log item for the given rule.
      Specified by:
      getLastAuditItem in interface AuditService
      Parameters:
      context - the tenant database context
      ruleId - id of teh rule
      Returns:
      empty if it can't find one
    • getAuditLogRetentionPeriodDays

      public int getAuditLogRetentionPeriodDays(Environment env)
      Specified by:
      getAuditLogRetentionPeriodDays in interface AuditService
      Parameters:
      env - The database environment to retrieve items from
      Returns:
      Number of days to keep audit logs for. -1 indicates keeping them forever
    • getObjectItemIdsToDelete

      public Set<Long> getObjectItemIdsToDelete(Environment env, long minAuditEntrysToKeep, Timestamp olderThan)
      Description copied from interface: AuditService
      Retrieves object item ids with audit items marked for deletion.
      Specified by:
      getObjectItemIdsToDelete in interface AuditService
      Parameters:
      env - The database environment to retrieve items from
      minAuditEntrysToKeep - object item ids with less than this number will not be deleted.
      olderThan - Only object items with audit ids older than this timestamp will be considered for deletion.
      Returns:
      object item ids with audit items marked for deletion.
    • removeAuditItemsFor

      public long removeAuditItemsFor(Environment env, Long objectItemId, Timestamp olderThan)
      Description copied from interface: AuditService
      Removes all audit items for the given object item older than the timestamp provided.
      Specified by:
      removeAuditItemsFor in interface AuditService
      Parameters:
      env - The database environment to retrieve items from
      objectItemId - the object item id to delete audit logs for
      olderThan - Only object items with audit ids older than this timestamp will be deleted
      Returns:
      number audit items deleted.
    • getItemCountForAssociatedItem

      public long getItemCountForAssociatedItem(TenantContext tenant, AssociatedItem.Type type, String associatedItemId)
      Specified by:
      getItemCountForAssociatedItem in interface AuditService
    • getItemsForAssociatedItem

      public List<LimitedAuditItemBean> getItemsForAssociatedItem(TenantContext tenant, AssociatedItem.Type type, String associatedItemId, long offset, long limit)
      Specified by:
      getItemsForAssociatedItem in interface AuditService
    • addGlobalMessageOnce

      public boolean addGlobalMessageOnce(TenantContext context, long auditItemId, String messageKey)
      Description copied from interface: AuditService
      Adds a global message to the audit item specified (only if it doesn't exist already).

      The returns true only if this performed an audit log update.

      Specified by:
      addGlobalMessageOnce in interface AuditService
      Parameters:
      context - the tenant database context
      auditItemId - the audit log entry to update
      Returns:
      true if an update was performed. false otherwise
    • fetchStaleAuditItemIds

      public Set<Long> fetchStaleAuditItemIds(TenantContext context, long startTime, long endTime)
      Description copied from interface: AuditService
      Fetches the audit item IDs that are considered stale. This method identifies audit item entries that have been into in progress status within the specified time range.
      Specified by:
      fetchStaleAuditItemIds in interface AuditService
      Parameters:
      context - the tenant database context
      startTime - the start time for the time range
      endTime - the end time for the time range
      Returns:
      the set of stale audit item IDs
    • updateStaleAuditItemEntries

      public void updateStaleAuditItemEntries(TenantContext context, Set<Long> staleAuditItemIds)
      Description copied from interface: AuditService
      Updates the audit item entries that are considered stale
      Specified by:
      updateStaleAuditItemEntries in interface AuditService
      Parameters:
      context - the tenant database context
      staleAuditItemIds - the set of stale audit item IDs
    • fetchAggregatedEventSourceCounts

      public AuditItemEventSourceResult fetchAggregatedEventSourceCounts(AuditItemFilter filter, int limit)
      Description copied from interface: AuditService
      Fetches the aggregated event source counts for the given filter.
      Specified by:
      fetchAggregatedEventSourceCounts in interface AuditService
      Parameters:
      filter - the filter to apply
      limit - the maximum number of records to return
      Returns:
      the aggregated event source counts