@Override public UUID getBundleId() { return bundle.getId(); }
private DefaultBlockingAggregator getBlockedStateBundle(final SubscriptionBaseBundle bundle, final InternalTenantContext context) { final DefaultBlockingAggregator result = getBlockedStateAccountId(bundle.getAccountId(), context); final DefaultBlockingAggregator bundleState = getBlockedStateForId(bundle.getId(), BlockingStateType.SUBSCRIPTION_BUNDLE, context); if (bundleState != null) { result.or(bundleState); } return result; }
subscriptionsForBundle, timeline, baseBundle.getOriginalCreatedDate(), baseBundle.getCreatedDate(), baseBundle.getUpdatedDate()); bundles.add(subscriptionBundle);
@Override public List<SubscriptionBaseBundle> getSubscriptionBundlesForAccountAndKey(final UUID accountId, final String bundleKey, final InternalTenantContext context) { final List<SubscriptionBaseBundle> results = new ArrayList<SubscriptionBaseBundle>(); for (final SubscriptionBaseBundle cur : bundles) { if (cur.getExternalKey().equals(bundleKey) && cur.getAccountId().equals(accountId)) { results.add(cur); } } return results; }
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1);
@Test(groups = "slow") public void testCreateBundlesWithSameExternalKeys() throws SubscriptionBaseApiException { final DateTime init = clock.getUTCNow(); final DateTime requestedDate = init.minusYears(1); final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.PHASE); final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(bundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, internalCallContext); assertListenerStatus(); assertNotNull(subscription); testListener.pushExpectedEvent(NextEvent.CANCEL); subscription.cancelWithDate(clock.getUTCNow(), callContext); assertListenerStatus(); final SubscriptionBaseBundle newBundle = subscriptionInternalApi.createBundleForAccount(bundle.getAccountId(), DefaultSubscriptionTestInitializer.DEFAULT_BUNDLE_KEY, internalCallContext); assertNotNull(newBundle); assertEquals(newBundle.getOriginalCreatedDate().compareTo(bundle.getCreatedDate()), 0); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.PHASE); final DefaultSubscriptionBase newSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(newBundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, null), requestedDate, internalCallContext); subscriptionInternalApi.updateExternalKey(newBundle.getId(), "myNewSuperKey", internalCallContext); final SubscriptionBaseBundle bundleWithNewKey = subscriptionInternalApi.getBundleFromId(newBundle.getId(), internalCallContext); assertEquals(bundleWithNewKey.getExternalKey(), "myNewSuperKey"); assertListenerStatus(); assertNotNull(newSubscription); }
@Override public List<SubscriptionBaseBundle> getSubscriptionBundleForAccount(final UUID accountId, final InternalTenantContext context) { final List<SubscriptionBaseBundle> results = new ArrayList<SubscriptionBaseBundle>(); for (final SubscriptionBaseBundle cur : bundles) { if (cur.getAccountId().equals(accountId)) { results.add(cur); } } return results; }
@Override public String getBundleExternalKey() { return bundle.getExternalKey(); }
final DateTime transferRequestedDate = clock.getUTCNow(); testListener.pushExpectedEvent(NextEvent.TRANSFER); transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, true, false, callContext); assertListenerStatus(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1);
final SubscriptionBaseBundle bundle = bundles.get(0); final DateTime bundleCreatedDate = bundle.getCreatedDate(); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(bundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1); final SubscriptionBase subscription = subscriptions.get(0); transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, true, callContext); assertListenerStatus(); final SubscriptionBase oldBaseSubscription = subscriptionInternalApi.getBaseSubscription(bundle.getId(), internalCallContext); assertTrue(oldBaseSubscription.getState() == EntitlementState.CANCELLED);
@Override public List<Entitlement> getAllEntitlementsForBundle(final UUID bundleId, final TenantContext tenantContext) throws EntitlementApiException { final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(tenantContext); final UUID accountId; try { accountId = subscriptionBaseInternalApi.getBundleFromId(bundleId, internalContext).getAccountId(); } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } return ImmutableList.<Entitlement>copyOf(Iterables.<Entitlement>filter(getAllEntitlementsForAccountId(accountId, tenantContext), new Predicate<Entitlement>() { @Override public boolean apply(final Entitlement input) { return bundleId.equals(input.getBundleId()); } })); }
@Override public List<SubscriptionBaseBundle> getSubscriptionBundlesForKey(final String bundleKey, final InternalTenantContext context) { final List<SubscriptionBaseBundle> results = new ArrayList<SubscriptionBaseBundle>(); for (final SubscriptionBaseBundle cur : bundles) { if (cur.getExternalKey().equals(bundleKey)) { results.add(cur); } } return results; }
public DefaultAccountEventsStreams(final Account account, final Iterable<SubscriptionBaseBundle> bundles, final Map<UUID, Collection<EventsStream>> eventsStreams) { this.account = account; this.eventsStreams = eventsStreams; for (final SubscriptionBaseBundle baseBundle : bundles) { this.bundles.put(baseBundle.getId(), baseBundle); } }
testListener.pushExpectedEvent(NextEvent.TRANSFER); testListener.pushExpectedEvent(NextEvent.CANCEL); transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext); assertListenerStatus(); final DateTime afterTransferDate = clock.getUTCNow(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1);
subscriptionBaseInternalApi.getBundleFromId(baseSubscription.getBundleId(), contextWithValidAccountRecordId) : null; if (baseBundle == null || ! baseBundle.getAccountId().equals(sourceAccountId)) { throw new EntitlementApiException(new SubscriptionBaseApiException(ErrorCode.SUB_GET_INVALID_BUNDLE_KEY, externalKey)); for (final SubscriptionBase subscriptionBase : subscriptionBaseInternalApi.getSubscriptionsForBundle(baseBundle.getId(), contextWithValidAccountRecordId)) { final BlockingState blockingState = new DefaultBlockingState(subscriptionBase.getId(), BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_CANCELLED, EntitlementService.ENTITLEMENT_SERVICE_NAME, true, true, false, requestedDate); entitlementUtils.setBlockingStateAndPostBlockingTransitionEvent(blockingState, contextWithValidAccountRecordId); return newBundle.getId(); } catch (SubscriptionBaseTransferApiException e) { throw new EntitlementApiException(e);
public EventsStream buildForEntitlement(final UUID entitlementId, final InternalTenantContext internalTenantContext) throws EntitlementApiException { final SubscriptionBaseBundle bundle; final SubscriptionBase subscription; final List<SubscriptionBase> allSubscriptionsForBundle; final SubscriptionBase baseSubscription; try { subscription = subscriptionInternalApi.getSubscriptionFromId(entitlementId, internalTenantContext); bundle = subscriptionInternalApi.getBundleFromId(subscription.getBundleId(), internalTenantContext); allSubscriptionsForBundle = subscriptionInternalApi.getSubscriptionsForBundle(subscription.getBundleId(), internalTenantContext); baseSubscription = Iterables.<SubscriptionBase>tryFind(allSubscriptionsForBundle, new Predicate<SubscriptionBase>() { @Override public boolean apply(final SubscriptionBase input) { return ProductCategory.BASE.equals(input.getLastActiveProduct().getCategory()); } }).orNull(); // null for standalone subscriptions } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } final Account account; try { account = accountInternalApi.getAccountById(bundle.getAccountId(), internalTenantContext); } catch (AccountApiException e) { throw new EntitlementApiException(e); } // Retrieve the blocking states final List<BlockingState> blockingStatesForAccount = defaultBlockingStateDao.getBlockingAllForAccountRecordId(internalTenantContext); return buildForEntitlement(blockingStatesForAccount, account, bundle, baseSubscription, subscription, allSubscriptionsForBundle, internalTenantContext); }
@Override public SubscriptionBundle apply(final SubscriptionBaseBundle subscriptionBaseBundle) { try { return getSubscriptionBundle(subscriptionBaseBundle.getId(), context); } catch (final SubscriptionApiException e) { log.warn("Error retrieving subscription", e); return null; } } }
transferApi.transferBundle(bundle.getAccountId(), newAccountId, bundle.getExternalKey(), transferRequestedDate, false, false, callContext); assertListenerStatus(); final DateTime afterTransferDate = clock.getUTCNow(); final List<SubscriptionBaseBundle> bundlesForAccountAndKey = subscriptionInternalApi.getBundlesForAccountAndKey(newAccountId, bundle.getExternalKey(), internalCallContext); assertEquals(bundlesForAccountAndKey.size(), 1); final List<SubscriptionBase> subscriptions = subscriptionInternalApi.getSubscriptionsForBundle(newBundle.getId(), internalCallContext); assertEquals(subscriptions.size(), 1);
@Override public List<EntitlementAOStatusDryRun> getDryRunStatusForChange(final UUID bundleId, final String targetProductName, final LocalDate effectiveDate, final TenantContext context) throws EntitlementApiException { final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(context); try { final SubscriptionBaseBundle bundle = subscriptionBaseInternalApi.getBundleFromId(bundleId, internalContext); final SubscriptionBase baseSubscription = subscriptionBaseInternalApi.getBaseSubscription(bundleId, internalContext); final InternalTenantContext contextWithValidAccountRecordId = internalCallContextFactory.createInternalTenantContext(bundle.getAccountId(), context); final DateTime requestedDate = dateHelper.fromLocalDateAndReferenceTime(effectiveDate, baseSubscription.getStartDate(), contextWithValidAccountRecordId); return subscriptionBaseInternalApi.getDryRunChangePlanStatus(baseSubscription.getId(), targetProductName, requestedDate, contextWithValidAccountRecordId); } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } }
@Override public SubscriptionBundle apply(final SubscriptionBaseBundle subscriptionBaseBundle) { try { return getSubscriptionBundle(subscriptionBaseBundle.getId(), context); } catch (final SubscriptionApiException e) { log.warn("Error retrieving subscription", e); return null; } } }