@Override public boolean apply(final Entitlement entitlement) { // Note: this would miss add-ons created in the future. We should expose a new API to do something similar to EventsStreamBuilder#findBaseSubscription return !ProductCategory.ADD_ON.equals(entitlement.getLastActiveProductCategory()); } });
@Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (category != null ? category.hashCode() : 0); result = 31 * result + (included != null ? included.hashCode() : 0); result = 31 * result + (available != null ? available.hashCode() : 0); result = 31 * result + Arrays.hashCode(limits); result = 31 * result + (catalogName != null ? catalogName.hashCode() : 0); return result; }
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeObject(product); out.writeBoolean(productCategory != null); if (productCategory != null) { out.writeUTF(productCategory.name()); } out.writeBoolean(billingPeriod != null); if (billingPeriod != null) { out.writeUTF(billingPeriod.name()); } out.writeObject(priceList); }
plan.getProduct().getCategory().toString()));
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { this.catalogName = in.readBoolean() ? in.readUTF() : null; this.name = in.readBoolean() ? in.readUTF() : null; this.prettyName = in.readBoolean() ? in.readUTF() : null; this.category = in.readBoolean() ? ProductCategory.valueOf(in.readUTF()) : null; this.included = (CatalogEntityCollection<Product>) in.readObject(); this.available = (CatalogEntityCollection<Product>) in.readObject(); this.limits = (DefaultLimit[]) in.readObject(); } }
@Override public DateTime getDryRunChangePlanEffectiveDate(final SubscriptionBase subscription, final EntitlementSpecifier spec, final DateTime requestedDateWithMs, final BillingActionPolicy requestedPolicy, final InternalCallContext context) throws SubscriptionBaseApiException, CatalogApiException { final TenantContext tenantContext = internalCallContextFactory.createTenantContext(context); final CallContext callContext = internalCallContextFactory.createCallContext(context); // verify the number of subscriptions (of the same kind) allowed per bundle final Catalog catalog = catalogInternalApi.getFullCatalog(true, true, context); final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : null; final DateTime effectiveCatalogDate = effectiveDate != null ? effectiveDate : context.getCreatedDate(); final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(spec.getOverrides(), callContext); final Plan plan = catalog.createOrFindPlan(spec.getPlanPhaseSpecifier(), overridesWithContext, effectiveCatalogDate, subscription.getStartDate()); if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(plan.getProduct().getCategory().toString())) { if (plan.getPlansAllowedInBundle() != -1 && plan.getPlansAllowedInBundle() > 0 && addonUtils.countExistingAddOnsWithSamePlanName(getSubscriptionsForBundle(subscription.getBundleId(), null, catalog, addonUtils, callContext, context), plan.getName()) >= plan.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, plan.getName()); } } return apiService.dryRunChangePlan((DefaultSubscriptionBase) subscription, spec, effectiveDate, requestedPolicy, tenantContext); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { this.product = (DefaultProduct) in.readObject(); this.productCategory = in.readBoolean() ? ProductCategory.valueOf(in.readUTF()) : null; this.billingPeriod = in.readBoolean() ? BillingPeriod.valueOf(in.readUTF()) : null; this.priceList = (DefaultPriceList) in.readObject(); } }
private int countCurrentAddOnsWithSamePlanName(final Iterable<Plan> entitlementsPlans, final Plan currentPlan) { int countCurrentAddOns = 0; for (final Plan plan : entitlementsPlans) { if (plan.getName().equalsIgnoreCase(currentPlan.getName()) && plan.getProduct().getCategory() != null && ProductCategory.ADD_ON.equals(plan.getProduct().getCategory())) { countCurrentAddOns++; } } return countCurrentAddOns; } }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (bundleId != null ? bundleId.hashCode() : 0); result = 31 * result + (category != null ? category.hashCode() : 0); result = 31 * result + (startDate != null ? startDate.hashCode() : 0); result = 31 * result + (bundleStartDate != null ? bundleStartDate.hashCode() : 0); result = 31 * result + (chargedThroughDate != null ? chargedThroughDate.hashCode() : 0); result = 31 * result + Boolean.valueOf(migrated).hashCode(); 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); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); this.fromProduct = (DefaultProduct) in.readObject(); this.fromProductCategory = in.readBoolean() ? ProductCategory.valueOf(in.readUTF()) : null; this.fromBillingPeriod = in.readBoolean() ? BillingPeriod.valueOf(in.readUTF()) : null; this.fromPriceList = (DefaultPriceList) in.readObject(); this.toPriceList = (DefaultPriceList) in.readObject(); } }
@Override public void writeExternal(final ObjectOutput out) throws IOException { out.writeBoolean(catalogName != null); if (catalogName != null) { out.writeUTF(catalogName); } out.writeBoolean(name != null); if (name != null) { out.writeUTF(name); } out.writeBoolean(prettyName != null); if (prettyName != null) { out.writeUTF(prettyName); } out.writeBoolean(category != null); if (category != null) { out.writeUTF(category.name()); } out.writeObject(included); out.writeObject(available); out.writeObject(limits); }
public int countExistingAddOnsWithSamePlanName(final Iterable<DefaultSubscriptionBase> subscriptionsForBundle, final String planName) { int countExistingAddOns = 0; for (final SubscriptionBase subscription : subscriptionsForBundle) { if (subscription.getCurrentPlan().getName().equalsIgnoreCase(planName) && subscription.getLastActiveProduct().getCategory() != null && ProductCategory.ADD_ON.equals(subscription.getLastActiveProduct().getCategory())) { countExistingAddOns++; } } return countExistingAddOns; } }
@Override public int hashCode() { int result = product != null ? product.hashCode() : 0; result = 31 * result + (productCategory != null ? productCategory.hashCode() : 0); result = 31 * result + (billingPeriod != null ? billingPeriod.hashCode() : 0); result = 31 * result + (priceList != null ? priceList.hashCode() : 0); return result; }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { this.phaseType = in.readBoolean() ? PhaseType.valueOf(in.readUTF()) : null; this.fromProduct = (DefaultProduct) in.readObject(); this.fromProductCategory = in.readBoolean() ? ProductCategory.valueOf(in.readUTF()) : null; this.fromBillingPeriod = in.readBoolean() ? BillingPeriod.valueOf(in.readUTF()) : null; this.fromPriceList = (DefaultPriceList) in.readObject(); this.toProduct = (DefaultProduct) in.readObject(); this.toProductCategory = in.readBoolean() ? ProductCategory.valueOf(in.readUTF()) : null; this.toBillingPeriod = in.readBoolean() ? BillingPeriod.valueOf(in.readUTF()) : null; this.toPriceList = (DefaultPriceList) in.readObject(); } }
@Override public void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); out.writeObject(fromProduct); out.writeBoolean(fromProductCategory != null); if (fromProductCategory != null) { out.writeUTF(fromProductCategory.name()); } out.writeBoolean(fromBillingPeriod != null); if (fromBillingPeriod != null) { out.writeUTF(fromBillingPeriod.name()); } out.writeObject(fromPriceList); out.writeObject(toPriceList); }
@Override public List<Listing> getAvailableBasePlanListings() { final List<Listing> availBasePlans = new ArrayList<Listing>(); for (final Plan plan : getCurrentPlans()) { if (plan.getProduct().getCategory().equals(ProductCategory.BASE)) { for (final PriceList priceList : getPriceLists().getAllPriceLists()) { for (final 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; }
@Override public int hashCode() { int result = phaseType != null ? phaseType.hashCode() : 0; result = 31 * result + (fromProduct != null ? fromProduct.hashCode() : 0); result = 31 * result + (fromProductCategory != null ? fromProductCategory.hashCode() : 0); result = 31 * result + (fromBillingPeriod != null ? fromBillingPeriod.hashCode() : 0); result = 31 * result + (fromPriceList != null ? fromPriceList.hashCode() : 0); result = 31 * result + (toProduct != null ? toProduct.hashCode() : 0); result = 31 * result + (toProductCategory != null ? toProductCategory.hashCode() : 0); result = 31 * result + (toBillingPeriod != null ? toBillingPeriod.hashCode() : 0); result = 31 * result + (toPriceList != null ? toPriceList.hashCode() : 0); return result; }
public ProductJson(final Product product) { this.type = product.getCategory().toString(); this.name = product.getName(); this.prettyName = product.getPrettyName(); this.plans = new LinkedList<PlanJson>(); this.included = toProductNames(product.getIncluded()); this.available = toProductNames(product.getAvailable()); }