Permalink
Browse files

auditing fixes

  • Loading branch information...
1 parent 0a3b102 commit 3a08ac1af600b1b634048a960f33dfc73d9f6817 @jkuehn committed Nov 19, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/groovy/grails/plugins/mongodb/audit/MorphiaAuditEntityInterceptor.java
@@ -11,6 +11,7 @@
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.commons.GrailsClass;
import org.codehaus.groovy.grails.commons.GrailsDomainClass;
+import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +37,10 @@ public void postPersist(Object ent, DBObject dbObj, Mapper mapr) {
String historyCollectionName = watchedClasses.get(ent.getClass());
if (historyCollectionName != null) {
// persist this entity to the history collection
- db.getCollection(ent.getClass().getSimpleName() + "History").save(new BasicDBObject("date", new Date()).append("entity", dbObj));
+ BasicDBObject historyEntity = new BasicDBObject("date", new Date()).append("entity", dbObj);
+ boolean abort = false;
+ if (auditProcessor != null) abort = !auditProcessor.processHistoryEntry(historyEntity, ent, dbObj, mapr);
+ if (!abort) db.getCollection(historyCollectionName).save(historyEntity);
}
}
@@ -67,7 +71,11 @@ public void afterPropertiesSet() throws Exception {
}
// init audit processor
- Object mongodbAuditProcessor = grailsApplication.getMainContext().getBean("mongodbAuditProcessor");
- if (mongodbAuditProcessor instanceof MongodbAuditProcessor) this.auditProcessor = (MongodbAuditProcessor)mongodbAuditProcessor;
+ try {
+ Object mongodbAuditProcessor = grailsApplication.getMainContext().getBean("mongodbAuditProcessor");
+ if (mongodbAuditProcessor instanceof MongodbAuditProcessor) this.auditProcessor = (MongodbAuditProcessor)mongodbAuditProcessor;
+ } catch (BeansException ignore) {
+ // do not care if not defined
+ }
}
}

0 comments on commit 3a08ac1

Please sign in to comment.