Class AuditServiceImpl
java.lang.Object
com.codebarrel.automation.api.service.AuditServiceImpl
- All Implemented Interfaces:
AuditService
-
Field Summary
Fields inherited from interface com.codebarrel.automation.api.service.AuditService
DEFAULT_NUM_ITEMS_PER_PAGE -
Constructor Summary
ConstructorsConstructorDescriptionAuditServiceImpl(AuditItemStore store, TenantService tenantService, AuditItemToBeanTransformerFactory auditItemToBeanTransformerFactory) -
Method Summary
Modifier and TypeMethodDescriptionlongaddEntry(TenantContext context, AuditItemBean item) Stores an audit item for the given tenant.longaddEntry(TenantContext context, AuditItemBean item, AutomationEvent automationEvent, com.codebarrel.automation.api.config.RuleConfigBean ruleConfigBean) Stores an audit item for the given tenant.booleanaddGlobalMessageOnce(TenantContext context, long auditItemId, String messageKey) Adds a global message to the audit item specified (only if it doesn't exist already).fetchAggregatedEventSourceCounts(AuditItemFilter filter, int limit) Fetches the aggregated event source counts for the given filter.fetchStaleAuditItemIds(TenantContext context, long startTime, long endTime) Fetches the audit item IDs that are considered stale.intgetItem(TenantContext tenantContext, AuditItemFilter filter, long auditId) Tries to lookup full item details including all component changes, associated items and item changes.longgetItemCountForAssociatedItem(TenantContext tenant, AssociatedItem.Type type, String associatedItemId) getItems(TenantContext context, AuditItemFilter filter, long offset, long limit) Retrieves all audit items for the tenant context in the project specified.getItemsForAssociatedItem(TenantContext tenant, AssociatedItem.Type type, String associatedItemId, long offset, long limit) getItemsWithDetails(TenantContext context, AuditItemFilter filter, long limit) Retrieves all audit items for the tenant context for the specified filter.getLastAuditItem(TenantContext context, long ruleId) Looks up the last audit log item for the given rule.getObjectItemIdsToDelete(Environment env, long minAuditEntrysToKeep, Timestamp olderThan) Retrieves object item ids with audit items marked for deletion.longremoveAuditItemsFor(Environment env, Long objectItemId, Timestamp olderThan) Removes all audit items for the given object item older than the timestamp provided.voidupdateEntry(TenantContext context, long ruleId, AuditItemBean update) Updates an existing audit item with new associated items and item changes.voidupdateStaleAuditItemEntries(TenantContext context, Set<Long> staleAuditItemIds) Updates the audit item entries that are considered stale
-
Constructor Details
-
AuditServiceImpl
@Inject public AuditServiceImpl(AuditItemStore store, TenantService tenantService, AuditItemToBeanTransformerFactory auditItemToBeanTransformerFactory)
-
-
Method Details
-
addEntry
Description copied from interface:AuditServiceStores an audit item for the given tenant.The AuditItemBean must contain an
ObjectItemwhich is the rule that executed. It can also contain a list ofAssociatedItems (the things affected by the automation rule) andItemChanges. (the actual changes carried out by the automation rule actions.- Specified by:
addEntryin interfaceAuditService- Parameters:
context- the tenant database contextitem- 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:AuditServiceStores 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:
addEntryin interfaceAuditService
-
getItemsWithDetails
Description copied from interface:AuditServiceRetrieves 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:
getItemsWithDetailsin interfaceAuditService- Parameters:
context- the tenant database contextfilter- filter to constrict querylimit- the maximum number of records to be returned from database- Returns:
- Items object containing all matching audit items
-
getItems
Description copied from interface:AuditServiceRetrieves 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:
getItemsin interfaceAuditService- Parameters:
context- the tenant database contextoffset- the audit item created offset to retrieve items fromlimit- the maximum number of items to return- Returns:
- Items object containing all matching audit items
-
updateEntry
Description copied from interface:AuditServiceUpdates an existing audit item with new associated items and item changes. This method also updates end of execution time- Specified by:
updateEntryin interfaceAuditService- Parameters:
context- the tenant database contextruleId- the rule id that just executedupdate- the completed audit item to update
-
getItem
public Optional<AuditItemBean> getItem(TenantContext tenantContext, AuditItemFilter filter, long auditId) Description copied from interface:AuditServiceTries to lookup full item details including all component changes, associated items and item changes.- Specified by:
getItemin interfaceAuditService- Parameters:
tenantContext- the tenant database contextauditId- the id of the audit item- Returns:
- empty if can't be found
-
getLastAuditItem
Description copied from interface:AuditServiceLooks up the last audit log item for the given rule.- Specified by:
getLastAuditItemin interfaceAuditService- Parameters:
context- the tenant database contextruleId- id of teh rule- Returns:
- empty if it can't find one
-
getAuditLogRetentionPeriodDays
- Specified by:
getAuditLogRetentionPeriodDaysin interfaceAuditService- 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:AuditServiceRetrieves object item ids with audit items marked for deletion.- Specified by:
getObjectItemIdsToDeletein interfaceAuditService- Parameters:
env- The database environment to retrieve items fromminAuditEntrysToKeep- 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
Description copied from interface:AuditServiceRemoves all audit items for the given object item older than the timestamp provided.- Specified by:
removeAuditItemsForin interfaceAuditService- Parameters:
env- The database environment to retrieve items fromobjectItemId- the object item id to delete audit logs forolderThan- 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:
getItemCountForAssociatedItemin interfaceAuditService
-
getItemsForAssociatedItem
public List<LimitedAuditItemBean> getItemsForAssociatedItem(TenantContext tenant, AssociatedItem.Type type, String associatedItemId, long offset, long limit) - Specified by:
getItemsForAssociatedItemin interfaceAuditService
-
addGlobalMessageOnce
Description copied from interface:AuditServiceAdds 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:
addGlobalMessageOncein interfaceAuditService- Parameters:
context- the tenant database contextauditItemId- the audit log entry to update- Returns:
- true if an update was performed. false otherwise
-
fetchStaleAuditItemIds
Description copied from interface:AuditServiceFetches 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:
fetchStaleAuditItemIdsin interfaceAuditService- Parameters:
context- the tenant database contextstartTime- the start time for the time rangeendTime- the end time for the time range- Returns:
- the set of stale audit item IDs
-
updateStaleAuditItemEntries
Description copied from interface:AuditServiceUpdates the audit item entries that are considered stale- Specified by:
updateStaleAuditItemEntriesin interfaceAuditService- Parameters:
context- the tenant database contextstaleAuditItemIds- the set of stale audit item IDs
-
fetchAggregatedEventSourceCounts
public AuditItemEventSourceResult fetchAggregatedEventSourceCounts(AuditItemFilter filter, int limit) Description copied from interface:AuditServiceFetches the aggregated event source counts for the given filter.- Specified by:
fetchAggregatedEventSourceCountsin interfaceAuditService- Parameters:
filter- the filter to applylimit- the maximum number of records to return- Returns:
- the aggregated event source counts
-