Search in sources :

Example 51 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 52 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 53 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 54 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 55 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)92 UUID (java.util.UUID)15 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)13 CacheLoaderArgument (org.killbill.billing.util.cache.CacheLoaderArgument)11 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)10 ArrayList (java.util.ArrayList)9 ObjectType (org.killbill.billing.ObjectType)9 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)9 TenantContext (org.killbill.billing.util.callcontext.TenantContext)9 ImmutableList (com.google.common.collect.ImmutableList)8 List (java.util.List)8 DefaultInvoice (org.killbill.billing.invoice.model.DefaultInvoice)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 DateTime (org.joda.time.DateTime)7 LocalDate (org.joda.time.LocalDate)7 Predicate (com.google.common.base.Predicate)6 AccountApiException (org.killbill.billing.account.api.AccountApiException)6 VersionedCatalog (org.killbill.billing.catalog.api.VersionedCatalog)6 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)6