@Override public boolean apply(final AuditLog auditLog) { // As we consume the data source, cache the entries cacheAuditLog(auditLog); return objectId.equals(auditLog.getAuditedEntityId()) && // Given our ordering, this should always be true for the first entry ChangeType.INSERT.equals(auditLog.getChangeType()); } }).orNull();
@Override public void bind(final SQLStatement<?> q, final EntityHistoryBinder bind, final EntityHistoryModelDao<M, E> history) { try { // Emulate @SmartBindBean final M arg = history.getEntity(); final BeanInfo infos = Introspector.getBeanInfo(arg.getClass()); final PropertyDescriptor[] props = infos.getPropertyDescriptors(); for (final PropertyDescriptor prop : props) { q.bind(prop.getName(), prop.getReadMethod().invoke(arg)); } q.bind("id", history.getId()); q.bind("targetRecordId", history.getTargetRecordId()); q.bind("changeType", history.getChangeType().toString()); } catch (IntrospectionException e) { logger.warn(e.getMessage()); } catch (InvocationTargetException e) { logger.warn(e.getMessage()); } catch (IllegalAccessException e) { logger.warn(e.getMessage()); } } };
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (tableName != null ? tableName.hashCode() : 0); result = 31 * result + (targetRecordId != null ? targetRecordId.hashCode() : 0); result = 31 * result + (changeType != null ? changeType.hashCode() : 0); return result; } }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { this.id = new UUID(in.readLong(), in.read()); this.createdDate = new DateTime(in.readUTF()); this.updatedDate = new DateTime(in.readUTF()); this.tableName = TableName.valueOf(in.readUTF()); this.targetRecordId = in.readLong(); this.changeType = ChangeType.valueOf(in.readUTF()); this.callContext = (DefaultCallContext) in.readObject(); this.recordId = in.readLong(); this.accountRecordId = in.readLong(); this.tenantRecordId = in.readLong(); }
@Override public void writeExternal(final ObjectOutput oo) throws IOException { oo.writeLong(id.getMostSignificantBits()); oo.writeLong(id.getLeastSignificantBits()); oo.writeUTF(createdDate.toString()); oo.writeUTF(updatedDate.toString()); oo.writeUTF(tableName.name()); oo.writeLong(targetRecordId); oo.writeUTF(changeType.name()); oo.writeObject(callContext); oo.writeLong(recordId); oo.writeLong(accountRecordId); oo.writeLong(tenantRecordId); } }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { this.id = new UUID(in.readLong(), in.read()); this.createdDate = new DateTime(in.readUTF()); this.updatedDate = new DateTime(in.readUTF()); this.tableName = TableName.valueOf(in.readUTF()); this.targetRecordId = in.readLong(); this.changeType = ChangeType.valueOf(in.readUTF()); this.callContext = (DefaultCallContext) in.readObject(); this.recordId = in.readLong(); this.accountRecordId = in.readLong(); this.tenantRecordId = in.readLong(); }
@Override public void writeExternal(final ObjectOutput oo) throws IOException { oo.writeLong(id.getMostSignificantBits()); oo.writeLong(id.getLeastSignificantBits()); oo.writeUTF(createdDate.toString()); oo.writeUTF(updatedDate.toString()); oo.writeUTF(tableName.name()); oo.writeLong(targetRecordId); oo.writeUTF(changeType.name()); oo.writeObject(callContext); oo.writeLong(recordId); oo.writeLong(accountRecordId); oo.writeLong(tenantRecordId); } }
private List<AuditLog> filterAuditLogs(final AuditLevel auditLevel, final List<AuditLog> auditLogs) { // TODO Do the filtering in the query if (AuditLevel.FULL.equals(auditLevel)) { return auditLogs; } else if (AuditLevel.MINIMAL.equals(auditLevel) && !auditLogs.isEmpty()) { if (ChangeType.INSERT.equals(auditLogs.get(0).getChangeType())) { return ImmutableList.<AuditLog>of(auditLogs.get(0)); } else { // We may be coming here via the history code path - only a single mapped history record id // will be for the initial INSERT return ImmutableList.<AuditLog>of(); } } else if (AuditLevel.NONE.equals(auditLevel)) { return ImmutableList.<AuditLog>of(); } else { return auditLogs; } } }
@Override public void bind(final SQLStatement<?> q, final EntityHistoryBinder bind, final EntityHistoryModelDao<M, E> history) { try { // Emulate @SmartBindBean final M arg = history.getEntity(); final BeanInfo infos = Introspector.getBeanInfo(arg.getClass()); final PropertyDescriptor[] props = infos.getPropertyDescriptors(); for (final PropertyDescriptor prop : props) { q.bind(prop.getName(), prop.getReadMethod().invoke(arg)); } q.bind("id", history.getId()); q.bind("targetRecordId", history.getTargetRecordId()); q.bind("changeType", history.getChangeType().toString()); } catch (IntrospectionException e) { logger.warn(e.getMessage()); } catch (InvocationTargetException e) { logger.warn(e.getMessage()); } catch (IllegalAccessException e) { logger.warn(e.getMessage()); } } };
@Override public int hashCode() { int result = id != null ? id.hashCode() : 0; result = 31 * result + (createdDate != null ? createdDate.hashCode() : 0); result = 31 * result + (updatedDate != null ? updatedDate.hashCode() : 0); result = 31 * result + (tableName != null ? tableName.hashCode() : 0); result = 31 * result + (targetRecordId != null ? targetRecordId.hashCode() : 0); result = 31 * result + (changeType != null ? changeType.hashCode() : 0); result = 31 * result + (callContext != null ? callContext.hashCode() : 0); result = 31 * result + (recordId != null ? recordId.hashCode() : 0); result = 31 * result + (accountRecordId != null ? accountRecordId.hashCode() : 0); result = 31 * result + (tenantRecordId != null ? tenantRecordId.hashCode() : 0); return result; }
private void insertAudits(final TableName tableName, final M entityModelDao, final Long entityRecordId, final Long historyRecordId, final ChangeType changeType, final InternalCallContext contextMaybeWithoutAccountRecordId) { final TableName destinationTableName = MoreObjects.firstNonNull(tableName.getHistoryTableName(), tableName); final EntityAudit audit = new EntityAudit(destinationTableName, historyRecordId, changeType, contextMaybeWithoutAccountRecordId.getCreatedDate()); final InternalCallContext context; // Populate the account record id when creating the account record if (TableName.ACCOUNT.equals(tableName) && ChangeType.INSERT.equals(changeType)) { // AccountModelDao in practice final TimeZoneAwareEntity accountModelDao = (TimeZoneAwareEntity) entityModelDao; context = internalCallContextFactory.createInternalCallContext(accountModelDao, entityRecordId, contextMaybeWithoutAccountRecordId); } else { context = contextMaybeWithoutAccountRecordId; } sqlDao.insertAuditFromTransaction(audit, context); printSQLWarnings(); // We need to invalidate the caches. There is a small window of doom here where caches will be stale. // TODO Knowledge on how the key is constructed is also in AuditSqlDao if (tableName.getHistoryTableName() != null) { final CacheController<String, List> cacheController = cacheControllerDispatcher.getCacheController(CacheType.AUDIT_LOG_VIA_HISTORY); if (cacheController != null) { final String key = buildCacheKey(ImmutableMap.<Integer, Object>of(0, tableName.getHistoryTableName(), 1, tableName.getHistoryTableName(), 2, entityRecordId)); cacheController.remove(key); } } else { final CacheController<String, List> cacheController = cacheControllerDispatcher.getCacheController(CacheType.AUDIT_LOG); if (cacheController != null) { final String key = buildCacheKey(ImmutableMap.<Integer, Object>of(0, tableName, 1, entityRecordId)); cacheController.remove(key); } } }
public AuditLogJson(final AuditLog auditLog) { this(auditLog.getChangeType().toString(), auditLog.getCreatedDate(), auditLog.getAuditedObjectType(), auditLog.getAuditedEntityId(), auditLog.getUserName(), auditLog.getReasonCode(), auditLog.getComment(), auditLog.getUserToken(), null); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (tableName != null ? tableName.hashCode() : 0); result = 31 * result + (targetRecordId != null ? targetRecordId.hashCode() : 0); result = 31 * result + (changeType != null ? changeType.hashCode() : 0); return result; } }
@Override public boolean apply(final AuditLog auditLog) { // As we consume the data source, cache the entries cacheAuditLog(auditLog); return objectId.equals(auditLog.getAuditedEntityId()) && // Given our ordering, this should always be true for the first entry ChangeType.INSERT.equals(auditLog.getChangeType()); } }).orNull();
public AuditLogJson(final AuditLogWithHistory auditLogWithHistory) { this(auditLogWithHistory.getChangeType().toString(), auditLogWithHistory.getCreatedDate(), auditLogWithHistory.getAuditedObjectType(), auditLogWithHistory.getAuditedEntityId(), auditLogWithHistory.getUserName(), auditLogWithHistory.getReasonCode(), auditLogWithHistory.getComment(), auditLogWithHistory.getUserToken(), auditLogWithHistory.getEntity()); }
@Override public int hashCode() { int result = id != null ? id.hashCode() : 0; result = 31 * result + (createdDate != null ? createdDate.hashCode() : 0); result = 31 * result + (updatedDate != null ? updatedDate.hashCode() : 0); result = 31 * result + (tableName != null ? tableName.hashCode() : 0); result = 31 * result + (targetRecordId != null ? targetRecordId.hashCode() : 0); result = 31 * result + (changeType != null ? changeType.hashCode() : 0); result = 31 * result + (callContext != null ? callContext.hashCode() : 0); result = 31 * result + (recordId != null ? recordId.hashCode() : 0); result = 31 * result + (accountRecordId != null ? accountRecordId.hashCode() : 0); result = 31 * result + (tenantRecordId != null ? tenantRecordId.hashCode() : 0); return result; }
private List<AuditLog> filterAuditLogs(final AuditLevel auditLevel, final List<AuditLog> auditLogs) { // TODO Do the filtering in the query if (AuditLevel.FULL.equals(auditLevel)) { return auditLogs; } else if (AuditLevel.MINIMAL.equals(auditLevel) && !auditLogs.isEmpty()) { if (ChangeType.INSERT.equals(auditLogs.get(0).getChangeType())) { return ImmutableList.<AuditLog>of(auditLogs.get(0)); } else { // We may be coming here via the history code path - only a single mapped history record id // will be for the initial INSERT return ImmutableList.<AuditLog>of(); } } else if (AuditLevel.NONE.equals(auditLevel)) { return ImmutableList.<AuditLog>of(); } else { return auditLogs; } } }
protected AuditLog getInvoiceCreationAuditLog(final UUID invoiceId, final AccountAuditLogs accountAuditLogs) throws OSGIServiceNotAvailable { final List<AuditLog> auditLogsForInvoice = accountAuditLogs.getAuditLogsForInvoice(invoiceId); for (final AuditLog auditLog : auditLogsForInvoice) { if (auditLog.getChangeType().equals(ChangeType.INSERT)) { return auditLog; } } logService.log(LogService.LOG_WARNING, "Unable to find Invoice creation audit log for id " + invoiceId); return null; }
protected AuditLog getInvoicePaymentCreationAuditLog(final UUID invoicePaymentId, final AccountAuditLogs accountAuditLogs) throws OSGIServiceNotAvailable { final List<AuditLog> auditLogsForInvoicePayment = accountAuditLogs.getAuditLogsForInvoicePayment(invoicePaymentId); for (final AuditLog auditLog : auditLogsForInvoicePayment) { if (auditLog.getChangeType().equals(ChangeType.INSERT)) { return auditLog; } } logService.log(LogService.LOG_WARNING, "Unable to find Invoice payment creation audit log for id " + invoicePaymentId); return null; }
protected AuditLog getPaymentCreationAuditLog(final UUID paymentId, final AccountAuditLogs accountAuditLogs) throws OSGIServiceNotAvailable { final List<AuditLog> auditLogsForPayment = accountAuditLogs.getAuditLogsForPayment(paymentId); for (final AuditLog auditLog : auditLogsForPayment) { if (auditLog.getChangeType().equals(ChangeType.INSERT)) { return auditLog; } } logService.log(LogService.LOG_WARNING, "Unable to find payment creation audit log for id " + paymentId); return null; }