@Override public Product findCurrentProduct(final String name) throws CatalogApiException { if (name == null || products == null) { throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PRODUCT, name); } for (final DefaultProduct p : products) { if (p.getName().equals(name)) { return p; } } throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PRODUCT, name); }
@Override public DefaultPlan findCurrentPlan(final String name) throws CatalogApiException { if (name == null || plans == null) { throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PLAN, name); } for (final DefaultPlan p : plans) { if (p.getName().equals(name)) { return p; } } throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PLAN, name); }
private int indexOfVersionForDate(final Date date) throws CatalogApiException { for (int i = versions.size() - 1; i >= 0; i--) { final StandaloneCatalog c = versions.get(i); if (c.getEffectiveDate().getTime() < date.getTime()) { return i; } } throw new CatalogApiException(ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE, date.toString()); }
@Override public PriceList findCurrentPricelist(final String name) throws CatalogApiException { if (name == null || priceLists == null) { throw new CatalogApiException(ErrorCode.CAT_PRICE_LIST_NOT_FOUND, name); } return priceLists.findPriceListFrom(name); }
public DefaultPriceList findPriceListFrom(final String priceListName) throws CatalogApiException { if (priceListName == null) { throw new CatalogApiException(ErrorCode.CAT_NULL_PRICE_LIST_NAME); } if (defaultPricelist.getName().equals(priceListName)) { return defaultPricelist; } for (final DefaultPriceList pl : childPriceLists) { if (pl.getName().equals(priceListName)) { return pl; } } throw new CatalogApiException(ErrorCode.CAT_PRICE_LIST_NOT_FOUND, priceListName); }
@Override public DefaultPlan findCurrentPlan(final String productName, final BillingPeriod period, final String priceListName) throws CatalogApiException { if (productName == null) { throw new CatalogApiException(ErrorCode.CAT_NULL_PRODUCT_NAME); } if (priceLists == null) { throw new CatalogApiException(ErrorCode.CAT_PRICE_LIST_NOT_FOUND, priceListName); } final Product product = findCurrentProduct(productName); final DefaultPlan result = priceLists.getPlanFrom(priceListName, product, period); if (result == null) { final String periodString = (period == null) ? "NULL" : period.toString(); throw new CatalogApiException(ErrorCode.CAT_PLAN_NOT_FOUND, productName, periodString, priceListName); } return result; }
public static String planName(final String phaseName) throws CatalogApiException { for (final PhaseType type : PhaseType.values()) { if (phaseName.endsWith(type.toString().toLowerCase())) { return phaseName.substring(0, phaseName.length() - type.toString().length() - 1); } } throw new CatalogApiException(ErrorCode.CAT_BAD_PHASE_NAME, phaseName); }
@Override public PlanPhase findPhase(final String name) throws CatalogApiException { for (final PlanPhase pp : getAllPhases()) { if (pp.getName().equals(name)) { return pp; } } throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PHASE, name); }
@Override public BigDecimal getPrice(final Currency currency) throws CatalogApiException { for (final Price p : prices) { if (p.getCurrency() == currency) { return p.getValue(); } } throw new CatalogApiException(ErrorCode.CAT_NO_PRICE_FOR_CURRENCY, currency); }
public void add(final StandaloneCatalog e) throws CatalogApiException { if (catalogName == null) { catalogName = e.getCatalogName(); } else { if (!catalogName.equals(getCatalogName())) { throw new CatalogApiException(ErrorCode.CAT_CATALOG_NAME_MISMATCH, catalogName, e.getCatalogName()); } } versions.add(e); Collections.sort(versions, new Comparator<StandaloneCatalog>() { @Override public int compare(final StandaloneCatalog c1, final StandaloneCatalog c2) { return c1.getEffectiveDate().compareTo(c2.getEffectiveDate()); } }); }
final List<StandaloneCatalog> catalogs = versionsBeforeDate(requestedDate.toDate()); if (catalogs.size() == 0) { throw new CatalogApiException(ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE, requestedDate.toDate().toString()); throw new CatalogApiException(ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE, requestedDate.toDate().toString());
@Override public PlanPhase findCurrentPhase(final String name) throws CatalogApiException { if (name == null || plans == null) { throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PHASE, name); } final String planName = DefaultPlanPhase.planName(name); final Plan plan = findCurrentPlan(planName); return plan.findPhase(name); }
@VisibleForTesting int calculateBcdForAlignment(final BillingAlignment alignment, final SubscriptionBaseBundle bundle, final SubscriptionBase subscription, final Account account, final Catalog catalog, final Plan plan, final InternalCallContext context) throws AccountApiException, SubscriptionBaseApiException, CatalogApiException { int result = 0; switch (alignment) { case ACCOUNT: result = account.getBillCycleDayLocal(); if (result == 0) { result = calculateBcdFromSubscription(subscription, plan, account, catalog, context); } break; case BUNDLE: final SubscriptionBase baseSub = subscriptionApi.getBaseSubscription(bundle.getId(), context); Plan basePlan = baseSub.getCurrentPlan(); if (basePlan == null) { // The BP has been cancelled basePlan = baseSub.getLastActivePlan(); } result = calculateBcdFromSubscription(baseSub, basePlan, account, catalog, context); break; case SUBSCRIPTION: result = calculateBcdFromSubscription(subscription, plan, account, catalog, context); break; } if (result == 0) { throw new CatalogApiException(ErrorCode.CAT_INVALID_BILLING_ALIGNMENT, alignment.toString()); } return result; }