private DefaultPlan maybeGetOverriddenPlan(final String planName) throws CatalogApiException { final InternalTenantContext internalTenantContext = createInternalTenantContext(); try { return priceOverride.getOverriddenPlan(planName, this, internalTenantContext); } catch (final RuntimeException e) { if (e.getCause() == null || e.getCause().getCause() == null || !(e.getCause().getCause() instanceof CatalogApiException) || ((CatalogApiException) e.getCause().getCause()).getCode() != ErrorCode.CAT_NO_SUCH_PLAN.getCode()) { throw e; } else { // Otherwise, ambiguous name? See https://github.com/killbill/killbill/issues/842. return null; } } }
public SubscriptionBaseTransferApiException(final CatalogApiException e) { super(e, e.getCode(), e.getMessage()); }
@Override public DefaultPlan findCurrentPlan(final String name) throws CatalogApiException { if (name == null || plans == null) { throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PLAN, name); } final DefaultPlan result = (DefaultPlan) plans.findByName(name); if (result != null) { return result; } throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PLAN, name); }
final List<StandaloneCatalog> catalogs = versionsBeforeDate(requestedDate.toDate()); if (catalogs.isEmpty()) { throw new CatalogApiException(ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE, requestedDate.toDate().toString()); plan = wrapper.findPlan(c); } catch (final CatalogApiException e) { if (e.getCode() != ErrorCode.CAT_NO_SUCH_PLAN.getCode() && e.getCode() != ErrorCode.CAT_PLAN_NOT_FOUND.getCode()) { throw e; } else { throw new CatalogApiException(ErrorCode.CAT_PLAN_NOT_FOUND, spec.getPlanName() != null ? spec.getPlanName() : "undefined", spec.getProductName() != null ? spec.getProductName() : "undefined",
log.warn("Failed to compute invoice pretty names:", e.getMessage()); } finally { result[0] = prettyProductName;
final List<StandaloneCatalog> catalogs = versionsBeforeDate(requestedDate.toDate()); if (catalogs.isEmpty()) { throw new CatalogApiException(ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE, requestedDate.toDate().toString()); plan = wrapper.findPlan(c); } catch (final CatalogApiException e) { if (e.getCode() != ErrorCode.CAT_NO_SUCH_PLAN.getCode() && e.getCode() != ErrorCode.CAT_PLAN_NOT_FOUND.getCode()) { throw e; } else { throw new CatalogApiException(ErrorCode.CAT_PLAN_NOT_FOUND, spec.getPlanName() != null ? spec.getPlanName() : "undefined", spec.getProductName() != null ? spec.getProductName() : "undefined",
private void addBadSimplePlanDescriptor(final CatalogUpdater catalogUpdater, final SimplePlanDescriptor desc) { try { catalogUpdater.addSimplePlanDescriptor(desc); fail("Should have failed to add invalid desc " + desc); } catch (final CatalogApiException e) { assertEquals(e.getCode(), ErrorCode.CAT_FAILED_SIMPLE_PLAN_VALIDATION.getCode()); } } }
public SubscriptionBaseRepairException(final CatalogApiException e) { super(e, e.getCode(), e.getMessage()); }
@Override public Product findCurrentProduct(final String name) throws CatalogApiException { if (name == null || products == null) { throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PRODUCT, name); } final Product result = products.findByName(name); if (result != null) { return result; } throw new CatalogApiException(ErrorCode.CAT_NO_SUCH_PRODUCT, name); }
protected void assertionException(final DefaultCaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final PhaseType phaseType, final StandaloneCatalog cat) { try { Assert.assertNull(cr.getResult(new PlanPhaseSpecifier(productName, bp, priceListName, phaseType), cat)); Assert.fail("Exception expected"); } catch (CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_PRICE_LIST_NOT_FOUND.getCode()); } }
public SubscriptionBaseTransferApiException(final CatalogApiException e) { super(e, e.getCode(), e.getMessage()); }
@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); }
@Test(groups = "fast") public void testErrorOnDateTooEarly() throws CatalogApiException { // We find it although the date provided is too early because we default to first catalog version vc.findPlan("shotgun-monthly", dt0); try { // We **don't find it** because date is too early and not part of first catalog version vc.findPlan("shotgun-quarterly", dt0); Assert.fail("Date is too early an exception should have been thrown"); } catch (final CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PLAN.getCode()); } }
public SubscriptionBaseRepairException(final CatalogApiException e) { super(e, e.getCode(), e.getMessage()); }
@Override public Double getMinTopUpCredit() throws CatalogApiException { if (!CatalogSafetyInitializer.DEFAULT_NON_REQUIRED_DOUBLE_FIELD_VALUE.equals(minTopUpCredit) && type != BlockType.TOP_UP) { throw new CatalogApiException(ErrorCode.CAT_NOT_TOP_UP_BLOCK, phase.getName()); } return minTopUpCredit; }
protected void assertionException(final DefaultCaseResult cr, final String productName, final ProductCategory productCategory, final BillingPeriod bp, final String priceListName, final StandaloneCatalog cat) { try { cr.getResult(new PlanSpecifier(productName, bp, priceListName), cat); Assert.fail("Expecting an exception"); } catch (CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_PRICE_LIST_NOT_FOUND.getCode()); } }
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); }
@Test(groups = "fast") public void testWithDeletedPlan() throws CatalogApiException { // We find it because this is version 2 whose effectiveDate is "2011-02-02T00:00:00+00:00" vc.findPlan("shotgun-quarterly", dt2); try { // We **don't find it** because date provided matches version 3 where plan was removed vc.findPlan("shotgun-quarterly", dt3); Assert.fail("Plan has been removed"); } catch (final CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_NO_SUCH_PLAN.getCode()); } // Similar test but for existing subscription: we want to find the plan in the original catalog in this case. // This would be called for instance when computing billing events (dt3 could be a future PHASE event for instance) vc.findPlan("shotgun-quarterly", dt3, dt1); }
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; } } // If the only version we have are after the input date, we return the first version // This is not strictly correct from an api point of view, but there is no real good use case // where the system would ask for the catalog for a date prior any catalog was uploaded and // yet time manipulation could end of inn that state -- see https://github.com/killbill/killbill/issues/760 if (!versions.isEmpty()) { return 0; } throw new CatalogApiException(ErrorCode.CAT_NO_CATALOG_FOR_GIVEN_DATE, date.toString()); }
protected void assertionException(final DefaultCaseChangeResult cr, final String fromProductName, final String toProductName, final BillingPeriod fromBp, final BillingPeriod toBp, final String fromPriceListName, final String toPriceListName, final PhaseType phaseType, final StandaloneCatalog cat) { try { cr.getResult(new PlanPhaseSpecifier(fromProductName, fromBp, fromPriceListName, phaseType), new PlanSpecifier(toProductName, toBp, toPriceListName), cat); Assert.fail("Expecting an exception"); } catch (CatalogApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.CAT_PRICE_LIST_NOT_FOUND.getCode()); } }