Package com.helger.photon.audit
Class AuditManager
- java.lang.Object
-
- com.helger.dao.AbstractDAO
-
- com.helger.dao.simple.AbstractSimpleDAO
-
- com.helger.photon.app.dao.AbstractPhotonSimpleDAO
-
- com.helger.photon.audit.AuditManager
-
- All Implemented Interfaces:
com.helger.commons.log.IHasConditionalLogger,com.helger.dao.IAutoSaveAware,com.helger.dao.IDAO,IAuditManager
@ThreadSafe public class AuditManager extends com.helger.photon.app.dao.AbstractPhotonSimpleDAO implements IAuditManager
The class handles all system audit actions. It collects them asynchronously (seeAsynchronousAuditor) and writes them to XML files on a per-day basis.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static StringELEMENT_ITEMElement name of each item in the serialized XMLstatic StringELEMENT_ITEMSElement name of the root element of the serialized XML
-
Constructor Summary
Constructors Constructor Description AuditManager(String sBaseDir, com.helger.security.authentication.subject.user.ICurrentUserIDProvider aCurrentUserIDProvider)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.helger.xml.microdom.IMicroDocumentcreateWriteData()booleanequals(Object o)com.helger.commons.collection.impl.ICommonsList<IAuditItem>getAllAuditItemsOfDate(LocalDate aDate)intgetAuditItemCount()AsynchronousAuditorgetAuditor()StringgetBaseDir()LocalDategetEarliestAuditDate()List<IAuditItem>getLastAuditItems(int nMaxItems)static StringgetRelativeAuditDirectory(LocalDate aDate)static StringgetRelativeAuditDirectoryYear(int nYear)static StringgetRelativeAuditFilename(LocalDate aDate)inthashCode()booleanisInMemory()protected voidonFilenameChange(String sPreviousFilename, String sNewFilename)protected com.helger.commons.state.EChangeonRead(com.helger.xml.microdom.IMicroDocument aDoc)static voidreadFromXML(com.helger.xml.microdom.IMicroDocument aDoc, Consumer<? super IAuditItem> aHandler)voidstop()Stop taking new audits.StringtoString()-
Methods inherited from class com.helger.dao.simple.AbstractSimpleDAO
beforeWriteToFile, getFilenameProvider, getInitCount, getIO, getLastFilename, getLastInitDateTime, getLastReadDateTime, getLastWriteDateTime, getReadCount, getSafeFile, getWriteCount, getXMLWriterSettings, initialRead, markAsChanged, modifyWriteData, onInit, triggerExceptionHandlersRead, triggerExceptionHandlersWrite, writeToFileOnPendingChanges
-
Methods inherited from class com.helger.dao.AbstractDAO
beginWithoutAutoSave, checkFileAccess, endWithoutAutoSave, exceptionHandlersRead, exceptionHandlersWrite, hasPendingChanges, internalHasPendingChanges, internalIsAutoSaveEnabled, internalSetPendingChanges, isAutoSaveEnabled, isSilentMode, setSilentMode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
ELEMENT_ITEMS
public static final String ELEMENT_ITEMS
Element name of the root element of the serialized XML- See Also:
- Constant Field Values
-
ELEMENT_ITEM
public static final String ELEMENT_ITEM
Element name of each item in the serialized XML- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AuditManager
@ContainsSoftMigration public AuditManager(@Nullable String sBaseDir, @Nonnull com.helger.security.authentication.subject.user.ICurrentUserIDProvider aCurrentUserIDProvider) throws com.helger.dao.DAOException
Constructor- Parameters:
sBaseDir- The base directory, relative to the default IO base directory. May benullto indicate an in-memory auditor only.aCurrentUserIDProvider- The current user ID provider. May not benull.- Throws:
com.helger.dao.DAOException- In case reading failed
-
-
Method Detail
-
getRelativeAuditDirectoryYear
@Nonnull @Nonempty public static String getRelativeAuditDirectoryYear(@Nonnull int nYear)
-
getRelativeAuditDirectory
@Nonnull @Nonempty public static String getRelativeAuditDirectory(@Nonnull LocalDate aDate)
-
getRelativeAuditFilename
@Nonnull @Nonempty public static String getRelativeAuditFilename(@Nonnull LocalDate aDate)
-
isInMemory
public boolean isInMemory()
- Specified by:
isInMemoryin interfaceIAuditManager- Returns:
trueif this manager operates only in memory,falseif it keeps persistent files.- See Also:
IAuditManager.getBaseDir()
-
getBaseDir
@Nullable public String getBaseDir()
- Specified by:
getBaseDirin interfaceIAuditManager- Returns:
- The base directory used for audit entries. May be
nullto indicate in-memory only auditing. If the results is notnullit must end with a path separator (slash). - See Also:
IAuditManager.isInMemory()
-
getAuditor
@Nonnull public AsynchronousAuditor getAuditor()
- Specified by:
getAuditorin interfaceIAuditManager- Returns:
- The underlying auditor. Never
null.
-
readFromXML
public static void readFromXML(@Nonnull com.helger.xml.microdom.IMicroDocument aDoc, @Nonnull Consumer<? super IAuditItem> aHandler)
-
onRead
@Nonnull protected com.helger.commons.state.EChange onRead(@Nonnull com.helger.xml.microdom.IMicroDocument aDoc)
- Specified by:
onReadin classcom.helger.dao.simple.AbstractSimpleDAO
-
createWriteData
protected com.helger.xml.microdom.IMicroDocument createWriteData()
- Specified by:
createWriteDatain classcom.helger.dao.simple.AbstractSimpleDAO
-
onFilenameChange
protected void onFilenameChange(@Nullable String sPreviousFilename, @Nonnull String sNewFilename)
- Overrides:
onFilenameChangein classcom.helger.dao.simple.AbstractSimpleDAO
-
getAuditItemCount
@Nonnegative public int getAuditItemCount()
-
getLastAuditItems
@Nonnull @ReturnsMutableCopy @CodingStyleguideUnaware public List<IAuditItem> getLastAuditItems(@Nonnegative int nMaxItems)
- Specified by:
getLastAuditItemsin interfaceIAuditManager- Parameters:
nMaxItems- The maximum number of items. Must be > 0.- Returns:
- The n latest audit items. Never
null.
-
stop
public void stop()
Description copied from interface:IAuditManagerStop taking new audits. Call this upon shutdown for correct cleanup! Consecutive calls to this method have no further effect.- Specified by:
stopin interfaceIAuditManager
-
getAllAuditItemsOfDate
@Nullable @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<IAuditItem> getAllAuditItemsOfDate(@Nonnull LocalDate aDate)
-
getEarliestAuditDate
@Nonnull public LocalDate getEarliestAuditDate()
- Specified by:
getEarliestAuditDatein interfaceIAuditManager- Returns:
- The earliest date for which auditing information is present. If
this is an in-memory audit manager, it must return the current
date. May be
nullif a persistent storage is used and no entry is present yet.
-
toString
public String toString()
- Overrides:
toStringin classcom.helger.dao.simple.AbstractSimpleDAO
-
-