Search in sources :

Example 1 with UnitUsageRecord

use of org.killbill.billing.usage.api.UnitUsageRecord in project killbill by killbill.

the class DefaultUsageUserApi method recordRolledUpUsage.

@Override
public void recordRolledUpUsage(final SubscriptionUsageRecord record, final CallContext callContext) throws UsageApiException {
    final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(record.getSubscriptionId(), ObjectType.SUBSCRIPTION, callContext);
    // check if we have (at least) one row with the supplied tracking id
    if (!Strings.isNullOrEmpty(record.getTrackingId()) && recordsWithTrackingIdExist(record, internalCallContext)) {
        throw new UsageApiException(ErrorCode.USAGE_RECORD_TRACKING_ID_ALREADY_EXISTS, record.getTrackingId());
    }
    final List<RolledUpUsageModelDao> usages = new ArrayList<RolledUpUsageModelDao>();
    for (final UnitUsageRecord unitUsageRecord : record.getUnitUsageRecord()) {
        for (final UsageRecord usageRecord : unitUsageRecord.getDailyAmount()) {
            usages.add(new RolledUpUsageModelDao(record.getSubscriptionId(), unitUsageRecord.getUnitType(), usageRecord.getDate(), usageRecord.getAmount(), record.getTrackingId()));
        }
    }
    rolledUpUsageDao.record(usages, internalCallContext);
}
Also used : UnitUsageRecord(org.killbill.billing.usage.api.UnitUsageRecord) SubscriptionUsageRecord(org.killbill.billing.usage.api.SubscriptionUsageRecord) UnitUsageRecord(org.killbill.billing.usage.api.UnitUsageRecord) UsageRecord(org.killbill.billing.usage.api.UsageRecord) ArrayList(java.util.ArrayList) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) RolledUpUsageModelDao(org.killbill.billing.usage.dao.RolledUpUsageModelDao) UsageApiException(org.killbill.billing.usage.api.UsageApiException)

Example 2 with UnitUsageRecord

use of org.killbill.billing.usage.api.UnitUsageRecord in project killbill by killbill.

the class TestConsumableInArrear method setUsage.

private void setUsage(final UUID subscriptionId, final String unitType, final LocalDate startDate, final Long amount, final CallContext context) throws UsageApiException {
    final List<UsageRecord> usageRecords = new ArrayList<UsageRecord>();
    usageRecords.add(new UsageRecord(startDate, amount));
    final List<UnitUsageRecord> unitUsageRecords = new ArrayList<UnitUsageRecord>();
    unitUsageRecords.add(new UnitUsageRecord(unitType, usageRecords));
    final SubscriptionUsageRecord record = new SubscriptionUsageRecord(subscriptionId, UUID.randomUUID().toString(), unitUsageRecords);
    usageUserApi.recordRolledUpUsage(record, context);
}
Also used : UnitUsageRecord(org.killbill.billing.usage.api.UnitUsageRecord) SubscriptionUsageRecord(org.killbill.billing.usage.api.SubscriptionUsageRecord) UnitUsageRecord(org.killbill.billing.usage.api.UnitUsageRecord) UsageRecord(org.killbill.billing.usage.api.UsageRecord) ArrayList(java.util.ArrayList) SubscriptionUsageRecord(org.killbill.billing.usage.api.SubscriptionUsageRecord)

Example 3 with UnitUsageRecord

use of org.killbill.billing.usage.api.UnitUsageRecord in project killbill by killbill.

the class SubscriptionUsageRecordJson method toSubscriptionUsageRecord.

public SubscriptionUsageRecord toSubscriptionUsageRecord() {
    final List<UnitUsageRecord> tmp = ImmutableList.copyOf(Iterables.transform(unitUsageRecords, new Function<UnitUsageRecordJson, UnitUsageRecord>() {

        @Override
        public UnitUsageRecord apply(final UnitUsageRecordJson input) {
            return input.toUnitUsageRecord();
        }
    }));
    final SubscriptionUsageRecord result = new SubscriptionUsageRecord(UUID.fromString(subscriptionId), trackingId, tmp);
    return result;
}
Also used : Function(com.google.common.base.Function) UnitUsageRecord(org.killbill.billing.usage.api.UnitUsageRecord) SubscriptionUsageRecord(org.killbill.billing.usage.api.SubscriptionUsageRecord)

Aggregations

SubscriptionUsageRecord (org.killbill.billing.usage.api.SubscriptionUsageRecord)3 UnitUsageRecord (org.killbill.billing.usage.api.UnitUsageRecord)3 ArrayList (java.util.ArrayList)2 UsageRecord (org.killbill.billing.usage.api.UsageRecord)2 Function (com.google.common.base.Function)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 UsageApiException (org.killbill.billing.usage.api.UsageApiException)1 RolledUpUsageModelDao (org.killbill.billing.usage.dao.RolledUpUsageModelDao)1