@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()); } })); }
private DefaultBlockingAggregator getBlockedStateBundleId(final UUID bundleId, final InternalTenantContext context) throws BlockingApiException { final SubscriptionBaseBundle bundle; try { bundle = subscriptionApi.getBundleFromId(bundleId, context); return getBlockedStateBundle(bundle, context); } catch (SubscriptionBaseApiException e) { throw new BlockingApiException(e, ErrorCode.fromCode(e.getCode())); } }
@BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); final SubscriptionBaseBundle bundle = Mockito.mock(SubscriptionBaseBundle.class); Mockito.when(bundle.getId()).thenReturn(bunId); final List<SubscriptionBaseBundle> bundles = ImmutableList.<SubscriptionBaseBundle>of(bundle); effectiveSubscriptionTransitions = new LinkedList<EffectiveSubscriptionInternalEvent>(); final DateTime subscriptionStartDate = clock.getUTCNow().minusDays(3); subscription = new MockSubscription(subId, bunId, null, subscriptionStartDate, effectiveSubscriptionTransitions); final List<SubscriptionBase> subscriptions = ImmutableList.<SubscriptionBase>of(subscription); Mockito.when(subscriptionInternalApi.getBundlesForAccount(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(bundles); Mockito.when(subscriptionInternalApi.getSubscriptionsForBundle(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(subscriptions); Mockito.when(subscriptionInternalApi.getSubscriptionFromId(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(subscription); Mockito.when(subscriptionInternalApi.getBundleFromId(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(bundle); Mockito.when(subscriptionInternalApi.getBaseSubscription(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(subscription); Mockito.when(subscriptionInternalApi.getBillingTransitions(Mockito.<SubscriptionBase>any(), Mockito.<InternalTenantContext>any())).thenReturn(effectiveSubscriptionTransitions); Mockito.when(subscriptionInternalApi.getAllTransitions(Mockito.<SubscriptionBase>any(), Mockito.<InternalTenantContext>any())).thenReturn(effectiveSubscriptionTransitions); catalog = ((MockCatalog) catalogService.getCurrentCatalog()); // TODO The MockCatalog module returns two different things for full vs current catalog Mockito.when(catalogService.getFullCatalog()).thenReturn(catalog); // Set a default alignment catalog.setBillingAlignment(BillingAlignment.ACCOUNT); // Cleanup mock daos ((MockBlockingStateDao) blockingStateDao).clear(); ((MockTagDao) tagDao).clear(); }
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 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); } }
subscriptionBaseInternalApi.getSubscriptionFromId(activeSubscriptionIdForKey, contextWithValidAccountRecordId) : null; final SubscriptionBaseBundle baseBundle = baseSubscription != null ? subscriptionBaseInternalApi.getBundleFromId(baseSubscription.getBundleId(), contextWithValidAccountRecordId) : null;
try { final InternalCallContext contextWithValidAccountRecordId = internalCallContextFactory.createInternalCallContext(bundleId, ObjectType.BUNDLE, context); final SubscriptionBaseBundle bundle = subscriptionBaseInternalApi.getBundleFromId(bundleId, contextWithValidAccountRecordId); final Account account = accountApi.getAccountById(bundle.getAccountId(), contextWithValidAccountRecordId); final SubscriptionBase baseSubscription = subscriptionBaseInternalApi.getBaseSubscription(bundleId, contextWithValidAccountRecordId);
final SubscriptionBaseBundle bundle = subscriptionBaseInternalApi.getBundleFromId(bundleId, contextWithValidAccountRecordId); final Account account = accountApi.getAccountById(bundle.getAccountId(), contextWithValidAccountRecordId); final SubscriptionBase baseSubscription = subscriptionBaseInternalApi.getBaseSubscription(bundleId, contextWithValidAccountRecordId);
@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); }