11
11
import org .codehaus .groovy .grails .commons .GrailsApplication ;
12
12
import org .codehaus .groovy .grails .commons .GrailsClass ;
13
13
import org .codehaus .groovy .grails .commons .GrailsDomainClass ;
14
+ import org .springframework .beans .BeansException ;
14
15
import org .springframework .beans .factory .InitializingBean ;
15
16
import org .springframework .beans .factory .annotation .Autowired ;
16
17
@@ -36,7 +37,10 @@ public void postPersist(Object ent, DBObject dbObj, Mapper mapr) {
36
37
String historyCollectionName = watchedClasses .get (ent .getClass ());
37
38
if (historyCollectionName != null ) {
38
39
// persist this entity to the history collection
39
- db .getCollection (ent .getClass ().getSimpleName () + "History" ).save (new BasicDBObject ("date" , new Date ()).append ("entity" , dbObj ));
40
+ BasicDBObject historyEntity = new BasicDBObject ("date" , new Date ()).append ("entity" , dbObj );
41
+ boolean abort = false ;
42
+ if (auditProcessor != null ) abort = !auditProcessor .processHistoryEntry (historyEntity , ent , dbObj , mapr );
43
+ if (!abort ) db .getCollection (historyCollectionName ).save (historyEntity );
40
44
}
41
45
}
42
46
@@ -67,7 +71,11 @@ public void afterPropertiesSet() throws Exception {
67
71
}
68
72
69
73
// init audit processor
70
- Object mongodbAuditProcessor = grailsApplication .getMainContext ().getBean ("mongodbAuditProcessor" );
71
- if (mongodbAuditProcessor instanceof MongodbAuditProcessor ) this .auditProcessor = (MongodbAuditProcessor )mongodbAuditProcessor ;
74
+ try {
75
+ Object mongodbAuditProcessor = grailsApplication .getMainContext ().getBean ("mongodbAuditProcessor" );
76
+ if (mongodbAuditProcessor instanceof MongodbAuditProcessor ) this .auditProcessor = (MongodbAuditProcessor )mongodbAuditProcessor ;
77
+ } catch (BeansException ignore ) {
78
+ // do not care if not defined
79
+ }
72
80
}
73
81
}
0 commit comments