Search in sources :

Example 6 with AuditLog

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

the class AuditChecker method checkInvoiceCreated.

/**
     * ********************************************  INVOICE *******************************************************
     */
public void checkInvoiceCreated(final Invoice invoice, final CallContext context) {
    final List<AuditLog> invoiceLogs = getAuditLogForInvoice(invoice, context);
    Assert.assertEquals(invoiceLogs.size(), 1);
    checkAuditLog(ChangeType.INSERT, context, invoiceLogs.get(0), invoice.getId(), InvoiceSqlDao.class, false, false);
    for (InvoiceItem cur : invoice.getInvoiceItems()) {
        final List<AuditLog> auditLogs = getAuditLogForInvoiceItem(cur, context);
        Assert.assertEquals(auditLogs.size(), 1);
        checkAuditLog(ChangeType.INSERT, context, auditLogs.get(0), cur.getId(), InvoiceItemSqlDao.class, false, false);
    }
}
Also used : InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) AuditLog(org.killbill.billing.util.audit.AuditLog)

Example 7 with AuditLog

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

the class AuditChecker method checkPaymentCreated.

/**
     * ********************************************  PAYMENT *******************************************************
     */
public void checkPaymentCreated(final Payment payment, final CallContext context) {
    final List<AuditLog> paymentLogs = getAuditLogForPayment(payment, context);
    Assert.assertEquals(paymentLogs.size(), 2);
    checkAuditLog(ChangeType.INSERT, context, paymentLogs.get(0), payment.getId(), PaymentSqlDao.class, true, false);
    checkAuditLog(ChangeType.UPDATE, context, paymentLogs.get(1), payment.getId(), PaymentSqlDao.class, true, false);
    for (PaymentTransaction cur : payment.getTransactions()) {
        final List<AuditLog> auditLogs = getAuditLogForPaymentTransaction(payment, cur, context);
        Assert.assertEquals(auditLogs.size(), 2);
        checkAuditLog(ChangeType.INSERT, context, auditLogs.get(0), cur.getId(), TransactionSqlDao.class, true, false);
        checkAuditLog(ChangeType.UPDATE, context, auditLogs.get(1), cur.getId(), TransactionSqlDao.class, true, false);
    }
}
Also used : PaymentTransaction(org.killbill.billing.payment.api.PaymentTransaction) AuditLog(org.killbill.billing.util.audit.AuditLog)

Example 8 with AuditLog

use of org.killbill.billing.util.audit.AuditLog 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)

Example 9 with AuditLog

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

the class DefaultAuditDao method getAuditLogsForAccountRecordId.

@Override
public DefaultAccountAuditLogsForObjectType getAuditLogsForAccountRecordId(final TableName tableName, final AuditLevel auditLevel, final InternalTenantContext context) {
    final String actualTableName;
    if (tableName.hasHistoryTable()) {
        // upper cased
        actualTableName = tableName.getHistoryTableName().name();
    } else {
        actualTableName = tableName.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> auditLogsForTableNameAndAccountRecordId = auditSqlDao.getAuditLogsForTableNameAndAccountRecordId(actualTableName, context);
    final Iterator<AuditLog> allAuditLogs = buildAuditLogsFromModelDao(auditLogsForTableNameAndAccountRecordId, context);
    return new DefaultAccountAuditLogsForObjectType(auditLevel, allAuditLogs);
}
Also used : EntitySqlDao(org.killbill.billing.util.entity.dao.EntitySqlDao) NonEntitySqlDao(org.killbill.billing.util.dao.NonEntitySqlDao) DefaultAccountAuditLogsForObjectType(org.killbill.billing.util.audit.DefaultAccountAuditLogsForObjectType) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) AuditLog(org.killbill.billing.util.audit.AuditLog)

Example 10 with AuditLog

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

the class DefaultAuditDao method buildAuditLogsFromModelDao.

private Iterator<AuditLog> buildAuditLogsFromModelDao(final Iterator<AuditLogModelDao> auditLogsForAccountRecordId, final InternalTenantContext tenantContext) {
    final Map<TableName, Map<Long, UUID>> recordIdIdsCache = new HashMap<TableName, Map<Long, UUID>>();
    final Map<TableName, Map<Long, UUID>> historyRecordIdIdsCache = new HashMap<TableName, Map<Long, UUID>>();
    return Iterators.<AuditLogModelDao, AuditLog>transform(auditLogsForAccountRecordId, new Function<AuditLogModelDao, AuditLog>() {

        @Override
        public AuditLog apply(final AuditLogModelDao input) {
            // If input is for e.g. TAG_DEFINITION_HISTORY, retrieve TAG_DEFINITIONS
            // For tables without history, e.g. TENANT, originalTableNameForHistoryTableName will be null
            final TableName originalTableNameForHistoryTableName = findTableNameForHistoryTableName(input.getTableName());
            final ObjectType objectType;
            final UUID auditedEntityId;
            if (originalTableNameForHistoryTableName != null) {
                // input point to a history entry
                objectType = originalTableNameForHistoryTableName.getObjectType();
                if (historyRecordIdIdsCache.get(originalTableNameForHistoryTableName) == null) {
                    if (TableName.ACCOUNT.equals(originalTableNameForHistoryTableName)) {
                        final Iterable<RecordIdIdMappings> mappings = nonEntitySqlDao.getHistoryRecordIdIdMappingsForAccountsTable(originalTableNameForHistoryTableName.getTableName(), input.getTableName().getTableName(), tenantContext);
                        historyRecordIdIdsCache.put(originalTableNameForHistoryTableName, RecordIdIdMappings.toMap(mappings));
                    } else if (TableName.TAG_DEFINITIONS.equals(originalTableNameForHistoryTableName)) {
                        final Iterable<RecordIdIdMappings> mappings = nonEntitySqlDao.getHistoryRecordIdIdMappingsForTablesWithoutAccountRecordId(originalTableNameForHistoryTableName.getTableName(), input.getTableName().getTableName(), tenantContext);
                        historyRecordIdIdsCache.put(originalTableNameForHistoryTableName, RecordIdIdMappings.toMap(mappings));
                    } else {
                        final Iterable<RecordIdIdMappings> mappings = nonEntitySqlDao.getHistoryRecordIdIdMappings(originalTableNameForHistoryTableName.getTableName(), input.getTableName().getTableName(), tenantContext);
                        historyRecordIdIdsCache.put(originalTableNameForHistoryTableName, RecordIdIdMappings.toMap(mappings));
                    }
                }
                auditedEntityId = historyRecordIdIdsCache.get(originalTableNameForHistoryTableName).get(input.getTargetRecordId());
            } else {
                objectType = input.getTableName().getObjectType();
                if (recordIdIdsCache.get(input.getTableName()) == null) {
                    final Iterable<RecordIdIdMappings> mappings = nonEntitySqlDao.getRecordIdIdMappings(input.getTableName().getTableName(), tenantContext);
                    recordIdIdsCache.put(input.getTableName(), RecordIdIdMappings.toMap(mappings));
                }
                auditedEntityId = recordIdIdsCache.get(input.getTableName()).get(input.getTargetRecordId());
            }
            return new DefaultAuditLog(input, objectType, auditedEntityId);
        }

        private TableName findTableNameForHistoryTableName(final TableName historyTableName) {
            for (final TableName tableName : TableName.values()) {
                if (historyTableName.equals(tableName.getHistoryTableName())) {
                    return tableName;
                }
            }
            return null;
        }
    });
}
Also used : HashMap(java.util.HashMap) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) AuditLog(org.killbill.billing.util.audit.AuditLog) TableName(org.killbill.billing.util.dao.TableName) ObjectType(org.killbill.billing.ObjectType) DefaultAccountAuditLogsForObjectType(org.killbill.billing.util.audit.DefaultAccountAuditLogsForObjectType) DefaultAuditLog(org.killbill.billing.util.audit.DefaultAuditLog) RecordIdIdMappings(org.killbill.billing.util.dao.RecordIdIdMappings) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AuditLog (org.killbill.billing.util.audit.AuditLog)16 UUID (java.util.UUID)6 DefaultAuditLog (org.killbill.billing.util.audit.DefaultAuditLog)5 Test (org.testng.annotations.Test)5 TableName (org.killbill.billing.util.dao.TableName)4 LinkedList (java.util.LinkedList)3 TagDefinition (org.killbill.billing.util.tag.TagDefinition)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 AccountEmail (org.killbill.billing.account.api.AccountEmail)2 DefaultAccountEmail (org.killbill.billing.account.api.DefaultAccountEmail)2 TagDefinitionJson (org.killbill.billing.jaxrs.json.TagDefinitionJson)2 AuditLevel (org.killbill.billing.util.api.AuditLevel)2 AccountAuditLogsForObjectType (org.killbill.billing.util.audit.AccountAuditLogsForObjectType)2 DefaultAccountAuditLogsForObjectType (org.killbill.billing.util.audit.DefaultAccountAuditLogsForObjectType)2 TenantContext (org.killbill.billing.util.callcontext.TenantContext)2 NonEntitySqlDao (org.killbill.billing.util.dao.NonEntitySqlDao)2