use of org.killbill.billing.util.tag.dao.TagModelDao in project killbill by killbill.
the class DefaultTagInternalApi method addTag.
@Override
public void addTag(final UUID objectId, final ObjectType objectType, final UUID tagDefinitionId, final InternalCallContext context) throws TagApiException {
final TagModelDao tag = new TagModelDao(context.getCreatedDate(), tagDefinitionId, objectId, objectType);
tagDao.create(tag, context);
}
use of org.killbill.billing.util.tag.dao.TagModelDao in project killbill by killbill.
the class DefaultTagUserApi method addTag.
@Override
public void addTag(final UUID objectId, final ObjectType objectType, final UUID tagDefinitionId, final CallContext context) throws TagApiException {
if (SystemTags.isSystemTag(tagDefinitionId)) {
// TODO Create a proper ErrorCode instaed
throw new IllegalStateException(String.format("Failed to add tag for tagDefinitionId='%s': System tags are reserved for the system.", tagDefinitionId));
}
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(objectId, objectType, context);
final TagModelDao tag = new TagModelDao(context.getCreatedDate(), tagDefinitionId, objectId, objectType);
try {
tagDao.create(tag, internalContext);
} catch (TagApiException e) {
// Be lenient here and make the addTag method idempotent
if (ErrorCode.TAG_ALREADY_EXISTS.getCode() != e.getCode()) {
throw e;
}
}
}
use of org.killbill.billing.util.tag.dao.TagModelDao in project killbill by killbill.
the class TestCache method testCacheRecordId.
@Test(groups = "slow")
public void testCacheRecordId() throws Exception {
this.transactionalSqlDao = new EntitySqlDaoTransactionalJdbiWrapper(dbi, clock, controlCacheDispatcher, nonEntityDao, internalCallContextFactory);
final TagModelDao tag = new TagModelDao(clock.getUTCNow(), UUID.randomUUID(), UUID.randomUUID(), ObjectType.TAG);
// Verify we start with nothing in the cache
Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 0);
insertTag(tag);
// Verify we still have nothing after insert in the cache
Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 0);
final Long tagRecordId = getTagRecordId(tag.getId());
// Verify we now have something in the cache
Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 1);
final Long recordIdFromCache = retrieveRecordIdFromCache(tag.getId());
Assert.assertNotNull(recordIdFromCache);
Assert.assertEquals(recordIdFromCache, tagRecordId);
// We cannot assume the number to be 1 here as the auto_increment implementation
// depends on the database.
// See also http://h2database.com/html/grammar.html#create_sequence
Assert.assertTrue(recordIdFromCache > 0);
Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 1);
}
use of org.killbill.billing.util.tag.dao.TagModelDao in project killbill by killbill.
the class TestTagStore method testTagCreationAndRetrieval.
@Test(groups = "slow")
public void testTagCreationAndRetrieval() throws TagApiException, TagDefinitionApiException {
final UUID accountId = UUID.randomUUID();
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
tagDefinitionDao.create("tag1", "First tag", internalCallContext);
assertListenerStatus();
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
final TagDefinitionModelDao testTagDefinition = tagDefinitionDao.create("testTagDefinition", "Second tag", internalCallContext);
assertListenerStatus();
final Tag tag = new DescriptiveTag(testTagDefinition.getId(), ObjectType.ACCOUNT, accountId, clock.getUTCNow());
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagDao.create(new TagModelDao(tag), internalCallContext);
assertListenerStatus();
final TagModelDao savedTag = tagDao.getById(tag.getId(), internalCallContext);
assertEquals(savedTag.getTagDefinitionId(), tag.getTagDefinitionId());
assertEquals(savedTag.getId(), tag.getId());
}
use of org.killbill.billing.util.tag.dao.TagModelDao in project killbill by killbill.
the class TestTagStore method testTagDefinitionDeletionForDefinitionInUse.
@Test(groups = "slow", expectedExceptions = TagDefinitionApiException.class)
public void testTagDefinitionDeletionForDefinitionInUse() throws TagDefinitionApiException, TagApiException {
final String definitionName = "TestTag12345";
eventsListener.pushExpectedEvent(NextEvent.TAG_DEFINITION);
tagDefinitionDao.create(definitionName, "Some test tag", internalCallContext);
assertListenerStatus();
final TagDefinitionModelDao tagDefinition = tagDefinitionDao.getByName(definitionName, internalCallContext);
assertNotNull(tagDefinition);
final UUID objectId = UUID.randomUUID();
final Tag tag = new DescriptiveTag(tagDefinition.getId(), ObjectType.ACCOUNT, objectId, internalCallContext.getCreatedDate());
eventsListener.pushExpectedEvent(NextEvent.TAG);
tagDao.create(new TagModelDao(tag), internalCallContext);
assertListenerStatus();
tagDefinitionDao.deleteById(tagDefinition.getId(), internalCallContext);
}
Aggregations