Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double records inserted in grails using audit-logging plugin

I have installed the audit-logging plugin into my application. The grails version is 2.1.1 and the plugin version is 1.0.1.

In my Config.groovy class, I have added this

auditLog {
    verbose = true // verbosely log all changed values to db
    logIds = true  // log db-ids of associated objects.
    // Note: if you change next 2 properties, you must update your database schema!
    tablename = 'audit_logs' // table name for audit logs.
    transactional = false
    actorClosure = { request, session ->
        org.apache.shiro.SecurityUtils.getSubject()?.getPrincipal()
    }

and in my domain class I have added this

class Survey {
    static auditable = true
    static final int NO_RUNNING_SURVERY = 0
    static final int RUNNING_SURVERY = 1

    static final int CALL_NO_Record_SURVEY = 0
    static final int CALL_Record_SURVEY = 1

    static final int REALTIME_SURVEY = 0
    static final int HISTORICAL_SURVEY = 1
    static final int STANDARD_SURVERY = 2

    String name
    String description
    int status
}  

when I add, delete and update some thing. In my audit_logs table, double record inserted against one operation e.g. If I change the status value from my controller class

def stopSurvey(Long id) {
        def survey = Survey.findById(params['stop'])
        survey.status = Survey.NO_RUNNING_SURVERY


        redirect(action: "list")
    } 

it inserts two records per call.

like image 376
Muhamamd Omar Muneer Avatar asked Jun 16 '14 10:06

Muhamamd Omar Muneer


2 Answers

@Bertl

I have found the problem,I think, the problem is in plugin. My application uses three databases one is the main database and other two are for other purposes. My databSource is as following.

dataSource.driverClassName = net.sourceforge.jtds.jdbcx.JtdsDataSource
dataSource.dbCreate = update
dataSource.url = jdbc:jtds:sqlserver://localhost:1433/test
dataSource.username = test
dataSource.password = 123

               #TEST1
dataSource_TEST1.driverClassName = net.sourceforge.jtds.jdbcx.JtdsDataSource
dataSource_TEST1.readOnly = true
dataSource_TEST1.url = jdbc:jtds:sqlserver://xxx.xxx.xxx.xxx:1433/test1
dataSource_TEST1.username = test1
dataSource_TEST1.password = 123


#                   TEST2  
dataSource_TEST2.driverClassName = net.sourceforge.jtds.jdbcx.JtdsDataSource
dataSource_TEST2.readOnly = true
dataSource_TEST2.url = jdbc:jtds:sqlserver://xxx.xxx.xxxx.xxx:1433/test2
dataSource_TEST2.username =  test2
dataSource_TEST2.password = 123

When i use only the test datasource and remove other dataSources, it inserts one record. When i use two datasources then it insert two reocrd in audit logging table. Same as when i use the three datasources then it insert three record in audit logging. I need all three databases but it creates the problem. What should i do now?

like image 89
2 revs Avatar answered Nov 03 '22 18:11

2 revs


Didn't see this behaviour here, too. Using this plugin in many projects. Can you please set verbose=false and test again? If the problem happens then also, it means the events might be fired not only once.

A small testapp would be great.

BTW: We use spock tests in the plugins project contained test application (audit-test) to check for how many events are stored in the audit_log table. Therefore I assume an edge case or a specific problem in your app.

like image 28
Bertl Avatar answered Nov 03 '22 16:11

Bertl