use of org.killbill.billing.usage.api.UsageApiException 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);
}
Aggregations