@Override public boolean apply(final Plan input) { return input.getPriceListName().equals(priceListName); } });
@Override public PriceList findPriceListForPlan(final String planName, final DateTime requestedDate, final DateTime subscriptionStartDate) throws CatalogApiException { final CatalogPlanEntry entry = findCatalogPlanEntry(new PlanRequestWrapper(planName), requestedDate, subscriptionStartDate); return entry.getStaticCatalog().findCurrentPricelist(entry.getPlan().getPriceListName()); }
private DefaultPriceList findPriceList(final PlanSpecifier specifier, final StaticCatalog catalog) throws CatalogApiException { DefaultPriceList result = DefaultCasePriceList.getResult(priceListCase, specifier, catalog); if (result == null) { final String priceListName = specifier.getPlanName() != null ? catalog.findCurrentPlan(specifier.getPlanName()).getPriceListName() : specifier.getPriceListName(); result = (DefaultPriceList) catalog.findCurrentPricelist(priceListName); } return result; }
@Override public void addPlan(final Plan plan) throws CatalogApiException { getCatalogEntityCollectionPlan().add(plan); final DefaultPriceList priceList = getPriceLists().findPriceListFrom(plan.getPriceListName()); priceList.getCatalogEntityCollectionPlan().add(plan); }
private Plan toDefaultPlan(final StaticCatalog staticCatalog, final Plan input) { if (tmpDefaultPlans != null) { final Plan existingPlan = tmpDefaultPlans.get(input.getName()); if (existingPlan == null) throw new IllegalStateException("Unknown plan " + input.getName()); return existingPlan; } final DefaultPlan result = new DefaultPlan(); result.setName(input.getName()); result.setPrettyName(input.getPrettyName()); result.setRecurringBillingMode(input.getRecurringBillingMode()); result.setEffectiveDateForExistingSubscriptions(input.getEffectiveDateForExistingSubscriptions()); result.setFinalPhase(toDefaultPlanPhase(input.getFinalPhase())); result.setInitialPhases(toDefaultPlanPhases(ImmutableList.copyOf(input.getInitialPhases()))); result.setPlansAllowedInBundle(input.getPlansAllowedInBundle()); result.setProduct(toDefaultProduct(input.getProduct())); result.setPriceListName(input.getPriceListName()); return result; }
if (phase == null) { throw new SubscriptionBaseError(String.format("No initial PlanPhase for Product %s, term %s and set %s does not exist in the catalog", spec.getProductName(), spec.getBillingPeriod().toString(), plan.getPriceListName())); subscription.setRealPriceList(plan.getPriceListName()); subscription.setEffectiveDate(effectiveDate); subscription.setProcessedDate(context.getCreatedDate());
private void doChangePlan(final DefaultSubscriptionBase subscription, final EntitlementSpecifier spec, final DateTime effectiveDate, final CallContext context) throws SubscriptionBaseApiException, CatalogApiException { final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context); final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(spec.getOverrides(), context); final Catalog fullCatalog = catalogInternalApi.getFullCatalog(true, true, internalCallContext); final PlanPhaseSpecifier planPhaseSpecifier = spec.getPlanPhaseSpecifier(); final Plan newPlan = fullCatalog.createOrFindPlan(planPhaseSpecifier, overridesWithContext, effectiveDate, subscription.getStartDate()); final PhaseType initialPhaseType = planPhaseSpecifier.getPhaseType(); if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(newPlan.getProduct().getCategory().toString())) { if (newPlan.getPlansAllowedInBundle() != -1 && newPlan.getPlansAllowedInBundle() > 0 && addonUtils.countExistingAddOnsWithSamePlanName(dao.getSubscriptions(subscription.getBundleId(), null, fullCatalog, internalCallContext), newPlan.getName()) >= newPlan.getPlansAllowedInBundle()) { // the plan can be changed to the new value, because it has reached its limit by bundle throw new SubscriptionBaseApiException(ErrorCode.SUB_CHANGE_AO_MAX_PLAN_ALLOWED_BY_BUNDLE, newPlan.getName()); } } if (newPlan.getProduct().getCategory() != subscription.getCategory()) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CHANGE_INVALID, subscription.getId()); } final List<DefaultSubscriptionBase> addOnSubscriptionsToBeCancelled = new ArrayList<DefaultSubscriptionBase>(); final List<SubscriptionBaseEvent> addOnCancelEvents = new ArrayList<SubscriptionBaseEvent>(); final List<SubscriptionBaseEvent> changeEvents = getEventsOnChangePlan(subscription, newPlan, newPlan.getPriceListName(), effectiveDate, true, addOnSubscriptionsToBeCancelled, addOnCancelEvents, initialPhaseType, spec.getBillCycleDay(), fullCatalog, internalCallContext); dao.changePlan(subscription, changeEvents, addOnSubscriptionsToBeCancelled, addOnCancelEvents, fullCatalog, internalCallContext); subscription.rebuildTransitions(dao.getEventsForSubscription(subscription.getId(), internalCallContext), fullCatalog); }
final DateTime bundleStartDate = getBundleStartDateWithSanity(bundleId, baseSubscription, plan, startEffectiveDate, addonUtils, context); final UUID subscriptionId = UUIDs.randomUUID(); dryRunEvents = apiService.getEventsOnCreation(subscriptionId, startEffectiveDate, bundleStartDate, plan, inputSpec.getPhaseType(), plan.getPriceListName(), startEffectiveDate, entitlementSpecifier.getBillCycleDay(), catalog, context); final SubscriptionBuilder builder = new SubscriptionBuilder() dryRunEvents = apiService.getEventsOnChangePlan(subscriptionForChange, plan, plan.getPriceListName(), changeEffectiveDate, true, entitlementSpecifier.getBillCycleDay(), catalog, context); break;
assertEquals(plan.getPriceListName(), DefaultPriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(plan.getProduct().getName(), "Dynamic"); assertEquals(plan.getProduct().getCategory(), ProductCategory.BASE);
inFromBillingPeriod = plan.getRecurringBillingPeriod(); inFromProductCategory = plan.getProduct().getCategory(); inFromPriceList = catalog.findCurrentPricelist(plan.getPriceListName()); } else { inFromProduct = catalog.findCurrentProduct(from.getProductName()); inToBillingPeriod = plan.getRecurringBillingPeriod(); inToProductCategory = plan.getProduct().getCategory(); inToPriceList = catalog.findCurrentPricelist(plan.getPriceListName()); } else { inToProduct = catalog.findCurrentProduct(to.getProductName());
protected boolean satisfiesCase(final PlanSpecifier planPhase, final StaticCatalog c) throws CatalogApiException { final Product product; final BillingPeriod billingPeriod; final ProductCategory productCategory; final PriceList priceList; if (planPhase.getPlanName() != null) { final Plan plan = c.findCurrentPlan(planPhase.getPlanName()); product = plan.getProduct(); billingPeriod = plan.getRecurringBillingPeriod(); productCategory = plan.getProduct().getCategory(); priceList = c.findCurrentPricelist(plan.getPriceListName()); } else { product = c.findCurrentProduct(planPhase.getProductName()); billingPeriod = planPhase.getBillingPeriod(); productCategory = product.getCategory(); priceList = getPriceList() != null ? c.findCurrentPricelist(planPhase.getPriceListName()) : null; } return (getProduct() == null || getProduct().equals(product)) && (getProductCategory() == null || getProductCategory().equals(productCategory)) && (getBillingPeriod() == null || getBillingPeriod().equals(billingPeriod)) && (getPriceList() == null || getPriceList().equals(priceList)); }
@Override public boolean apply(final Plan input) { return input.getPriceListName().equals(priceListName); } });
@Override public PriceList findPriceListForPlan(final String planName, final DateTime requestedDate, final DateTime subscriptionStartDate) throws CatalogApiException { final CatalogPlanEntry entry = findCatalogPlanEntry(new PlanRequestWrapper(planName), requestedDate, subscriptionStartDate); return entry.getStaticCatalog().findCurrentPricelist(entry.getPlan().getPriceListName()); }
private DefaultPriceList findPriceList(final PlanSpecifier specifier, final StaticCatalog catalog) throws CatalogApiException { DefaultPriceList result = DefaultCasePriceList.getResult(priceListCase, specifier, catalog); if (result == null) { final String priceListName = specifier.getPlanName() != null ? catalog.findCurrentPlan(specifier.getPlanName()).getPriceListName() : specifier.getPriceListName(); result = (DefaultPriceList) catalog.findCurrentPricelist(priceListName); } return result; }
@Override public void addPlan(final Plan plan) throws CatalogApiException { getCatalogEntityCollectionPlan().add(plan); final DefaultPriceList priceList = getPriceLists().findPriceListFrom(plan.getPriceListName()); priceList.getCatalogEntityCollectionPlan().add(plan); }
private Plan toDefaultPlan(final StaticCatalog staticCatalog, final Plan input) { if (tmpDefaultPlans != null) { final Plan existingPlan = tmpDefaultPlans.get(input.getName()); if (existingPlan == null) throw new IllegalStateException("Unknown plan " + input.getName()); return existingPlan; } final DefaultPlan result = new DefaultPlan(); result.setName(input.getName()); result.setPrettyName(input.getPrettyName()); result.setRecurringBillingMode(input.getRecurringBillingMode()); result.setEffectiveDateForExistingSubscriptions(input.getEffectiveDateForExistingSubscriptions()); result.setFinalPhase(toDefaultPlanPhase(input.getFinalPhase())); result.setInitialPhases(toDefaultPlanPhases(ImmutableList.copyOf(input.getInitialPhases()))); result.setPlansAllowedInBundle(input.getPlansAllowedInBundle()); result.setProduct(toDefaultProduct(input.getProduct())); result.setPriceListName(input.getPriceListName()); return result; }
private void doChangePlan(final DefaultSubscriptionBase subscription, final EntitlementSpecifier spec, final DateTime effectiveDate, final CallContext context) throws SubscriptionBaseApiException, CatalogApiException { final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context); final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(spec.getOverrides(), context); final Catalog fullCatalog = catalogInternalApi.getFullCatalog(true, true, internalCallContext); final PlanPhaseSpecifier planPhaseSpecifier = spec.getPlanPhaseSpecifier(); final Plan newPlan = fullCatalog.createOrFindPlan(planPhaseSpecifier, overridesWithContext, effectiveDate, subscription.getStartDate()); final PhaseType initialPhaseType = planPhaseSpecifier.getPhaseType(); if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(newPlan.getProduct().getCategory().toString())) { if (newPlan.getPlansAllowedInBundle() != -1 && newPlan.getPlansAllowedInBundle() > 0 && addonUtils.countExistingAddOnsWithSamePlanName(dao.getSubscriptions(subscription.getBundleId(), null, fullCatalog, internalCallContext), newPlan.getName()) >= newPlan.getPlansAllowedInBundle()) { // the plan can be changed to the new value, because it has reached its limit by bundle throw new SubscriptionBaseApiException(ErrorCode.SUB_CHANGE_AO_MAX_PLAN_ALLOWED_BY_BUNDLE, newPlan.getName()); } } if (newPlan.getProduct().getCategory() != subscription.getCategory()) { throw new SubscriptionBaseApiException(ErrorCode.SUB_CHANGE_INVALID, subscription.getId()); } final List<DefaultSubscriptionBase> addOnSubscriptionsToBeCancelled = new ArrayList<DefaultSubscriptionBase>(); final List<SubscriptionBaseEvent> addOnCancelEvents = new ArrayList<SubscriptionBaseEvent>(); final List<SubscriptionBaseEvent> changeEvents = getEventsOnChangePlan(subscription, newPlan, newPlan.getPriceListName(), effectiveDate, true, addOnSubscriptionsToBeCancelled, addOnCancelEvents, initialPhaseType, spec.getBillCycleDay(), fullCatalog, internalCallContext); dao.changePlan(subscription, changeEvents, addOnSubscriptionsToBeCancelled, addOnCancelEvents, fullCatalog, internalCallContext); subscription.rebuildTransitions(dao.getEventsForSubscription(subscription.getId(), internalCallContext), fullCatalog); }
assertEquals(plan.getPriceListName(), DefaultPriceListSet.DEFAULT_PRICELIST_NAME); assertEquals(plan.getProduct().getName(), "Dynamic"); assertEquals(plan.getProduct().getCategory(), ProductCategory.BASE);
inFromBillingPeriod = plan.getRecurringBillingPeriod(); inFromProductCategory = plan.getProduct().getCategory(); inFromPriceList = catalog.findCurrentPricelist(plan.getPriceListName()); } else { inFromProduct = catalog.findCurrentProduct(from.getProductName()); inToBillingPeriod = plan.getRecurringBillingPeriod(); inToProductCategory = plan.getProduct().getCategory(); inToPriceList = catalog.findCurrentPricelist(plan.getPriceListName()); } else { inToProduct = catalog.findCurrentProduct(to.getProductName());
protected boolean satisfiesCase(final PlanSpecifier planPhase, final StaticCatalog c) throws CatalogApiException { final Product product; final BillingPeriod billingPeriod; final ProductCategory productCategory; final PriceList priceList; if (planPhase.getPlanName() != null) { final Plan plan = c.findCurrentPlan(planPhase.getPlanName()); product = plan.getProduct(); billingPeriod = plan.getRecurringBillingPeriod(); productCategory = plan.getProduct().getCategory(); priceList = c.findCurrentPricelist(plan.getPriceListName()); } else { product = c.findCurrentProduct(planPhase.getProductName()); billingPeriod = planPhase.getBillingPeriod(); productCategory = product.getCategory(); priceList = getPriceList() != null ? c.findCurrentPricelist(planPhase.getPriceListName()) : null; } return (getProduct() == null || getProduct().equals(product)) && (getProductCategory() == null || getProductCategory().equals(productCategory)) && (getBillingPeriod() == null || getBillingPeriod().equals(billingPeriod)) && (getPriceList() == null || getPriceList().equals(priceList)); }