37
37
*/
38
38
public class AuditingEventListener implements ApplicationListener <CouchbaseMappingEvent <Object >> {
39
39
40
- private final ObjectFactory <IsNewAwareAuditingHandler > auditingHandlerFactory ;
40
+ private final ObjectFactory <Object > auditingHandlerFactory ;
41
41
42
42
public AuditingEventListener () {
43
43
this .auditingHandlerFactory = null ;
@@ -51,8 +51,8 @@ public AuditingEventListener() {
51
51
*
52
52
* @param auditingHandlerFactory must not be {@literal null}.
53
53
*/
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!" );
56
56
this .auditingHandlerFactory = auditingHandlerFactory ;
57
57
}
58
58
@@ -63,8 +63,19 @@ public AuditingEventListener(ObjectFactory<IsNewAwareAuditingHandler> auditingHa
63
63
@ Override
64
64
public void onApplicationEvent (CouchbaseMappingEvent <Object > event ) {
65
65
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
+ }
68
79
}
69
80
if (event instanceof BeforeSaveEvent ) {}
70
81
if (event instanceof AfterSaveEvent ) {}
0 commit comments