use of org.killbill.billing.ObjectType 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 NonEntitySqlDao nonEntitySqlDao = dbRouter.onDemand(true);
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;
}
});
}
use of org.killbill.billing.ObjectType in project killbill by killbill.
the class BaseIdCacheLoader method compute.
@Override
public V compute(final String key, final CacheLoaderArgument cacheLoaderArgument) {
final String rawKey;
if (getCacheType().isKeyPrefixedWithTableName()) {
final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
rawKey = parts[1];
} else {
rawKey = key;
}
final ObjectType objectType = cacheLoaderArgument.getObjectType();
final Handle handle = cacheLoaderArgument.getHandle();
return doRetrieveOperation(rawKey, objectType, handle);
}
use of org.killbill.billing.ObjectType in project killbill by killbill.
the class TestDefaultControlTagDeletionEvent method testPojo.
@Test(groups = "fast")
public void testPojo() throws Exception {
final UUID tagId = UUID.randomUUID();
final UUID objectId = UUID.randomUUID();
final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
final UUID tagDefinitionId = UUID.randomUUID();
final String tagDefinitionName = UUID.randomUUID().toString();
final String tagDefinitionDescription = UUID.randomUUID().toString();
final boolean controlTag = false;
final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
final UUID userToken = UUID.randomUUID();
final DefaultControlTagDeletionEvent event = new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
Assert.assertEquals(event.getBusEventType(), BusInternalEvent.BusInternalEventType.CONTROL_TAG_DELETION);
Assert.assertEquals(event.getTagId(), tagId);
Assert.assertEquals(event.getObjectId(), objectId);
Assert.assertEquals(event.getObjectType(), objectType);
Assert.assertEquals(event.getTagDefinition(), tagDefinition);
Assert.assertEquals(event.getTagDefinition().getId(), tagDefinitionId);
Assert.assertEquals(event.getTagDefinition().getName(), tagDefinitionName);
Assert.assertEquals(event.getTagDefinition().getDescription(), tagDefinitionDescription);
Assert.assertEquals(event, event);
Assert.assertEquals(event, new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID()));
Assert.assertTrue(event.equals(event));
Assert.assertTrue(event.equals(new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID())));
}
use of org.killbill.billing.ObjectType in project killbill by killbill.
the class TestDefaultUserTagDeletionEvent method testSerialization.
@Test(groups = "fast")
public void testSerialization() throws Exception {
final ObjectMapper objectMapper = new ObjectMapper();
final UUID tagId = UUID.randomUUID();
final UUID objectId = UUID.randomUUID();
final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
final UUID tagDefinitionId = UUID.randomUUID();
final String tagDefinitionName = UUID.randomUUID().toString();
final String tagDefinitionDescription = UUID.randomUUID().toString();
final boolean controlTag = false;
final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
final UUID userToken = UUID.randomUUID();
final DefaultUserTagDeletionEvent event = new DefaultUserTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
final String json = objectMapper.writeValueAsString(event);
final DefaultUserTagDeletionEvent fromJson = objectMapper.readValue(json, DefaultUserTagDeletionEvent.class);
Assert.assertEquals(fromJson, event);
}
use of org.killbill.billing.ObjectType in project killbill by killbill.
the class TestDefaultUserTagCreationEvent method testSerialization.
@Test(groups = "fast")
public void testSerialization() throws Exception {
final ObjectMapper objectMapper = new ObjectMapper();
final UUID tagId = UUID.randomUUID();
final UUID objectId = UUID.randomUUID();
final ObjectType objectType = ObjectType.ACCOUNT_EMAIL;
final UUID tagDefinitionId = UUID.randomUUID();
final String tagDefinitionName = UUID.randomUUID().toString();
final String tagDefinitionDescription = UUID.randomUUID().toString();
final boolean controlTag = false;
final TagDefinition tagDefinition = new DefaultTagDefinition(tagDefinitionId, tagDefinitionName, tagDefinitionDescription, controlTag);
final UUID userToken = UUID.randomUUID();
final DefaultUserTagCreationEvent event = new DefaultUserTagCreationEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
final String json = objectMapper.writeValueAsString(event);
final DefaultUserTagCreationEvent fromJson = objectMapper.readValue(json, DefaultUserTagCreationEvent.class);
Assert.assertEquals(fromJson, event);
}
Aggregations