use of org.killbill.billing.subscription.engine.dao.model.SubscriptionBundleModelDao in project killbill by killbill.
the class MockSubscriptionDaoMemory method searchSubscriptionBundles.
@Override
public Pagination<SubscriptionBundleModelDao> searchSubscriptionBundles(final String searchKey, final Long offset, final Long limit, final InternalTenantContext context) {
final List<SubscriptionBundleModelDao> results = new LinkedList<SubscriptionBundleModelDao>();
int maxNbRecords = 0;
for (final SubscriptionBundleModelDao bundleModelDao : getAll(context)) {
maxNbRecords++;
if (bundleModelDao.getId().toString().equals(searchKey) || bundleModelDao.getExternalKey().equals(searchKey) || bundleModelDao.getAccountId().toString().equals(searchKey)) {
results.add(bundleModelDao);
}
}
return DefaultPagination.<SubscriptionBundleModelDao>build(offset, limit, maxNbRecords, results);
}
use of org.killbill.billing.subscription.engine.dao.model.SubscriptionBundleModelDao in project killbill by killbill.
the class TestSubscriptionDao method testWithAuditAndHistory.
@Test(groups = "slow")
public void testWithAuditAndHistory() throws SubscriptionBaseApiException {
final String bundleExternalKey = "54341455sttfs1";
final DateTime startDate = clock.getUTCNow();
final DefaultSubscriptionBaseBundle bundleDef = new DefaultSubscriptionBaseBundle(bundleExternalKey, accountId, startDate, startDate, startDate, startDate);
final SubscriptionBaseBundle bundle = dao.createSubscriptionBundle(bundleDef, catalog, true, internalCallContext);
final List<AuditLogWithHistory> bundleHistory1 = dao.getSubscriptionBundleAuditLogsWithHistoryForId(bundle.getId(), AuditLevel.FULL, internalCallContext);
assertEquals(bundleHistory1.size(), 1);
final AuditLogWithHistory bundleHistoryRow1 = bundleHistory1.get(0);
assertEquals(bundleHistoryRow1.getChangeType(), ChangeType.INSERT);
final SubscriptionBundleModelDao historyRow1 = (SubscriptionBundleModelDao) bundleHistoryRow1.getEntity();
assertEquals(historyRow1.getExternalKey(), bundle.getExternalKey());
assertEquals(historyRow1.getAccountId(), bundle.getAccountId());
dao.updateBundleExternalKey(bundle.getId(), "you changed me!", internalCallContext);
final List<AuditLogWithHistory> bundleHistory2 = dao.getSubscriptionBundleAuditLogsWithHistoryForId(bundle.getId(), AuditLevel.FULL, internalCallContext);
assertEquals(bundleHistory2.size(), 2);
final AuditLogWithHistory bundleHistoryRow2 = bundleHistory2.get(1);
assertEquals(bundleHistoryRow2.getChangeType(), ChangeType.UPDATE);
final SubscriptionBundleModelDao historyRow2 = (SubscriptionBundleModelDao) bundleHistoryRow2.getEntity();
assertEquals(historyRow2.getExternalKey(), "you changed me!");
assertEquals(historyRow2.getAccountId(), bundle.getAccountId());
final SubscriptionBuilder builder = new SubscriptionBuilder().setId(UUIDs.randomUUID()).setBundleId(bundle.getId()).setBundleExternalKey(bundle.getExternalKey()).setCategory(ProductCategory.BASE).setBundleStartDate(startDate).setAlignStartDate(startDate).setMigrated(false);
final ApiEventBuilder createBuilder = new ApiEventBuilder().setSubscriptionId(builder.getId()).setEventPlan("shotgun-monthly").setEventPlanPhase("shotgun-monthly-trial").setEventPriceList(DefaultPriceListSet.DEFAULT_PRICELIST_NAME).setEffectiveDate(startDate).setFromDisk(true);
final SubscriptionBaseEvent creationEvent = new ApiEventCreate(createBuilder);
final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(builder);
testListener.pushExpectedEvents(NextEvent.CREATE);
final SubscriptionBaseWithAddOns subscriptionBaseWithAddOns = new DefaultSubscriptionBaseWithAddOns(bundle, ImmutableList.<SubscriptionBase>of(subscription));
final List<SubscriptionBaseEvent> resultSubscriptions = dao.createSubscriptionsWithAddOns(ImmutableList.<SubscriptionBaseWithAddOns>of(subscriptionBaseWithAddOns), ImmutableMap.<UUID, List<SubscriptionBaseEvent>>of(subscription.getId(), ImmutableList.<SubscriptionBaseEvent>of(creationEvent)), catalog, internalCallContext);
assertListenerStatus();
assertEquals(resultSubscriptions.size(), 1);
final SubscriptionBaseEvent subscriptionBaseEvent = resultSubscriptions.get(0);
final List<AuditLogWithHistory> subscriptionHistory = dao.getSubscriptionAuditLogsWithHistoryForId(subscriptionBaseEvent.getSubscriptionId(), AuditLevel.FULL, internalCallContext);
assertEquals(subscriptionHistory.size(), 1);
final AuditLogWithHistory subscriptionHistoryRow1 = subscriptionHistory.get(0);
assertEquals(subscriptionHistoryRow1.getChangeType(), ChangeType.INSERT);
final SubscriptionModelDao subHistoryRow1 = (SubscriptionModelDao) subscriptionHistoryRow1.getEntity();
assertEquals(subHistoryRow1.getBundleId(), bundle.getId());
assertEquals(subHistoryRow1.getCategory(), ProductCategory.BASE);
final List<AuditLogWithHistory> subscriptionEventHistory = dao.getSubscriptionEventAuditLogsWithHistoryForId(subscriptionBaseEvent.getId(), AuditLevel.FULL, internalCallContext);
final AuditLogWithHistory subscriptionEventHistoryRow1 = subscriptionEventHistory.get(0);
assertEquals(subscriptionEventHistoryRow1.getChangeType(), ChangeType.INSERT);
final SubscriptionEventModelDao subEventHistoryRow1 = (SubscriptionEventModelDao) subscriptionEventHistoryRow1.getEntity();
assertEquals(subEventHistoryRow1.getSubscriptionId(), subscriptionBaseEvent.getSubscriptionId());
assertEquals(subEventHistoryRow1.getEventType(), EventType.API_USER);
assertEquals(subEventHistoryRow1.getUserType(), ApiEventType.CREATE);
assertEquals(subEventHistoryRow1.getPlanName(), "shotgun-monthly");
assertEquals(subEventHistoryRow1.getIsActive(), true);
}
use of org.killbill.billing.subscription.engine.dao.model.SubscriptionBundleModelDao in project killbill by killbill.
the class TestSubscriptionModelDao method testBundleExternalKeyPattern3.
@Test(groups = "fast")
public void testBundleExternalKeyPattern3() throws Exception {
final SubscriptionBundleModelDao b = new SubscriptionBundleModelDao();
b.setExternalKey("kbXXXX-343453:1235");
assertEquals(SubscriptionBundleModelDao.toSubscriptionBundle(b).getExternalKey(), "1235");
}
use of org.killbill.billing.subscription.engine.dao.model.SubscriptionBundleModelDao 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 SubscriptionBundleModelDao existingBundleForAccount = transBundleDao.getBundlesFromAccountAndKey(bundleData.getAccountId().toString(), bundleData.getExternalKey(), context);
if (existingBundleForAccount != null) {
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()) {
createAndRefresh(transactional, new SubscriptionEventModelDao(curEvent), context);
recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory, curEvent.getEffectiveDate(), new SubscriptionNotificationKey(curEvent.getId()), context);
}
createAndRefresh(transSubDao, 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, 0, context);
}
createAndRefresh(transBundleDao, new SubscriptionBundleModelDao(bundleData), context);
}
use of org.killbill.billing.subscription.engine.dao.model.SubscriptionBundleModelDao in project killbill by killbill.
the class DefaultSubscriptionDao method getSubscriptionsFromAccountId.
private Map<UUID, List<SubscriptionBase>> getSubscriptionsFromAccountId(final InternalTenantContext context) {
final List<SubscriptionBase> allSubscriptions = transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<List<SubscriptionBase>>() {
@Override
public List<SubscriptionBase> inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception {
final List<SubscriptionBundleModelDao> bundleModels = entitySqlDaoWrapperFactory.become(BundleSqlDao.class).getByAccountRecordId(context);
final List<SubscriptionModelDao> subscriptionModels = entitySqlDaoWrapperFactory.become(SubscriptionSqlDao.class).getByAccountRecordId(context);
return new ArrayList<SubscriptionBase>(Collections2.transform(subscriptionModels, new Function<SubscriptionModelDao, SubscriptionBase>() {
@Override
public SubscriptionBase apply(final SubscriptionModelDao input) {
final SubscriptionBundleModelDao bundleModel = Iterables.find(bundleModels, new Predicate<SubscriptionBundleModelDao>() {
@Override
public boolean apply(final SubscriptionBundleModelDao bundleInput) {
return bundleInput.getId().equals(input.getBundleId());
}
});
return SubscriptionModelDao.toSubscription(input, bundleModel.getExternalKey());
}
}));
}
});
final Map<UUID, List<SubscriptionBase>> result = new HashMap<UUID, List<SubscriptionBase>>();
for (final SubscriptionBase subscriptionBase : allSubscriptions) {
if (result.get(subscriptionBase.getBundleId()) == null) {
result.put(subscriptionBase.getBundleId(), new LinkedList<SubscriptionBase>());
}
result.get(subscriptionBase.getBundleId()).add(subscriptionBase);
}
return result;
}
Aggregations