Skip to content

Commit

Permalink
Renaming of catalog api to make it clear the operation may create pla…
Browse files Browse the repository at this point in the history
…n entries
  • Loading branch information
sbrossie committed Mar 27, 2015
1 parent c40dc21 commit 9f729f0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
Expand Up @@ -163,7 +163,7 @@ public DefaultPriceListSet getPriceLists() {
* @see org.killbill.billing.catalog.ICatalog#getPlan(java.lang.String, java.lang.String)
*/
@Override
public DefaultPlan findCurrentPlan(final String productName, final BillingPeriod period, final String priceListName, final PlanPhasePriceOverridesWithCallContext unused) throws CatalogApiException {
public DefaultPlan createOrFindCurrentPlan(final String productName, final BillingPeriod period, final String priceListName, final PlanPhasePriceOverridesWithCallContext unused) throws CatalogApiException {
if (productName == null) {
throw new CatalogApiException(ErrorCode.CAT_NULL_PRODUCT_NAME);
}
Expand Down Expand Up @@ -346,7 +346,7 @@ protected StandaloneCatalog setPriceLists(final DefaultPriceListSet priceLists)
@Override
public boolean canCreatePlan(final PlanSpecifier specifier) throws CatalogApiException {
final Product product = findCurrentProduct(specifier.getProductName());
final Plan plan = findCurrentPlan(specifier.getProductName(), specifier.getBillingPeriod(), specifier.getPriceListName(), null);
final Plan plan = createOrFindCurrentPlan(specifier.getProductName(), specifier.getBillingPeriod(), specifier.getPriceListName(), null);
final DefaultPriceList priceList = findCurrentPriceList(specifier.getPriceListName());

return (!product.isRetired()) &&
Expand Down
Expand Up @@ -103,8 +103,8 @@ public DefaultPlan[] getCurrentPlans() throws CatalogApiException {
}

@Override
public Plan findCurrentPlan(final String productName, final BillingPeriod period, final String priceListName, final PlanPhasePriceOverridesWithCallContext overrides) throws CatalogApiException {
final Plan defaultPlan = standaloneCatalog.findCurrentPlan(productName, period, priceListName, null);
public Plan createOrFindCurrentPlan(final String productName, final BillingPeriod period, final String priceListName, final PlanPhasePriceOverridesWithCallContext overrides) throws CatalogApiException {
final Plan defaultPlan = standaloneCatalog.createOrFindCurrentPlan(productName, period, priceListName, null);

if (overrides == null ||
overrides.getOverrides() == null ||
Expand Down
Expand Up @@ -133,7 +133,7 @@ public Plan findPlan(final StandaloneCatalogWithPriceOverride catalog) throws Ca
if (name != null) {
return catalog.findCurrentPlan(name);
} else {
return catalog.findCurrentPlan(productName, bp, priceListName, overrides);
return catalog.createOrFindCurrentPlan(productName, bp, priceListName, overrides);
}
}
}
Expand Down Expand Up @@ -246,13 +246,13 @@ public Plan findPlan(final String name,
}

@Override
public Plan findPlan(final String productName,
public Plan createOrFindPlan(final String productName,
final BillingPeriod term,
final String priceListName,
final PlanPhasePriceOverridesWithCallContext overrides,
final DateTime requestedDate)
throws CatalogApiException {
return versionForDate(requestedDate).findCurrentPlan(productName, term, priceListName, overrides);
return versionForDate(requestedDate).createOrFindCurrentPlan(productName, term, priceListName, overrides);
}

@Override
Expand All @@ -264,7 +264,7 @@ public Plan findPlan(final String name,
}

@Override
public Plan findPlan(final String productName,
public Plan createOrFindPlan(final String productName,
final BillingPeriod term,
final String priceListName,
final PlanPhasePriceOverridesWithCallContext overrides,
Expand Down Expand Up @@ -404,9 +404,9 @@ public Plan[] getCurrentPlans() throws CatalogApiException {
}

@Override
public Plan findCurrentPlan(final String productName, final BillingPeriod term,
public Plan createOrFindCurrentPlan(final String productName, final BillingPeriod term,
final String priceList, PlanPhasePriceOverridesWithCallContext overrides) throws CatalogApiException {
return versionForDate(clock.getUTCNow()).findCurrentPlan(productName, term, priceList, overrides);
return versionForDate(clock.getUTCNow()).createOrFindCurrentPlan(productName, term, priceList, overrides);
}

@Override
Expand Down
Expand Up @@ -112,9 +112,9 @@ public Plan findPlan(final String name, final DateTime requestedDate) throws Cat
}

@Override
public Plan findPlan(final String productName, final BillingPeriod term, final String priceListName, PlanPhasePriceOverridesWithCallContext overrides, final DateTime requestedDate)
public Plan createOrFindPlan(final String productName, final BillingPeriod term, final String priceListName, PlanPhasePriceOverridesWithCallContext overrides, final DateTime requestedDate)
throws CatalogApiException {
return findCurrentPlan(productName, term, priceListName, overrides);
return createOrFindCurrentPlan(productName, term, priceListName, overrides);
}

@Override
Expand All @@ -124,9 +124,9 @@ public Plan findPlan(final String name, final DateTime effectiveDate, final Date
}

@Override
public Plan findPlan(final String productName, final BillingPeriod term, final String priceListName, PlanPhasePriceOverridesWithCallContext overrides, final DateTime requestedDate,
public Plan createOrFindPlan(final String productName, final BillingPeriod term, final String priceListName, PlanPhasePriceOverridesWithCallContext overrides, final DateTime requestedDate,
final DateTime subscriptionStartDate) throws CatalogApiException {
return findCurrentPlan(productName, term, priceListName, overrides);
return createOrFindCurrentPlan(productName, term, priceListName, overrides);
}

@Override
Expand Down
Expand Up @@ -48,11 +48,11 @@ public TimedMigration[] getEventsMigration(final SubscriptionMigrationCase[] inp

try {
TimedMigration[] events;
final Plan plan0 = catalogService.getFullCatalog(context).findPlan(input[0].getPlanPhaseSpecifier().getProductName(),
input[0].getPlanPhaseSpecifier().getBillingPeriod(), input[0].getPlanPhaseSpecifier().getPriceListName(), null, now);
final Plan plan0 = catalogService.getFullCatalog(context).createOrFindPlan(input[0].getPlanPhaseSpecifier().getProductName(),
input[0].getPlanPhaseSpecifier().getBillingPeriod(), input[0].getPlanPhaseSpecifier().getPriceListName(), null, now);

final Plan plan1 = (input.length > 1) ? catalogService.getFullCatalog(context).findPlan(input[1].getPlanPhaseSpecifier().getProductName(),
input[1].getPlanPhaseSpecifier().getBillingPeriod(), input[1].getPlanPhaseSpecifier().getPriceListName(), null, now) :
final Plan plan1 = (input.length > 1) ? catalogService.getFullCatalog(context).createOrFindPlan(input[1].getPlanPhaseSpecifier().getProductName(),
input[1].getPlanPhaseSpecifier().getBillingPeriod(), input[1].getPlanPhaseSpecifier().getPriceListName(), null, now) :
null;

DateTime migrationStartDate = input[0].getEffectiveDate();
Expand Down
Expand Up @@ -117,7 +117,7 @@ public SubscriptionBase createSubscription(final UUID bundleId, final PlanPhaseS
final Catalog catalog = catalogService.getFullCatalog(context);
final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(overrides, callContext);

final Plan plan = catalog.findPlan(spec.getProductName(), spec.getBillingPeriod(), realPriceList, overridesWithContext, requestedDate);
final Plan plan = catalog.createOrFindPlan(spec.getProductName(), spec.getBillingPeriod(), realPriceList, overridesWithContext, requestedDate);
final PlanPhase phase = plan.getAllPhases()[0];
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",
Expand Down Expand Up @@ -403,7 +403,7 @@ private void populateDryRunEvents(@Nullable final UUID bundleId,

final PlanPhasePriceOverridesWithCallContext overridesWithContext = null; // TODO not supported to dryRun with custom price
final Plan plan = (inputSpec != null && inputSpec.getProductName() != null && inputSpec.getBillingPeriod() != null) ?
catalog.findPlan(inputSpec.getProductName(), inputSpec.getBillingPeriod(), realPriceList, overridesWithContext, utcNow) : null;
catalog.createOrFindPlan(inputSpec.getProductName(), inputSpec.getBillingPeriod(), realPriceList, overridesWithContext, utcNow) : null;
final TenantContext tenantContext = internalCallContextFactory.createTenantContext(context);

if (dryRunArguments != null) {
Expand Down
Expand Up @@ -121,7 +121,7 @@ public boolean recreatePlan(final DefaultSubscriptionBase subscription, final Pl
final String realPriceList = (spec.getPriceListName() == null) ? PriceListSet.DEFAULT_PRICELIST_NAME : spec.getPriceListName();
final InternalTenantContext internalCallContext = createTenantContextFromBundleId(subscription.getBundleId(), context);
final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(overrides, context);
final Plan plan = catalogService.getFullCatalog(internalCallContext).findPlan(spec.getProductName(), spec.getBillingPeriod(), realPriceList, overridesWithContext, effectiveDate);
final Plan plan = catalogService.getFullCatalog(internalCallContext).createOrFindPlan(spec.getProductName(), spec.getBillingPeriod(), realPriceList, overridesWithContext, effectiveDate);
final PlanPhase phase = plan.getAllPhases()[0];
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",
Expand Down Expand Up @@ -353,7 +353,7 @@ private DateTime doChangePlan(final DefaultSubscriptionBase subscription,
final CallContext context) throws SubscriptionBaseApiException, CatalogApiException {
final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context);
final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(overrides, context);
final Plan newPlan = catalogService.getFullCatalog(internalCallContext).findPlan(newProductName, newBillingPeriod, newPriceList, overridesWithContext, effectiveDate, subscription.getStartDate());
final Plan newPlan = catalogService.getFullCatalog(internalCallContext).createOrFindPlan(newProductName, newBillingPeriod, newPriceList, overridesWithContext, effectiveDate, subscription.getStartDate());

final List<SubscriptionBaseEvent> changeEvents = getEventsOnChangePlan(subscription, newPlan, newPriceList, now, effectiveDate, now, false, internalCallContext);
dao.changePlan(subscription, changeEvents, internalCallContext);
Expand Down

1 comment on commit 9f729f0

@pierre
Copy link
Member

@pierre pierre commented on 9f729f0 Mar 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Nit: I would have named it findOrCreatePlan to match the implementation.

Please sign in to comment.