Search in sources :

Example 1 with ChangeType

use of org.killbill.billing.util.audit.ChangeType in project killbill by killbill.

the class EntitySqlDaoWrapperInvocationHandler method invokeWithAuditAndHistory.

private Object invokeWithAuditAndHistory(final Audited auditedAnnotation, final Method method, final Object[] args) throws Throwable {
    InternalCallContext context = null;
    List<String> entityIds = null;
    final Map<String, M> entities = new HashMap<String, M>();
    final Map<String, Long> entityRecordIds = new HashMap<String, Long>();
    if (auditedAnnotation != null) {
        // There will be some work required after the statement is executed,
        // get the id before in case the change is a delete
        context = retrieveContextFromArguments(args);
        entityIds = retrieveEntityIdsFromArguments(method, args);
        for (final String entityId : entityIds) {
            entities.put(entityId, sqlDao.getById(entityId, context));
            entityRecordIds.put(entityId, sqlDao.getRecordId(entityId, context));
        }
    }
    // Real jdbc call
    final Object obj = prof.executeWithProfiling(ProfilingFeatureType.DAO_DETAILS, sqlDaoClass.getSimpleName() + " (raw) :", new WithProfilingCallback() {

        @Override
        public Object execute() throws Throwable {
            return method.invoke(sqlDao, args);
        }
    });
    final ChangeType changeType = auditedAnnotation.value();
    for (final String entityId : entityIds) {
        updateHistoryAndAudit(entityId, entities, entityRecordIds, changeType, context);
    }
    return obj;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) WithProfilingCallback(org.killbill.commons.profiling.Profiling.WithProfilingCallback) ChangeType(org.killbill.billing.util.audit.ChangeType)

Example 2 with ChangeType

use of org.killbill.billing.util.audit.ChangeType in project killbill by killbill.

the class TestAuditLogJson method testConstructor.

@Test(groups = "fast")
public void testConstructor() throws Exception {
    final TableName tableName = TableName.ACCOUNT_EMAIL_HISTORY;
    final long recordId = Long.MAX_VALUE;
    final ChangeType changeType = ChangeType.DELETE;
    final EntityAudit entityAudit = new EntityAudit(tableName, recordId, changeType, null);
    final AuditLog auditLog = new DefaultAuditLog(new AuditLogModelDao(entityAudit, callContext), ObjectType.ACCOUNT_EMAIL, UUID.randomUUID());
    final AuditLogJson auditLogJson = new AuditLogJson(auditLog);
    Assert.assertEquals(auditLogJson.getChangeType(), changeType.toString());
    Assert.assertNotNull(auditLogJson.getChangeDate());
    Assert.assertEquals(auditLogJson.getChangedBy(), callContext.getUserName());
    Assert.assertEquals(auditLogJson.getReasonCode(), callContext.getReasonCode());
    Assert.assertEquals(auditLogJson.getComments(), callContext.getComments());
    Assert.assertEquals(auditLogJson.getUserToken(), callContext.getUserToken().toString());
}
Also used : EntityAudit(org.killbill.billing.util.dao.EntityAudit) TableName(org.killbill.billing.util.dao.TableName) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) ChangeType(org.killbill.billing.util.audit.ChangeType) AuditLogModelDao(org.killbill.billing.util.audit.dao.AuditLogModelDao) AuditLog(org.killbill.billing.util.audit.AuditLog) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) Test(org.testng.annotations.Test)

Aggregations

ChangeType (org.killbill.billing.util.audit.ChangeType)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 AuditLog (org.killbill.billing.util.audit.AuditLog)1 DefaultAuditLog (org.killbill.billing.util.audit.DefaultAuditLog)1 AuditLogModelDao (org.killbill.billing.util.audit.dao.AuditLogModelDao)1 EntityAudit (org.killbill.billing.util.dao.EntityAudit)1 TableName (org.killbill.billing.util.dao.TableName)1 WithProfilingCallback (org.killbill.commons.profiling.Profiling.WithProfilingCallback)1 Test (org.testng.annotations.Test)1