use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class DefaultSubscriptionBaseApiService method getPlanChangeResult.
@Override
public PlanChangeResult getPlanChangeResult(final DefaultSubscriptionBase subscription, final PlanSpecifier toPlanPhase, final DateTime effectiveDate, final TenantContext context) throws SubscriptionBaseApiException {
final PlanChangeResult planChangeResult;
try {
final InternalTenantContext internalCallContext = createTenantContextFromBundleId(subscription.getBundleId(), context);
final Plan currentPlan = subscription.getCurrentPlan();
final PlanPhaseSpecifier fromPlanPhase = new PlanPhaseSpecifier(currentPlan.getName(), subscription.getCurrentPhase().getPhaseType());
planChangeResult = catalogService.getFullCatalog(true, true, internalCallContext).planChange(fromPlanPhase, toPlanPhase, effectiveDate);
} catch (final CatalogApiException e) {
throw new SubscriptionBaseApiException(e);
}
return planChangeResult;
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class TenantOverdueConfigCacheLoader 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 callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0];
final String overdueXML = tenantApi.getTenantOverdueConfig(internalTenantContext);
if (overdueXML == null) {
return EMPTY_VALUE_PLACEHOLDER;
}
try {
log.info("Loading overdue cache for tenant " + internalTenantContext.getTenantRecordId());
return callback.loadOverdueConfig(overdueXML);
} catch (final OverdueApiException e) {
throw new IllegalStateException(String.format("Failed to de-serialize overdue config for tenant %s : %s", internalTenantContext.getTenantRecordId(), e.getMessage()), e);
}
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class CacheConfig method initializeCacheLoaderArgument.
private CacheLoaderArgument initializeCacheLoaderArgument() {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
public Object loadConfig(@Nullable final String inputJson) throws IOException {
return inputJson != null ? objectMapper.readValue(inputJson, PerTenantConfig.class) : new PerTenantConfig();
}
};
final Object[] args = new Object[1];
args[0] = loaderCallback;
final ObjectType irrelevant = null;
final InternalTenantContext notUsed = null;
return new CacheLoaderArgument(irrelevant, args, notUsed);
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class EntitySqlDaoWrapperInvocationHandler method invokeWithCaching.
private Object invokeWithCaching(final Cachable cachableAnnotation, final Method method, final Object[] args) throws Throwable {
final ObjectType objectType = getObjectType();
final CacheType cacheType = cachableAnnotation.value();
final CacheController<Object, Object> cache = cacheControllerDispatcher.getCacheController(cacheType);
Object result = null;
if (cache != null) {
// Find all arguments marked with @CachableKey
final Map<Integer, Object> keyPieces = new LinkedHashMap<Integer, Object>();
final Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < annotations.length; i++) {
for (int j = 0; j < annotations[i].length; j++) {
final Annotation annotation = annotations[i][j];
if (CachableKey.class.equals(annotation.annotationType())) {
// CachableKey position starts at 1
keyPieces.put(((CachableKey) annotation).value() - 1, args[i]);
break;
}
}
}
// Build the Cache key
final String cacheKey = buildCacheKey(keyPieces);
final InternalTenantContext internalTenantContext = (InternalTenantContext) Iterables.find(ImmutableList.copyOf(args), new Predicate<Object>() {
@Override
public boolean apply(final Object input) {
return input instanceof InternalTenantContext;
}
}, null);
final CacheLoaderArgument cacheLoaderArgument = new CacheLoaderArgument(objectType, args, internalTenantContext, handle);
return cache.get(cacheKey, cacheLoaderArgument);
}
if (result == null) {
result = prof.executeWithProfiling(ProfilingFeatureType.DAO_DETAILS, sqlDaoClass.getSimpleName() + "(raw) :" + method.getName(), new WithProfilingCallback() {
@Override
public Object execute() throws Throwable {
return method.invoke(sqlDao, args);
}
});
}
return result;
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class DefaultUsageUserApi method getAllUsageForSubscription.
@Override
public List<RolledUpUsage> getAllUsageForSubscription(final UUID subscriptionId, final List<LocalDate> transitionTimes, final TenantContext tenantContext) {
final InternalTenantContext internalCallContext = internalCallContextFactory.createInternalTenantContext(subscriptionId, ObjectType.SUBSCRIPTION, tenantContext);
List<RolledUpUsage> result = new ArrayList<RolledUpUsage>();
LocalDate prevDate = null;
for (LocalDate curDate : transitionTimes) {
if (prevDate != null) {
final List<RolledUpUsageModelDao> usageForSubscription = rolledUpUsageDao.getAllUsageForSubscription(subscriptionId, prevDate, curDate, internalCallContext);
final List<RolledUpUnit> rolledUpAmount = getRolledUpUnits(usageForSubscription);
result.add(new DefaultRolledUpUsage(subscriptionId, prevDate, curDate, rolledUpAmount));
}
prevDate = curDate;
}
return result;
}
Aggregations