Search in sources :

Example 21 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class TestDefaultControlTagDeletionEvent 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 DefaultControlTagDeletionEvent event = new DefaultControlTagDeletionEvent(tagId, objectId, objectType, tagDefinition, 1L, 2L, UUID.randomUUID());
    final String json = objectMapper.writeValueAsString(event);
    final DefaultControlTagDeletionEvent fromJson = objectMapper.readValue(json, DefaultControlTagDeletionEvent.class);
    Assert.assertEquals(fromJson, event);
}
Also used : ObjectType(org.killbill.billing.ObjectType) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) TagDefinition(org.killbill.billing.util.tag.TagDefinition) DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UUID(java.util.UUID) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 22 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class TestFieldStore method testCreateCustomField.

@Test(groups = "slow")
public void testCreateCustomField() throws CustomFieldApiException {
    final UUID id = UUID.randomUUID();
    final ObjectType objectType = ObjectType.ACCOUNT;
    String fieldName = "TestField1";
    String fieldValue = "Kitty Hawk";
    eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
    customFieldDao.create(new CustomFieldModelDao(internalCallContext.getCreatedDate(), fieldName, fieldValue, id, objectType), internalCallContext);
    assertListenerStatus();
    fieldName = "TestField2";
    fieldValue = "Cape Canaveral";
    eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
    customFieldDao.create(new CustomFieldModelDao(internalCallContext.getCreatedDate(), fieldName, fieldValue, id, objectType), internalCallContext);
    assertListenerStatus();
}
Also used : ObjectType(org.killbill.billing.ObjectType) CustomFieldModelDao(org.killbill.billing.util.customfield.dao.CustomFieldModelDao) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 23 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class EhCacheCatalogCache method initializeCacheLoaderArgument.

//
// Build the LoaderCallback that is required to build the catalog from the xml from a module that knows
// nothing about catalog.
//
// This is a contract between the TenantCatalogCacheLoader and the EhCacheCatalogCache
private CacheLoaderArgument initializeCacheLoaderArgument(final boolean filterTemplateCatalog) {
    final LoaderCallback loaderCallback = new LoaderCallback() {

        @Override
        public Object loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException {
            return loader.load(catalogXMLs, filterTemplateCatalog, tenantRecordId);
        }
    };
    final Object[] args = new Object[1];
    args[0] = loaderCallback;
    final ObjectType irrelevant = null;
    final InternalTenantContext notUsed = null;
    return new CacheLoaderArgument(irrelevant, args, notUsed);
}
Also used : ObjectType(org.killbill.billing.ObjectType) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) LoaderCallback(org.killbill.billing.util.cache.TenantCatalogCacheLoader.LoaderCallback) CacheLoaderArgument(org.killbill.billing.util.cache.CacheLoaderArgument)

Example 24 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class EntitySqlDaoWrapperInvocationHandler method getObjectType.

/**
     * Extract object from sqlDaoClass by looking at first parameter type (EntityModelDao) and
     * constructing an empty object so we can call the getObjectType method on it.
     *
     * @return the objectType associated to that handler
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws ClassNotFoundException
     */
private ObjectType getObjectType() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    int foundIndexForEntitySqlDao = -1;
    // If the sqlDaoClass implements multiple interfaces, first figure out which one is the EntitySqlDao
    for (int i = 0; i < sqlDaoClass.getGenericInterfaces().length; i++) {
        final Type type = sqlDaoClass.getGenericInterfaces()[0];
        if (!(type instanceof java.lang.reflect.ParameterizedType)) {
            // AuditSqlDao for example won't extend EntitySqlDao
            return null;
        }
        if (EntitySqlDao.class.getName().equals(((Class) ((java.lang.reflect.ParameterizedType) type).getRawType()).getName())) {
            foundIndexForEntitySqlDao = i;
            break;
        }
    }
    // Find out from the parameters of the EntitySqlDao which one is the EntityModelDao, and extract his (sub)type to finally return the ObjectType
    if (foundIndexForEntitySqlDao >= 0) {
        final Type[] types = ((java.lang.reflect.ParameterizedType) sqlDaoClass.getGenericInterfaces()[foundIndexForEntitySqlDao]).getActualTypeArguments();
        int foundIndexForEntityModelDao = -1;
        for (int i = 0; i < types.length; i++) {
            final Class clz = ((Class) types[i]);
            if (EntityModelDao.class.getName().equals(((Class) ((java.lang.reflect.ParameterizedType) clz.getGenericInterfaces()[0]).getRawType()).getName())) {
                foundIndexForEntityModelDao = i;
                break;
            }
        }
        if (foundIndexForEntityModelDao >= 0) {
            final String modelClassName = ((Class) types[foundIndexForEntityModelDao]).getName();
            final Class<? extends EntityModelDao<?>> clz = (Class<? extends EntityModelDao<?>>) Class.forName(modelClassName);
            final EntityModelDao<?> modelDao = (EntityModelDao<?>) clz.newInstance();
            return modelDao.getTableName().getObjectType();
        }
    }
    return null;
}
Also used : NonEntitySqlDao(org.killbill.billing.util.dao.NonEntitySqlDao) CacheType(org.killbill.billing.util.cache.Cachable.CacheType) ChangeType(org.killbill.billing.util.audit.ChangeType) ProfilingFeatureType(org.killbill.commons.profiling.ProfilingFeature.ProfilingFeatureType) ObjectType(org.killbill.billing.ObjectType) Type(java.lang.reflect.Type)

Example 25 with ObjectType

use of org.killbill.billing.ObjectType in project killbill by killbill.

the class BaseIdCacheLoader method load.

@Override
public Object load(final Object key, final Object argument) {
    checkCacheLoaderStatus();
    if (!(key instanceof String)) {
        throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
    }
    if (!(argument instanceof CacheLoaderArgument)) {
        throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName());
    }
    final String rawKey;
    if (getCacheType().isKeyPrefixedWithTableName()) {
        final String[] parts = ((String) key).split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
        rawKey = parts[1];
    } else {
        rawKey = (String) key;
    }
    final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType();
    final Handle handle = ((CacheLoaderArgument) argument).getHandle();
    return doRetrieveOperation(rawKey, objectType, handle);
}
Also used : ObjectType(org.killbill.billing.ObjectType) Handle(org.skife.jdbi.v2.Handle)

Aggregations

ObjectType (org.killbill.billing.ObjectType)41 UUID (java.util.UUID)27 Test (org.testng.annotations.Test)25 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)12 TagDefinition (org.killbill.billing.util.tag.TagDefinition)12 CacheLoaderArgument (org.killbill.billing.util.cache.CacheLoaderArgument)11 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)9 ObjectMapper (org.killbill.billing.util.jackson.ObjectMapper)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 TagInternalEvent (org.killbill.billing.events.TagInternalEvent)3 DescriptiveTag (org.killbill.billing.util.tag.DescriptiveTag)3 TagDefinitionModelDao (org.killbill.billing.util.tag.dao.TagDefinitionModelDao)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 DefaultPlan (org.killbill.billing.catalog.DefaultPlan)2 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)2 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)2 ControlTagCreationInternalEvent (org.killbill.billing.events.ControlTagCreationInternalEvent)2 ControlTagDeletionInternalEvent (org.killbill.billing.events.ControlTagDeletionInternalEvent)2