@Override public UUID getBundleId() { return bundle.getId(); }
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); } }
@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; } } }
@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; } } }
@Override public SubscriptionBaseBundle getSubscriptionBundleFromId(final UUID bundleId, final InternalTenantContext context) { for (final SubscriptionBaseBundle cur : bundles) { if (cur.getId().equals(bundleId)) { return cur; } } return null; }
@Override public List<SubscriptionBundle> getSubscriptionBundlesForExternalKey(final String externalKey, final TenantContext context) throws SubscriptionApiException { final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(context); final List<SubscriptionBaseBundle> baseBundles = subscriptionBaseInternalApi.getBundlesForKey(externalKey, internalContext); final List<SubscriptionBundle> result = new ArrayList<SubscriptionBundle>(baseBundles.size()); for (final SubscriptionBaseBundle cur : baseBundles) { final SubscriptionBundle bundle = getSubscriptionBundle(cur.getId(), context); result.add(bundle); } return result; }
private void addBillingEventsForBundles(final List<SubscriptionBaseBundle> bundles, final Account account, final InternalCallContext context, final DefaultBillingEventSet result) { for (final SubscriptionBaseBundle bundle : bundles) { final List<SubscriptionBase> subscriptions = subscriptionApi.getSubscriptionsForBundle(bundle.getId(), context); //Check if billing is off for the bundle final List<Tag> bundleTags = tagApi.getTags(bundle.getId(), ObjectType.BUNDLE, context); boolean found_AUTO_INVOICING_OFF = is_AUTO_INVOICING_OFF(bundleTags); if (found_AUTO_INVOICING_OFF) { for (final SubscriptionBase subscription : subscriptions) { // billing is off so list sub ids in set to be excluded result.getSubscriptionIdsWithAutoInvoiceOff().add(subscription.getId()); } } else { // billing is not off addBillingEventsForSubscription(subscriptions, bundle, account, context, result); } } }
@Test(groups = "fast") public void testCreateSubscriptionNoBP() { tCreateSubscriptionInternal(bundle.getId(), "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.SUB_CREATE_NO_BP); }
public DefaultSubscriptionBase createSubscription(final SubscriptionBaseBundle bundle, final String productName, final BillingPeriod term, final String planSet, final DateTime requestedDate) throws SubscriptionBaseApiException { return createSubscriptionWithBundle(bundle.getId(), productName, term, planSet, requestedDate); }
@Test(groups = "fast") public void testCreateSubscriptionBadCatalog() { // WRONG PRODUCTS tCreateSubscriptionInternal(bundle.getId(), null, BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.CAT_NULL_PRODUCT_NAME); tCreateSubscriptionInternal(bundle.getId(), "Whatever", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.CAT_NO_SUCH_PRODUCT); // TODO: MARTIN TO FIX WITH CORRECT ERROR CODE. RIGHT NOW NPE // WRONG BILLING PERIOD tCreateSubscriptionInternal(bundle.getId(), "Shotgun", null, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.CAT_PLAN_NOT_FOUND); // WRONG PLAN SET tCreateSubscriptionInternal(bundle.getId(), "Shotgun", BillingPeriod.ANNUAL, "Whatever", ErrorCode.CAT_PRICE_LIST_NOT_FOUND); }
public DefaultSubscriptionBase createSubscription(final SubscriptionBaseBundle bundle, final String productName, final BillingPeriod term, final String planSet) throws SubscriptionBaseApiException { return createSubscriptionWithBundle(bundle.getId(), productName, term, planSet, null); }
@Test(groups = "fast") public void testCreateSubscriptionAddOnNotAvailable() throws SubscriptionBaseApiException { final UUID accountId = UUID.randomUUID(); final SubscriptionBaseBundle aoBundle = subscriptionInternalApi.createBundleForAccount(accountId, "myAOBundle", internalCallContext); testUtil.createSubscriptionWithBundle(aoBundle.getId(), "Pistol", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); tCreateSubscriptionInternal(aoBundle.getId(), "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.SUB_CREATE_AO_NOT_AVAILABLE); }
@Test(groups = "fast") public void testCreateSubscriptionAddOnIncluded() throws SubscriptionBaseApiException { final UUID accountId = UUID.randomUUID(); final SubscriptionBaseBundle aoBundle = subscriptionInternalApi.createBundleForAccount(accountId, "myAOBundle", internalCallContext); testUtil.createSubscriptionWithBundle(aoBundle.getId(), "Assault-Rifle", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, null); tCreateSubscriptionInternal(aoBundle.getId(), "Telescopic-Scope", BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.SUB_CREATE_AO_ALREADY_INCLUDED); }
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; }
@Test(groups = "fast") public void testCreateSubscriptionBPExists() throws SubscriptionBaseApiException { testUtil.createSubscription(bundle, "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME); tCreateSubscriptionInternal(bundle.getId(), "Shotgun", BillingPeriod.ANNUAL, PriceListSet.DEFAULT_PRICELIST_NAME, ErrorCode.SUB_CREATE_BP_EXISTS); }
@Override public boolean apply(final BlockingState input) { return !input.getEffectiveDate().isBefore(utcNow) && typeList.contains(input.getStateName()) && ( // ... for that subscription BlockingStateType.SUBSCRIPTION.equals(input.getType()) && input.getBlockedId().equals(subscription.getId()) || // ... for the associated base subscription BlockingStateType.SUBSCRIPTION.equals(input.getType()) && input.getBlockedId().equals(baseSubscription.getId()) || // ... for that bundle BlockingStateType.SUBSCRIPTION_BUNDLE.equals(input.getType()) && input.getBlockedId().equals(bundle.getId()) || // ... for that account BlockingStateType.ACCOUNT.equals(input.getType()) && input.getBlockedId().equals(account.getId()) ); } });
@Test(groups = "slow") public void testSubscriptionWithAddOn() throws SubscriptionBaseApiException { final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.ANNUAL; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; testListener.pushExpectedEvent(NextEvent.CREATE); final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) subscriptionInternalApi.createSubscription(bundle.getId(), testUtil.getProductSpecifier(productName, planSetName, term, null), clock.getUTCNow(), internalCallContext); assertNotNull(subscription); assertListenerStatus(); } }
@Override public void doTest() throws SubscriptionBaseRepairException { final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final DeletedEvent de = testUtil.createDeletedEvent(UUID.randomUUID()); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.singletonList(de), Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_NON_EXISTENT_DELETE_EVENT);
@Override public void doTest() throws SubscriptionBaseRepairException { // MOVE AFTER TRIAL testListener.pushExpectedEvent(NextEvent.PHASE); final Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(40)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); final BundleBaseTimeline bundleRepair = repairApi.getBundleTimeline(bundle.getId(), callContext); testUtil.sortEventsOnBundle(bundleRepair); final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Assault-Rifle", ProductCategory.BASE, BillingPeriod.MONTHLY, PriceListSet.DEFAULT_PRICELIST_NAME, PhaseType.EVERGREEN); final NewEvent ne = testUtil.createNewEvent(SubscriptionBaseTransitionType.CHANGE, baseSubscription.getStartDate().plusDays(10), spec); final SubscriptionBaseTimeline sRepair = testUtil.createSubscriptionRepair(baseSubscription.getId(), Collections.<DeletedEvent>emptyList(), Collections.singletonList(ne)); final BundleBaseTimeline bRepair = testUtil.createBundleRepair(bundle.getId(), bundleRepair.getViewId(), Collections.singletonList(sRepair)); repairApi.repairBundle(bRepair, true, callContext); } }, ErrorCode.SUB_REPAIR_NEW_EVENT_BEFORE_LAST_BP_REMAINING);
@Override public Entitlement createBaseEntitlement(final UUID accountId, final PlanPhaseSpecifier planPhaseSpecifier, final String externalKey, final LocalDate effectiveDate, final CallContext callContext) throws EntitlementApiException { final InternalCallContext contextWithValidAccountRecordId = internalCallContextFactory.createInternalCallContext(accountId, callContext); try { if (entitlementUtils.getFirstActiveSubscriptionIdForKeyOrNull(externalKey, contextWithValidAccountRecordId) != null) { throw new EntitlementApiException(new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_ACTIVE_BUNDLE_KEY_EXISTS, externalKey)); } final SubscriptionBaseBundle bundle = subscriptionBaseInternalApi.createBundleForAccount(accountId, externalKey, contextWithValidAccountRecordId); final DateTime referenceTime = clock.getUTCNow(); final DateTime requestedDate = dateHelper.fromLocalDateAndReferenceTime(effectiveDate, referenceTime, contextWithValidAccountRecordId); final SubscriptionBase subscription = subscriptionBaseInternalApi.createSubscription(bundle.getId(), planPhaseSpecifier, requestedDate, contextWithValidAccountRecordId); return new DefaultEntitlement(subscription.getId(), eventsStreamBuilder, this, blockingStateDao, subscriptionBaseInternalApi, checker, notificationQueueService, entitlementUtils, dateHelper, clock, internalCallContextFactory, callContext); } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } }