@Override public List<Listing> getAvailableBasePlanListings() { final List<Listing> availBasePlans = new ArrayList<Listing>(); for (Plan plan : getCurrentPlans()) { if (plan.getProduct().getCategory().equals(ProductCategory.BASE)) { for (PriceList priceList : getPriceLists().getAllPriceLists()) { for (Plan priceListPlan : priceList.getPlans()) { if (priceListPlan.getName().equals(plan.getName()) && priceListPlan.getProduct().getName().equals(plan.getProduct().getName())) { availBasePlans.add(new DefaultListing(priceListPlan, priceList)); } } } } } return availBasePlans; } }
ProductJson productJson = productMap.get(product.getName()); if (productJson == null) { productJson = new ProductJson(product.getCategory().toString(), product.getName(), toProductNames(product.getIncluded()), toProductNames(product.getAvailable())); productMap.put(product.getName(), productJson);
private static ProductCategory getTypeFromSubscription(final Plan plan) { if (plan != null && plan.getProduct() != null) { final Product product = plan.getProduct(); if (product.getCatalogName() != null && product.getCategory() != null) { return product.getCategory(); } } return null; }
private Collection<BlockingState> computeAddonsBlockingStatesForSubscriptionBaseEvent(@Nullable final Product baseTransitionTriggerNextProduct, final DateTime blockingStateEffectiveDate) { if (baseSubscription == null || baseSubscription.getLastActivePlan() == null || !ProductCategory.BASE.equals(baseSubscription.getLastActivePlan().getProduct().getCategory())) { return ImmutableList.<BlockingState>of(); availableAddonsForProduct = ImmutableList.<String>of(); } else { includedAddonsForProduct = Collections2.<Product, String>transform(ImmutableSet.<Product>copyOf(baseTransitionTriggerNextProduct.getIncluded()), new Function<Product, String>() { @Override availableAddonsForProduct = Collections2.<Product, String>transform(ImmutableSet.<Product>copyOf(baseTransitionTriggerNextProduct.getAvailable()), new Function<Product, String>() { @Override
@Override public String apply(final Product product) { return product.getName(); } });
@Test(groups = "fast") public void testConstructor() throws Exception { Assert.assertEquals(subscription.getRoundedMrr(), 0.0); Assert.assertEquals(subscription.getSlug(), phase.getName()); Assert.assertEquals(subscription.getPhase(), phase.getPhaseType().toString()); Assert.assertEquals(subscription.getBillingPeriod(), phase.getBillingPeriod()); Assert.assertEquals(subscription.getPrice(), phase.getRecurringPrice().getPrice(null)); Assert.assertEquals(subscription.getProductCategory(), product.getCategory()); Assert.assertEquals(subscription.getProductName(), product.getName()); Assert.assertEquals(subscription.getProductType(), product.getCatalogName()); Assert.assertEquals(subscription.getStartDate(), isubscription.getStartDate()); }
@Override public boolean apply(final SubscriptionBase input) { return ProductCategory.BASE.equals(input.getLastActiveProduct().getCategory()); } }).orNull();
@Override public List<Listing> getAvailableAddonListings(final String baseProductName) { final List<Listing> availAddons = new ArrayList<Listing>(); try { Product product = findCurrentProduct(baseProductName); if ( product != null ) { for ( Product availAddon : product.getAvailable() ) { for ( BillingPeriod billingPeriod : BillingPeriod.values()) { for( PriceList priceList : getPriceLists().getAllPriceLists()) { Plan addonInList = priceList.findPlan(availAddon, billingPeriod); if ( (addonInList != null) ) { availAddons.add(new DefaultListing(addonInList, priceList)); } } } } } } catch (CatalogApiException e) { // No such product - just return an empty list } return availAddons; }
@Override public String apply(final Product input) { return input.getName(); } });
public BusinessInvoiceItemModelDao(@Nullable final String externalKey, final InvoiceItem invoiceItem, @Nullable final Plan plan, @Nullable final PlanPhase planPhase) { this(invoiceItem.getAmount(), planPhase != null ? planPhase.getBillingPeriod().toString() : null, invoiceItem.getCreatedDate(), invoiceItem.getCurrency(), /* Populate end date for fixed items for convenience (null in invoice_items table) */ (invoiceItem.getEndDate() == null && planPhase != null) ? invoiceItem.getStartDate().plus(planPhase.getDuration().toJodaPeriod()) : invoiceItem.getEndDate(), externalKey, invoiceItem.getInvoiceId(), invoiceItem.getId(), invoiceItem.getLinkedItemId(), invoiceItem.getInvoiceItemType().toString(), planPhase != null ? planPhase.getPhaseType().toString() : null, plan != null ? plan.getProduct().getCategory().toString() : null, plan != null ? plan.getProduct().getName() : null, plan != null ? plan.getProduct().getCatalogName() : null, planPhase != null ? planPhase.getName() : null, invoiceItem.getStartDate(), invoiceItem.getUpdatedDate()); }
@Override public boolean apply(final SubscriptionBase input) { return ProductCategory.BASE.equals(input.getLastActiveProduct().getCategory()); } }).orNull(); // null for standalone subscriptions
private void checkChangePlan(final DefaultSubscriptionBase subscription, final String expProduct, final ProductCategory expCategory, final BillingPeriod expBillingPeriod, final PhaseType expPhase) { final Plan currentPlan = subscription.getCurrentPlan(); assertNotNull(currentPlan); assertEquals(currentPlan.getProduct().getName(), expProduct); assertEquals(currentPlan.getProduct().getCategory(), expCategory); assertEquals(currentPlan.getBillingPeriod(), expBillingPeriod); final PlanPhase currentPhase = subscription.getCurrentPhase(); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), expPhase); }
@Override public String apply(final Product product) { return product.getName(); } });
productName = product.getName(); productCategory = product.getCategory(); productType = product.getCatalogName(); } else { productName = null;
@Override public SubscriptionBase getBaseSubscription(final UUID bundleId, final InternalTenantContext context) { for (final SubscriptionBase cur : subscriptions) { if (cur.getBundleId().equals(bundleId) && cur.getCurrentPlan().getProduct().getCategory() == ProductCategory.BASE) { return buildSubscription((DefaultSubscriptionBase) cur, context); } } return null; }
assertEquals(currentPlan.getProduct().getName(), newBaseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);
@Override public boolean apply(final SubscriptionBase subscription) { return ProductCategory.ADD_ON.equals(subscription.getCategory()) && // Check the entitlement for that add-on hasn't been cancelled yet getEntitlementCancellationEvent(subscription.getId()) == null && ( // Base subscription cancelled baseTransitionTriggerNextProduct == null || ( // Change plan - check which add-ons to cancel includedAddonsForProduct.contains(subscription.getLastActivePlan().getProduct().getName()) || !availableAddonsForProduct.contains(subscription.getLastActivePlan().getProduct().getName()) ) ); } });
productName = product.getName(); productCategory = product.getCategory(); productType = product.getCatalogName(); } else { productName = null;
@Test(groups = "fast") public void testFromSubscription() throws Exception { BusinessSubscriptionEvent event; final DateTime now = new DateTime(); event = BusinessSubscriptionEvent.subscriptionCreated(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.ADD); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "ADD_BASE"); event = BusinessSubscriptionEvent.subscriptionCancelled(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.CANCEL); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "CANCEL_BASE"); event = BusinessSubscriptionEvent.subscriptionChanged(subscription.getCurrentPlan().getName(), catalog, now, now); Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.CHANGE); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "CHANGE_BASE"); event = BusinessSubscriptionEvent.subscriptionPhaseChanged(subscription.getCurrentPlan().getName(), subscription.getState(), catalog, now, now); // The subscription is still active, it's a system change Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.SYSTEM_CHANGE); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "SYSTEM_CHANGE_BASE"); subscription = new MockSubscription(SubscriptionState.CANCELLED, plan, phase); event = BusinessSubscriptionEvent.subscriptionPhaseChanged(subscription.getCurrentPlan().getName(), subscription.getState(), catalog, now, now); // The subscription is cancelled, it's a system cancellation Assert.assertEquals(event.getEventType(), BusinessSubscriptionEvent.EventType.SYSTEM_CANCEL); Assert.assertEquals(event.getCategory(), product.getCategory()); Assert.assertEquals(event.toString(), "SYSTEM_CANCEL_BASE"); }
assertEquals(currentPlan.getProduct().getName(), newBaseProduct); assertEquals(currentPlan.getProduct().getCategory(), ProductCategory.BASE); assertEquals(currentPlan.getBillingPeriod(), BillingPeriod.MONTHLY);