@Override public BigDecimal getPrice(final Currency currency) throws CatalogApiException { if (prices.length == 0) { return BigDecimal.ZERO; } for (final Price p : prices) { if (p.getCurrency() == currency) { return p.getValue(); } } throw new CatalogApiException(ErrorCode.CAT_NO_PRICE_FOR_CURRENCY, currency); }
private boolean isStandaloneSpecifier(final Plan inputPlan) { return inputPlan.getProduct().getCategory() == ProductCategory.STANDALONE; }
private enum WhichPhase { CURRENT, NEXT }
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 boolean apply(final PlanPhasePriceOverride input) { if (input.getPhaseName() != null) { return input.getPhaseName().equals(curPhase.getName()); } // If the phaseName was not passed, we infer by matching the phaseType. This obviously would not work in a case where // a plan is defined with multiple phases of the same type. final PlanPhaseSpecifier curPlanPhaseSpecifier = input.getPlanPhaseSpecifier(); if (curPlanPhaseSpecifier.getPhaseType().equals(curPhase.getPhaseType())) { return true; } return false; } }).orNull();
public boolean isAddonAvailable(final Product baseProduct, final Plan targetAddOnPlan) { final Product targetAddonProduct = targetAddOnPlan.getProduct(); final Collection<Product> availableAddOns = baseProduct.getAvailable(); for (final Product curAv : availableAddOns) { if (curAv.getName().equals(targetAddonProduct.getName())) { return true; } } return false; }
@Override public boolean apply(final TieredBlockPriceOverride input) { return input.getUnitName() != null && input.getSize() != null && input.getMax() != null && (input.getUnitName().equals(curTieredBlock.getUnit().getName()) && Double.compare(input.getSize(), curTieredBlock.getSize()) == 0 && Double.compare(input.getMax(), curTieredBlock.getMax()) == 0); } }).orNull();
public boolean isAddonIncluded(final Product baseProduct, final Plan targetAddOnPlan) { final Product targetAddonProduct = targetAddOnPlan.getProduct(); final Collection<Product> includedAddOns = baseProduct.getIncluded(); for (final Product curAv : includedAddOns) { if (curAv.getName().equals(targetAddonProduct.getName())) { return true; } } return false; }
public DefaultPlanPhase setPlan(final Plan plan) { this.planName = plan.getName(); this.product = plan.getProduct(); return this; }
private BillingPeriod getBillingPeriod(final Catalog catalog, @Nullable final String phaseName, final DateTime effectiveDate, DateTime startDate) throws CatalogApiException { if (phaseName == null) { return BillingPeriod.NO_BILLING_PERIOD; } final PlanPhase phase = catalog.findPhase(phaseName, effectiveDate, startDate); return phase.getRecurring() != null ? phase.getRecurring().getBillingPeriod() : BillingPeriod.NO_BILLING_PERIOD; }
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; }
public T getResult(final PlanPhaseSpecifier specifier, final StaticCatalog c) throws CatalogApiException { if ((phaseType == null || specifier.getPhaseType() == phaseType) && satisfiesCase(new PlanSpecifier(specifier), c)) { return getResult(); } return null; }
@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 Catalog getFullCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext context) throws CatalogApiException { return catalogService.getFullCatalogForInternalUse(useDefaultCatalog, filterTemplateCatalog, context); } }
@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(); } }
@Override public BigDecimal getValue() throws CurrencyValueNull { if (value == null) { throw new CurrencyValueNull(currency); } return value; }
private boolean isBaseSpecifier(final Plan inputPlan) { return inputPlan.getProduct().getCategory() == ProductCategory.BASE; }