Search in sources :

Example 1 with DryRunTenantContext

use of org.killbill.billing.usage.DryRunTenantContext in project killbill by killbill.

the class DefaultInternalUserApi method getRawUsageForAccount.

@Override
public List<RawUsageRecord> getRawUsageForAccount(final LocalDate startDate, final LocalDate endDate, @Nullable final DryRunInfo dryRunInfo, final InternalTenantContext internalTenantContext) {
    log.info("GetRawUsageForAccount startDate='{}', endDate='{}'", startDate, endDate);
    final TenantContext tenantContext = internalCallContextFactory.createTenantContext(internalTenantContext);
    final TenantContext tenantContextWithHint = dryRunInfo != null ? new DryRunTenantContext(dryRunInfo, tenantContext) : tenantContext;
    final List<RawUsageRecord> resultFromPlugin = getAccountUsageFromPlugin(startDate, endDate, tenantContextWithHint);
    if (resultFromPlugin != null) {
        return resultFromPlugin;
    }
    final List<RolledUpUsageModelDao> usage = rolledUpUsageDao.getRawUsageForAccount(startDate, endDate, internalTenantContext);
    return ImmutableList.copyOf(Iterables.transform(usage, new Function<RolledUpUsageModelDao, RawUsageRecord>() {

        @Override
        public RawUsageRecord apply(final RolledUpUsageModelDao input) {
            return new DefaultRawUsage(input.getSubscriptionId(), input.getRecordDate(), input.getUnitType(), input.getAmount(), input.getTrackingId());
        }
    }));
}
Also used : Function(com.google.common.base.Function) RawUsageRecord(org.killbill.billing.usage.api.RawUsageRecord) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) DryRunTenantContext(org.killbill.billing.usage.DryRunTenantContext) TenantContext(org.killbill.billing.util.callcontext.TenantContext) DryRunTenantContext(org.killbill.billing.usage.DryRunTenantContext) RolledUpUsageModelDao(org.killbill.billing.usage.dao.RolledUpUsageModelDao)

Aggregations

Function (com.google.common.base.Function)1 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)1 DryRunTenantContext (org.killbill.billing.usage.DryRunTenantContext)1 RawUsageRecord (org.killbill.billing.usage.api.RawUsageRecord)1 RolledUpUsageModelDao (org.killbill.billing.usage.dao.RolledUpUsageModelDao)1 TenantContext (org.killbill.billing.util.callcontext.TenantContext)1