Class AuditLogObserver

java.lang.Object
com.university.bookstore.observer.AuditLogObserver
All Implemented Interfaces:
MaterialObserver

public class AuditLogObserver extends Object implements MaterialObserver
Observer that maintains an audit log of all material events. Provides a complete history of system activities for compliance and debugging.
Since:
2024-09-15
Version:
3.0
Author:
Navid Mohaghegh
  • Constructor Details

    • AuditLogObserver

      public AuditLogObserver()
      Creates a new audit log observer with unlimited log size.
    • AuditLogObserver

      public AuditLogObserver(int maxLogSize)
      Creates a new audit log observer with the specified maximum log size.
      Parameters:
      maxLogSize - the maximum number of log entries to keep
  • Method Details

    • onEvent

      public void onEvent(MaterialEvent event)
      Description copied from interface: MaterialObserver
      Called when a material event occurs.
      Specified by:
      onEvent in interface MaterialObserver
      Parameters:
      event - the material event that occurred
    • getAuditLog

      public List<AuditLogObserver.AuditLogEntry> getAuditLog()
      Gets all audit log entries.
      Returns:
      list of audit log entries
    • getAuditLogForMaterial

      public List<AuditLogObserver.AuditLogEntry> getAuditLogForMaterial(String materialId)
      Gets audit log entries for a specific material.
      Parameters:
      materialId - the material ID to filter by
      Returns:
      list of audit log entries for the material
    • getAuditLogForEventType

      public List<AuditLogObserver.AuditLogEntry> getAuditLogForEventType(String eventType)
      Gets audit log entries for a specific event type.
      Parameters:
      eventType - the event type to filter by
      Returns:
      list of audit log entries for the event type
    • getAuditLogForTimeRange

      public List<AuditLogObserver.AuditLogEntry> getAuditLogForTimeRange(long startTime, long endTime)
      Gets audit log entries within a time range.
      Parameters:
      startTime - the start time in milliseconds
      endTime - the end time in milliseconds
      Returns:
      list of audit log entries within the time range
    • printAuditLog

      public void printAuditLog()
      Prints the audit log to the console.
    • getLogSize

      public int getLogSize()
      Gets the number of audit log entries.
      Returns:
      the log size
    • clearAuditLog

      public void clearAuditLog()
      Clears the audit log.
    • getAuditLogStats

      public AuditLogObserver.AuditLogStats getAuditLogStats()
      Gets audit log statistics.
      Returns:
      audit log statistics
    • getObserverName

      public String getObserverName()
      Description copied from interface: MaterialObserver
      Gets the name of this observer for identification purposes.
      Specified by:
      getObserverName in interface MaterialObserver
      Returns:
      the observer name
    • toString

      public String toString()
      Overrides:
      toString in class Object