Search in sources :

Example 6 with TagModelDao

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);
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao)

Example 7 with TagModelDao

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;
        }
    }
}
Also used : TagApiException(org.killbill.billing.util.api.TagApiException) TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 8 with TagModelDao

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);
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) EntitySqlDaoTransactionalJdbiWrapper(org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper) Test(org.testng.annotations.Test)

Example 9 with TagModelDao

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());
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 10 with TagModelDao

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);
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) TagDefinitionModelDao(org.killbill.billing.util.tag.dao.TagDefinitionModelDao) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

TagModelDao (org.killbill.billing.util.tag.dao.TagModelDao)10 Test (org.testng.annotations.Test)7 UUID (java.util.UUID)6 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)5 EntitySqlDaoTransactionalJdbiWrapper (org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper)2 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)2 Tag (org.killbill.billing.util.tag.Tag)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 TagApiException (org.killbill.billing.util.api.TagApiException)1