Class AuditLogObserver
java.lang.Object
com.university.bookstore.observer.AuditLogObserver
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a single audit log entry.static classStatistics for the audit log. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new audit log observer with unlimited log size.AuditLogObserver(int maxLogSize) Creates a new audit log observer with the specified maximum log size. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the audit log.Gets all audit log entries.getAuditLogForEventType(String eventType) Gets audit log entries for a specific event type.getAuditLogForMaterial(String materialId) Gets audit log entries for a specific material.getAuditLogForTimeRange(long startTime, long endTime) Gets audit log entries within a time range.Gets audit log statistics.intGets the number of audit log entries.Gets the name of this observer for identification purposes.voidonEvent(MaterialEvent event) Called when a material event occurs.voidPrints the audit log to the console.toString()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.university.bookstore.observer.MaterialObserver
onAdded, onRemoved
-
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
Description copied from interface:MaterialObserverCalled when a material event occurs.- Specified by:
onEventin interfaceMaterialObserver- Parameters:
event- the material event that occurred
-
getAuditLog
Gets all audit log entries.- Returns:
- list of audit log entries
-
getAuditLogForMaterial
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
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
Gets audit log entries within a time range.- Parameters:
startTime- the start time in millisecondsendTime- 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
Gets audit log statistics.- Returns:
- audit log statistics
-
getObserverName
Description copied from interface:MaterialObserverGets the name of this observer for identification purposes.- Specified by:
getObserverNamein interfaceMaterialObserver- Returns:
- the observer name
-
toString
-