3737 */
3838public class AuditingEventListener implements ApplicationListener <CouchbaseMappingEvent <Object >> {
3939
40- private final ObjectFactory <IsNewAwareAuditingHandler > auditingHandlerFactory ;
40+ private final ObjectFactory <Object > auditingHandlerFactory ;
4141
4242 public AuditingEventListener () {
4343 this .auditingHandlerFactory = null ;
@@ -51,8 +51,8 @@ public AuditingEventListener() {
5151 *
5252 * @param auditingHandlerFactory must not be {@literal null}.
5353 */
54- public AuditingEventListener (ObjectFactory <IsNewAwareAuditingHandler > auditingHandlerFactory ) {
55- Assert .notNull (auditingHandlerFactory , "IsNewAwareAuditingHandler must not be null!" );
54+ public AuditingEventListener (ObjectFactory <Object > auditingHandlerFactory ) {
55+ Assert .notNull (auditingHandlerFactory , "auditingHandlerFactory must not be null!" );
5656 this .auditingHandlerFactory = auditingHandlerFactory ;
5757 }
5858
@@ -63,8 +63,19 @@ public AuditingEventListener(ObjectFactory<IsNewAwareAuditingHandler> auditingHa
6363 @ Override
6464 public void onApplicationEvent (CouchbaseMappingEvent <Object > event ) {
6565 if (event instanceof BeforeConvertEvent ) {
66- Optional .ofNullable (event .getSource ())//
67- .ifPresent (it -> auditingHandlerFactory .getObject ().markAudited (it ));
66+ IsNewAwareAuditingHandler h = auditingHandlerFactory != null
67+ && auditingHandlerFactory .getObject () instanceof IsNewAwareAuditingHandler
68+ ? (IsNewAwareAuditingHandler ) (auditingHandlerFactory .getObject ())
69+ : null ;
70+ if (auditingHandlerFactory != null && h == null ) {
71+ if (LOG .isWarnEnabled ()) {
72+ LOG .warn ("event:{} source:{} auditingHandler is not an IsNewAwareAuditingHandler: {}" ,
73+ event .getClass ().getSimpleName (), event .getSource (), auditingHandlerFactory .getObject ());
74+ }
75+ }
76+ if (h != null ) {
77+ Optional .ofNullable (event .getSource ()).ifPresent (it -> h .markAudited (it ));
78+ }
6879 }
6980 if (event instanceof BeforeSaveEvent ) {}
7081 if (event instanceof AfterSaveEvent ) {}
0 commit comments