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);
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations