Class EntityLogImpl

java.lang.Object
io.jmix.audit.impl.EntityLogImpl
All Implemented Interfaces:
EntityLog, JpaLifecycleListener

@Component("audit_EntityLog") public class EntityLogImpl extends Object implements EntityLog, JpaLifecycleListener
  • Field Details

    • RESOURCE_HOLDER_KEY

      public static final String RESOURCE_HOLDER_KEY
    • timeSource

      @Autowired protected TimeSource timeSource
    • metadata

      @Autowired protected Metadata metadata
    • metadataTools

      @Autowired protected MetadataTools metadataTools
    • extendedEntities

      @Autowired protected ExtendedEntities extendedEntities
    • entityStates

      @Autowired protected EntityStates entityStates
    • auditInfoProvider

      @Autowired protected AuditInfoProvider auditInfoProvider
    • referenceToEntitySupport

      @Autowired protected ReferenceToEntitySupport referenceToEntitySupport
    • stores

      @Autowired protected Stores stores
    • datatypeRegistry

      @Autowired protected DatatypeRegistry datatypeRegistry
    • attributeChangesProvider

      @Autowired protected AttributeChangesProvider attributeChangesProvider
    • entityEventManager

      @Autowired protected EntityEventManager entityEventManager
    • entityManager

      protected javax.persistence.EntityManager entityManager
    • transaction

      protected org.springframework.transaction.support.TransactionTemplate transaction
    • properties

      protected AuditProperties properties
    • enabled

      protected volatile boolean enabled
    • loaded

      protected volatile boolean loaded
    • entitiesManual

      protected Map<String,Set<String>> entitiesManual
    • entitiesAuto

      protected Map<String,Set<String>> entitiesAuto
    • lock

      protected ReentrantReadWriteLock lock
    • entityLogSwitchedOn

      protected ThreadLocal<Boolean> entityLogSwitchedOn
  • Constructor Details

    • EntityLogImpl

      public EntityLogImpl()
  • Method Details

    • setTransactionManager

      @Autowired protected void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
    • setProperties

      @Autowired public void setProperties(AuditProperties properties)
    • processLoggingForCurrentThread

      public void processLoggingForCurrentThread(boolean enabled)
      Description copied from interface: EntityLog
      Disables/enables entity logging for current thread. Enabled by default.
      Specified by:
      processLoggingForCurrentThread in interface EntityLog
      Parameters:
      enabled - entity logging disabled if false, enabled otherwise.
    • isLoggingForCurrentThread

      public boolean isLoggingForCurrentThread()
      Specified by:
      isLoggingForCurrentThread in interface EntityLog
      Returns:
      whether logging for the current thread is enabled
      See Also:
    • onEntityChange

      public void onEntityChange(Object entity, EntityOp entityOp, @Nullable AttributeChanges changes)
      Description copied from interface: JpaLifecycleListener
      Invoked before entity commit.
      Specified by:
      onEntityChange in interface JpaLifecycleListener
      Parameters:
      entity - entity
      entityOp - entity change type
      changes - object describing changes in the entity attributes - null for CREATE and DELETE change types
    • onFlush

      public void onFlush(String storeName)
      Description copied from interface: JpaLifecycleListener
      Invoked before committing to data store.
      Specified by:
      onFlush in interface JpaLifecycleListener
      Parameters:
      storeName - name of data store
    • flush

      public void flush(String storeName)
      Description copied from interface: EntityLog
      Flush records accumulated by invocations of EntityLog.registerCreate(Object) and other registration methods to the database.
      Specified by:
      flush in interface EntityLog
    • computeChanges

      protected void computeChanges(EntityLogItem itemToSave, List<EntityLogItem> sameEntityList)
    • processAttributes

      protected void processAttributes(EntityLogItem itemToSave, List<EntityLogItem> sameEntityList, Set<String> attributes)
    • setAttributeOldValue

      protected void setAttributeOldValue(EntityLogAttr entityLogAttr, EntityLogItem itemToSave)
    • setAttributeNewValue

      protected void setAttributeNewValue(EntityLogAttr entityLogAttr, EntityLogItem itemToSave)
    • getAttrToSave

      protected EntityLogAttr getAttrToSave(EntityLogAttr entityLogAttr, EntityLogItem itemToSave)
    • saveItem

      protected void saveItem(EntityLogItem item)
    • isEnabled

      public boolean isEnabled()
      Specified by:
      isEnabled in interface EntityLog
    • setEnabled

      public void setEnabled(boolean enabled)
      Specified by:
      setEnabled in interface EntityLog
    • invalidateCache

      public void invalidateCache()
      Description copied from interface: EntityLog
      Invalidates configuration cache. The configuration will be recreated from the database on next lifecycle event.
      Specified by:
      invalidateCache in interface EntityLog
    • getLoggedAttributes

      @Nullable protected Set<String> getLoggedAttributes(String entity, boolean auto)
    • loadEntities

      protected void loadEntities()
    • getEntityName

      protected String getEntityName(Object entity)
    • doNotRegister

      protected boolean doNotRegister(@Nullable Object entity)
    • registerCreate

      public void registerCreate(Object entity)
      Description copied from interface: EntityLog
      Logs creation of an entity which is configured for manual logging (LoggedEntity.auto == false).
      Specified by:
      registerCreate in interface EntityLog
    • registerCreate

      public void registerCreate(Object entity, boolean auto)
      Description copied from interface: EntityLog
      Logs creation of an entity which is configured for auto or manual logging (depending on the auto parameter).
      Specified by:
      registerCreate in interface EntityLog
    • filterRemovedAttributes

      protected Set<String> filterRemovedAttributes(Object entity, Set<String> attributes)
    • internalRegisterCreate

      protected void internalRegisterCreate(Object entity, String entityName, String storeName, Set<String> attributes)
    • findUsername

      protected String findUsername()
    • enqueueItem

      protected void enqueueItem(EntityLogItem item, String storeName)
    • getEntityLogResourceHolder

      protected EntityLogImpl.EntityLogResourceHolder getEntityLogResourceHolder()
    • registerModify

      public void registerModify(Object entity)
      Description copied from interface: EntityLog
      Logs modification of an entity which is configured for manual logging (LoggedEntity.auto == false).
      Specified by:
      registerModify in interface EntityLog
    • registerModify

      public void registerModify(Object entity, boolean auto)
      Description copied from interface: EntityLog
      Logs modification of an entity which is configured for auto or manual logging (depending on the auto parameter).
      Specified by:
      registerModify in interface EntityLog
    • registerModify

      public void registerModify(Object entity, boolean auto, @Nullable AttributeChanges changes)
      Description copied from interface: EntityLog
      Logs modification of an entity which is configured for auto or manual logging (depending on the auto parameter).
      Specified by:
      registerModify in interface EntityLog
      changes - attribute changes provided by caller
    • internalRegisterModify

      protected EntityLogItem internalRegisterModify(Object entity, @Nullable AttributeChanges changes, MetaClass metaClass, String storeName, Set<String> attributes)
    • createLogAttributes

      protected Set<EntityLogAttr> createLogAttributes(Object entity, Set<String> attributes, EntityLogItem.Type type, @Nullable AttributeChanges changes)
    • getChanges

      protected String getChanges(Properties properties)
    • registerDelete

      public void registerDelete(Object entity)
      Description copied from interface: EntityLog
      Logs deletion of an entity which is configured for manual logging (LoggedEntity.auto == false).
      Specified by:
      registerDelete in interface EntityLog
    • registerDelete

      public void registerDelete(Object entity, boolean auto)
      Description copied from interface: EntityLog
      Logs deletion of an entity which is configured for auto or manual logging (depending on the auto parameter).
      Specified by:
      registerDelete in interface EntityLog
    • internalRegisterDelete

      protected void internalRegisterDelete(Object entity, String entityName, String storeName, Set<String> attributes)
    • generateEntityLogItem

      protected EntityLogItem generateEntityLogItem(Object entity, String entityName, Set<String> attributes, EntityLogItem.Type type)
    • getAllAttributes

      protected Set<String> getAllAttributes(Object entity)
    • getValueId

      @Nullable protected Object getValueId(@Nullable Object value)
    • stringify

      protected String stringify(@Nullable Object value, @Nullable MetaProperty metaProperty)
    • calculateDirtyFields

      protected Set<String> calculateDirtyFields(Object entity, @Nullable AttributeChanges changes)
    • getIdAttributePath

      @Nullable protected String getIdAttributePath(MetaPropertyPath propertyPath, String storeName)
    • logError

      protected void logError(Object entity, Exception e)