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;
}
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());
}
Aggregations