Search in sources :

Example 1 with SubscriptionTransferData

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);
}
Also used : SubscriptionNotificationKey(org.killbill.billing.subscription.engine.core.SubscriptionNotificationKey) SubscriptionModelDao(org.killbill.billing.subscription.engine.dao.model.SubscriptionModelDao) DefaultSubscriptionBaseBundle(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle) SubscriptionBundleModelDao(org.killbill.billing.subscription.engine.dao.model.SubscriptionBundleModelDao) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) SubscriptionTransferData(org.killbill.billing.subscription.api.transfer.SubscriptionTransferData) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) SubscriptionEventModelDao(org.killbill.billing.subscription.engine.dao.model.SubscriptionEventModelDao)

Aggregations

SubscriptionTransferData (org.killbill.billing.subscription.api.transfer.SubscriptionTransferData)1 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)1 DefaultSubscriptionBaseBundle (org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseBundle)1 SubscriptionNotificationKey (org.killbill.billing.subscription.engine.core.SubscriptionNotificationKey)1 SubscriptionBundleModelDao (org.killbill.billing.subscription.engine.dao.model.SubscriptionBundleModelDao)1 SubscriptionEventModelDao (org.killbill.billing.subscription.engine.dao.model.SubscriptionEventModelDao)1 SubscriptionModelDao (org.killbill.billing.subscription.engine.dao.model.SubscriptionModelDao)1 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)1