use of org.killbill.billing.subscription.api.transfer.SubscriptionTransferData in project killbill by killbill.
the class DefaultSubscriptionDao method transferBundleDataFromTransaction.
private void transferBundleDataFromTransaction(final BundleTransferData bundleTransferData, final EntitySqlDao transactional, final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InternalCallContext context) throws EntityPersistenceException {
final SubscriptionSqlDao transSubDao = entitySqlDaoWrapperFactory.become(SubscriptionSqlDao.class);
final BundleSqlDao transBundleDao = entitySqlDaoWrapperFactory.become(BundleSqlDao.class);
final DefaultSubscriptionBaseBundle bundleData = bundleTransferData.getData();
final List<SubscriptionBundleModelDao> existingBundleModels = transBundleDao.getBundlesFromAccountAndKey(bundleData.getAccountId().toString(), bundleData.getExternalKey(), context);
if (!existingBundleModels.isEmpty()) {
log.warn("Bundle already exists for accountId='{}', bundleExternalKey='{}'", bundleData.getAccountId(), bundleData.getExternalKey());
return;
}
for (final SubscriptionTransferData curSubscription : bundleTransferData.getSubscriptions()) {
final DefaultSubscriptionBase subData = curSubscription.getData();
for (final SubscriptionBaseEvent curEvent : curSubscription.getInitialEvents()) {
transactional.create(new SubscriptionEventModelDao(curEvent), context);
recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory, curEvent.getEffectiveDate(), new SubscriptionNotificationKey(curEvent.getId()), context);
}
transSubDao.create(new SubscriptionModelDao(subData), context);
// Notify the Bus of the latest requested change
final SubscriptionBaseEvent finalEvent = curSubscription.getInitialEvents().get(curSubscription.getInitialEvents().size() - 1);
notifyBusOfRequestedChange(entitySqlDaoWrapperFactory, subData, finalEvent, SubscriptionBaseTransitionType.TRANSFER, context);
}
transBundleDao.create(new SubscriptionBundleModelDao(bundleData), context);
}
Aggregations