use of org.killbill.billing.util.audit.AuditLog in project killbill by killbill.
the class DefaultAuditDao method getAuditLogsForAccountRecordId.
@Override
public DefaultAccountAuditLogs getAuditLogsForAccountRecordId(final AuditLevel auditLevel, final InternalTenantContext context) {
final UUID accountId = nonEntitySqlDao.getIdFromObject(context.getAccountRecordId(), TableName.ACCOUNT.getTableName());
// Lazy evaluate records to minimize the memory footprint (these can yield a lot of results)
// We usually always want to wrap our queries in an EntitySqlDaoTransactionWrapper... except here.
// Since we want to stream the results out, we don't want to auto-commit when this method returns.
final EntitySqlDao auditSqlDao = transactionalSqlDao.onDemandForStreamingResults(EntitySqlDao.class);
final Iterator<AuditLogModelDao> auditLogsForAccountRecordId = auditSqlDao.getAuditLogsForAccountRecordId(context);
final Iterator<AuditLog> allAuditLogs = buildAuditLogsFromModelDao(auditLogsForAccountRecordId, context);
return new DefaultAccountAuditLogs(accountId, auditLevel, allAuditLogs);
}
use of org.killbill.billing.util.audit.AuditLog in project killbill by killbill.
the class DefaultAuditDao method doGetAuditLogsViaHistoryForId.
private List<AuditLog> doGetAuditLogsViaHistoryForId(final TableName tableName, final UUID objectId, final AuditLevel auditLevel, final InternalTenantContext context) {
final TableName historyTableName = tableName.getHistoryTableName();
if (historyTableName == null) {
throw new IllegalStateException("History table shouldn't be null for " + tableName);
}
final Long targetRecordId = nonEntitySqlDao.getRecordIdFromObject(objectId.toString(), tableName.getTableName());
final List<AuditLog> allAuditLogs = transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<List<AuditLog>>() {
@Override
public List<AuditLog> inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception {
final List<AuditLogModelDao> auditLogsViaHistoryForTargetRecordId = entitySqlDaoWrapperFactory.become(EntitySqlDao.class).getAuditLogsViaHistoryForTargetRecordId(historyTableName.name(), historyTableName.getTableName().toLowerCase(), targetRecordId, context);
return buildAuditLogsFromModelDao(auditLogsViaHistoryForTargetRecordId, tableName.getObjectType(), objectId);
}
});
return filterAuditLogs(auditLevel, allAuditLogs);
}
use of org.killbill.billing.util.audit.AuditLog in project killbill by killbill.
the class JaxRsResourceBase method createTagResponse.
protected Response createTagResponse(final UUID accountId, final List<Tag> tags, final AuditMode auditMode, final TenantContext context) throws TagDefinitionApiException {
final AccountAuditLogsForObjectType tagsAuditLogs = auditUserApi.getAccountAuditLogs(accountId, ObjectType.TAG, auditMode.getLevel(), context);
final Map<UUID, TagDefinition> tagDefinitionsCache = new HashMap<UUID, TagDefinition>();
final Collection<TagJson> result = new LinkedList<TagJson>();
for (final Tag tag : tags) {
if (tagDefinitionsCache.get(tag.getTagDefinitionId()) == null) {
tagDefinitionsCache.put(tag.getTagDefinitionId(), tagUserApi.getTagDefinition(tag.getTagDefinitionId(), context));
}
final TagDefinition tagDefinition = tagDefinitionsCache.get(tag.getTagDefinitionId());
final List<AuditLog> auditLogs = tagsAuditLogs.getAuditLogs(tag.getId());
result.add(new TagJson(tag, tagDefinition, auditLogs));
}
return Response.status(Response.Status.OK).entity(result).build();
}
use of org.killbill.billing.util.audit.AuditLog in project killbill by killbill.
the class TestDefaultAuditUserApi method beforeClass.
@Override
@BeforeClass(groups = "fast")
public void beforeClass() throws Exception {
super.beforeClass();
auditLogs = ImmutableList.<AuditLog>of(createAuditLog(), createAuditLog(), createAuditLog(), createAuditLog());
objectIds = ImmutableList.<UUID>of(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID());
for (final TableName tableName : TableName.values()) {
for (final UUID objectId : objectIds) {
for (final AuditLog auditLog : auditLogs) {
((MockAuditDao) auditDao).addAuditLogForId(tableName, objectId, auditLog);
}
}
}
}
use of org.killbill.billing.util.audit.AuditLog in project killbill by killbill.
the class TestDefaultAuditDao method testRetrieveAuditsViaHistory.
@Test(groups = "slow")
public void testRetrieveAuditsViaHistory() throws Exception {
addTag();
for (final AuditLevel level : AuditLevel.values()) {
final List<AuditLog> auditLogs = auditDao.getAuditLogsForId(TableName.TAG, tag.getId(), level, internalCallContext);
verifyAuditLogsForTag(auditLogs, level);
final AccountAuditLogs accountAuditLogs = auditDao.getAuditLogsForAccountRecordId(level, internalCallContext);
verifyAuditLogsForTag(accountAuditLogs.getAuditLogs(ObjectType.TAG).getAuditLogs(tag.getId()), level);
final AccountAuditLogsForObjectType accountAuditLogsForObjectType = auditDao.getAuditLogsForAccountRecordId(TableName.TAG, level, internalCallContext);
verifyAuditLogsForTag(accountAuditLogsForObjectType.getAuditLogs(tag.getId()), level);
}
}
Aggregations