Search in sources :

Example 41 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class AuditLogCacheLoader 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 Object[] args = ((CacheLoaderArgument) argument).getArgs();
    final String tableName = (String) args[0];
    final Long targetRecordId = (Long) args[1];
    final InternalTenantContext internalTenantContext = (InternalTenantContext) args[2];
    return auditSqlDao.getAuditLogsForTargetRecordId(tableName, targetRecordId, internalTenantContext);
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext)

Example 42 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class AuditLogViaHistoryCacheLoader 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 Object[] args = ((CacheLoaderArgument) argument).getArgs();
    final String tableName = (String) args[0];
    final String historyTableName = (String) args[1];
    final Long targetRecordId = (Long) args[2];
    final InternalTenantContext internalTenantContext = (InternalTenantContext) args[3];
    return auditSqlDao.getAuditLogsViaHistoryForTargetRecordId(tableName, historyTableName, targetRecordId, internalTenantContext);
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext)

Example 43 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class OverriddenPlanCacheLoader 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 argument type of " + argument.getClass().getName());
    }
    final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
    if (cacheLoaderArgument.getArgs() == null || cacheLoaderArgument.getArgs().length != 2) {
        throw new IllegalArgumentException("Invalid arguments for overridden plans");
    }
    if (!(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) {
        throw new IllegalArgumentException("Invalid arguments for overridden plans: missing loaderCallback from argument");
    }
    if (!(cacheLoaderArgument.getArgs()[1] instanceof StaticCatalog)) {
        throw new IllegalArgumentException("Invalid arguments for overridden plans: missing catalog from argument");
    }
    final String planName = (String) key;
    final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0];
    final StaticCatalog catalog = (StaticCatalog) cacheLoaderArgument.getArgs()[1];
    final InternalTenantContext internalTenantContext = ((CacheLoaderArgument) argument).getInternalTenantContext();
    try {
        log.info("Loading overridden plan {} for tenant {}", planName, internalTenantContext.getTenantRecordId());
        return callback.loadPlan(planName, catalog, internalTenantContext);
    } catch (final CatalogApiException e) {
        throw new IllegalStateException(String.format("Failed to load overridden plan for tenant %s : %s", planName, internalTenantContext.getTenantRecordId()), e);
    }
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog)

Example 44 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class TenantConfigCacheLoader method load.

@Override
public Object load(final Object key, final Object argument) {
    checkCacheLoaderStatus();
    if (!(key instanceof Long)) {
        throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName());
    }
    if (!(argument instanceof CacheLoaderArgument)) {
        throw new IllegalArgumentException("Unexpected argument type of " + argument.getClass().getName());
    }
    final Long tenantRecordId = (Long) key;
    final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId);
    final CacheLoaderArgument cacheLoaderArgument = (CacheLoaderArgument) argument;
    if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) {
        throw new IllegalArgumentException("Missing LoaderCallback from the arguments ");
    }
    final LoaderCallback loader = (LoaderCallback) cacheLoaderArgument.getArgs()[0];
    final String jsonValue = tenantApi.getTenantConfig(internalTenantContext);
    try {
        return loader.loadConfig(jsonValue);
    } catch (final IOException e) {
        throw new IllegalArgumentException("Failed to deserialize per tenant config for tenant recordId = " + tenantRecordId, e);
    }
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) IOException(java.io.IOException)

Example 45 with InternalTenantContext

use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.

the class TenantKVCacheLoader 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[] parts = ((String) key).split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR);
    final String rawKey = parts[0];
    final String tenantRecordId = parts[1];
    final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId));
    final List<String> valuesForKey = tenantApi.getTenantValuesForKey(rawKey, internalTenantContext);
    if (valuesForKey == null || valuesForKey.isEmpty()) {
        return EMPTY_VALUE_PLACEHOLDER;
    }
    if (valuesForKey.size() > 1) {
        throw new IllegalStateException("TenantKVCacheLoader expecting no more than one value for key " + key);
    }
    return valuesForKey.get(0);
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext)

Aggregations

InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)56 UUID (java.util.UUID)9 ArrayList (java.util.ArrayList)8 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)8 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)7 CacheLoaderArgument (org.killbill.billing.util.cache.CacheLoaderArgument)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 LocalDate (org.joda.time.LocalDate)6 Predicate (com.google.common.base.Predicate)5 IOException (java.io.IOException)5 ObjectType (org.killbill.billing.ObjectType)5 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)5 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)5 InputStream (java.io.InputStream)4 URI (java.net.URI)4 DateTime (org.joda.time.DateTime)4 Account (org.killbill.billing.account.api.Account)4 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)4 Invoice (org.killbill.billing.invoice.api.Invoice)4