Enabling object auditing
Enabling object auditing
To enable object auditing, you first need to add the audit entity listener to the list of entity manager lifecycle and persistence engine operation listeners. In the ep-core project, open WEB-INF/conf/spring/dataaccess/openjpa/openjpa.xml and locate the entityManagerLifecycleListeners bean definition. The entityManagerLifecycleListeners definition contains the objects that listen for OpenJPA lifecycle events (creates, updates, etc.). Add the auditEntityListener bean to the entityManagerLifecycleListeners list.
<util:list id="entityManagerLifecycleListeners"> <ref bean="lastModifiedEntityListener"/commerce-legacy/> <ref bean="objectDeletedEntityListener"/commerce-legacy/> <ref bean="changeSetPersistenceListener"/commerce-legacy/> <ref bean="persistablePostLoadListener"/commerce-legacy/> <ref bean="auditEntityListener"/commerce-legacy/> <!-- Must also be registered in the PersistenceEngine --> </util:list>
Then locate the persistenceEngineOperationListeners list and add the auditEntityListener bean to the persistenceEngineOperationListeners list.
<util:list id="persistenceEngineOperationListeners"> <ref bean="auditEntityListener"/commerce-legacy/> <!--Must also be registered in the EntityManagerFactory--> </util:list>
Then locate the auditEntityListener bean definition. The auditableClasses property specifies the classes that will be audited. If you want to audit other domain objects, you must add their class names to this list.
<bean id="auditEntityListener" class="com.elasticpath.persistence.impl.AuditEntityListener"> <property name="persistenceEngine" ref="persistenceEngineTarget" /> <property name="auditableClasses"> <set> <value>com.elasticpath.domain.attribute.impl.AbstractAttributeValueImpl</value> <value>com.elasticpath.domain.attribute.impl.ProductAttributeValueImpl</value> <value>com.elasticpath.domain.attribute.impl.SkuAttributeValueImpl</value> <value>com.elasticpath.domain.catalog.impl.DigitalAssetImpl</value> ... </set> </property> <property name="auditDao" ref="auditDao" /> <property name="metadataMap" ref="persistenceListenerMetadataMap"/commerce-legacy/> </bean>
After making the changes, you must rebuild and redeploy the core library, web applications, and the Commerce Manager.
When auditing is enabled, information related to the changed objects is written to the audit tables in the database.
Note that you can include custom metadata in the audit records. For more information, see Including audit metadata.