killbill-aplcache
Changes
subscription/src/main/java/org/killbill/billing/subscription/api/SubscriptionBaseApiService.java 10(+5 -5)
subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java 36(+17 -19)
subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java 52(+25 -27)
subscription/src/main/java/org/killbill/billing/subscription/api/user/SubscriptionSpecifier.java 12(+1 -11)
Details
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/alignment/PlanAligner.java b/subscription/src/main/java/org/killbill/billing/subscription/alignment/PlanAligner.java
index 8d76cbd..fe4e369 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/alignment/PlanAligner.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/alignment/PlanAligner.java
@@ -70,7 +70,6 @@ public class PlanAligner extends BaseAligner {
* @param plan the current Plan
* @param initialPhase the initialPhase on which we should create that subscription. can be null
* @param priceList the priceList
- * @param requestedDate the requested date (only used to loadDefaultCatalog the catalog)
* @param effectiveDate the effective creation date (driven by the catalog policy, i.e. when the creation occurs)
* @return the current and next phases
* @throws CatalogApiException for catalog errors
@@ -81,7 +80,6 @@ public class PlanAligner extends BaseAligner {
final Plan plan,
@Nullable final PhaseType initialPhase,
final String priceList,
- final DateTime requestedDate,
final DateTime effectiveDate,
final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException {
final List<TimedPhase> timedPhases = getTimedPhaseOnCreate(alignStartDate,
@@ -89,7 +87,7 @@ public class PlanAligner extends BaseAligner {
plan,
initialPhase,
priceList,
- requestedDate,
+ effectiveDate,
context);
final TimedPhase[] result = new TimedPhase[2];
result[0] = getTimedPhase(timedPhases, effectiveDate, WhichPhase.CURRENT);
@@ -104,7 +102,6 @@ public class PlanAligner extends BaseAligner {
* are looked at)
* @param plan the current Plan
* @param priceList the priceList on which we should change that subscription.
- * @param requestedDate the requested date
* @param effectiveDate the effective change date (driven by the catalog policy, i.e. when the change occurs)
* @return the current phase
* @throws CatalogApiException for catalog errors
@@ -113,10 +110,9 @@ public class PlanAligner extends BaseAligner {
public TimedPhase getCurrentTimedPhaseOnChange(final DefaultSubscriptionBase subscription,
final Plan plan,
final String priceList,
- final DateTime requestedDate,
final DateTime effectiveDate,
final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException {
- return getTimedPhaseOnChange(subscription, plan, priceList, requestedDate, effectiveDate, WhichPhase.CURRENT, context);
+ return getTimedPhaseOnChange(subscription, plan, priceList, effectiveDate, WhichPhase.CURRENT, context);
}
/**
@@ -126,7 +122,6 @@ public class PlanAligner extends BaseAligner {
* are looked at)
* @param plan the current Plan
* @param priceList the priceList on which we should change that subscription.
- * @param requestedDate the requested date
* @param effectiveDate the effective change date (driven by the catalog policy, i.e. when the change occurs)
* @return the next phase
* @throws CatalogApiException for catalog errors
@@ -135,21 +130,18 @@ public class PlanAligner extends BaseAligner {
public TimedPhase getNextTimedPhaseOnChange(final DefaultSubscriptionBase subscription,
final Plan plan,
final String priceList,
- final DateTime requestedDate,
final DateTime effectiveDate,
final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException {
- return getTimedPhaseOnChange(subscription, plan, priceList, requestedDate, effectiveDate, WhichPhase.NEXT, context);
+ return getTimedPhaseOnChange(subscription, plan, priceList, effectiveDate, WhichPhase.NEXT, context);
}
/**
* Returns next Phase for that SubscriptionBase at a point in time
*
* @param subscription the subscription for which we need to compute the next Phase event
- * @param requestedDate the requested date
- * @param effectiveDate the date at which we look to compute that event. effective needs to be after last Plan change or initial Plan
* @return the next phase
*/
- public TimedPhase getNextTimedPhase(final DefaultSubscriptionBase subscription, final DateTime requestedDate, final DateTime effectiveDate, final InternalTenantContext context) {
+ public TimedPhase getNextTimedPhase(final DefaultSubscriptionBase subscription, final DateTime effectiveDate, final InternalTenantContext context) {
try {
final SubscriptionBaseTransitionData lastPlanTransition = subscription.getLastTransitionForCurrentPlan();
if (effectiveDate.isBefore(lastPlanTransition.getEffectiveTransitionTime())) {
@@ -168,10 +160,9 @@ public class PlanAligner extends BaseAligner {
lastPlanTransition.getNextPlan(),
lastPlanTransition.getNextPhase().getPhaseType(),
lastPlanTransition.getNextPriceList().getName(),
- requestedDate,
+ effectiveDate,
context);
return getTimedPhase(timedPhases, effectiveDate, WhichPhase.NEXT);
- // If we went through Plan changes, borrow the logic for changePlanWithRequestedDate alignment
case CHANGE:
return getTimedPhaseOnChange(subscription.getAlignStartDate(),
subscription.getBundleStartDate(),
@@ -180,7 +171,6 @@ public class PlanAligner extends BaseAligner {
lastPlanTransition.getPreviousPriceList().getName(),
lastPlanTransition.getNextPlan(),
lastPlanTransition.getNextPriceList().getName(),
- requestedDate,
effectiveDate,
lastPlanTransition.getEffectiveTransitionTime(),
WhichPhase.NEXT,
@@ -199,7 +189,7 @@ public class PlanAligner extends BaseAligner {
final Plan plan,
@Nullable final PhaseType initialPhase,
final String priceList,
- final DateTime requestedDate,
+ final DateTime effectiveDate,
final InternalTenantContext context)
throws CatalogApiException, SubscriptionBaseApiException {
final Catalog catalog = catalogService.getFullCatalog(context);
@@ -210,7 +200,7 @@ public class PlanAligner extends BaseAligner {
priceList);
final DateTime planStartDate;
- final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, requestedDate);
+ final PlanAlignmentCreate alignment = catalog.planCreateAlignment(planSpecifier, effectiveDate);
switch (alignment) {
case START_OF_SUBSCRIPTION:
planStartDate = subscriptionStartDate;
@@ -228,7 +218,6 @@ public class PlanAligner extends BaseAligner {
private TimedPhase getTimedPhaseOnChange(final DefaultSubscriptionBase subscription,
final Plan nextPlan,
final String nextPriceList,
- final DateTime requestedDate,
final DateTime effectiveDate,
final WhichPhase which,
final InternalTenantContext context) throws CatalogApiException, SubscriptionBaseApiException {
@@ -239,7 +228,6 @@ public class PlanAligner extends BaseAligner {
subscription.getCurrentPriceList().getName(),
nextPlan,
nextPriceList,
- requestedDate,
effectiveDate,
// This method is only called while doing the change, hence we want to pass the change effective date
effectiveDate,
@@ -254,7 +242,6 @@ public class PlanAligner extends BaseAligner {
final String currentPriceList,
final Plan nextPlan,
final String priceList,
- final DateTime requestedDate,
final DateTime effectiveDate,
final DateTime lastOrCurrentChangeEffectiveDate,
final WhichPhase which,
@@ -273,7 +260,7 @@ public class PlanAligner extends BaseAligner {
priceList);
final DateTime planStartDate;
- final PlanAlignmentChange alignment = catalog.planChangeAlignment(fromPlanPhaseSpecifier, toPlanSpecifier, requestedDate);
+ final PlanAlignmentChange alignment = catalog.planChangeAlignment(fromPlanPhaseSpecifier, toPlanSpecifier, effectiveDate);
switch (alignment) {
case START_OF_SUBSCRIPTION:
planStartDate = subscriptionStartDate;
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/api/SubscriptionBaseApiService.java b/subscription/src/main/java/org/killbill/billing/subscription/api/SubscriptionBaseApiService.java
index 26c6a3d..a4fefd0 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/api/SubscriptionBaseApiService.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/api/SubscriptionBaseApiService.java
@@ -43,7 +43,7 @@ import org.killbill.billing.util.callcontext.TenantContext;
public interface SubscriptionBaseApiService {
public DefaultSubscriptionBase createPlan(SubscriptionBuilder builder, Plan plan, PhaseType initialPhase,
- String realPriceList, DateTime requestedDate, DateTime effectiveDate, DateTime processedDate,
+ String realPriceList, DateTime effectiveDate, DateTime processedDate,
CallContext context)
throws SubscriptionBaseApiException;
@@ -91,16 +91,16 @@ public interface SubscriptionBaseApiService {
//
public List<SubscriptionBaseEvent> getEventsOnCreation(UUID bundleId, UUID subscriptionId, DateTime alignStartDate, DateTime bundleStartDate, long activeVersion,
Plan plan, PhaseType initialPhase,
- String realPriceList, DateTime requestedDate, DateTime effectiveDate, DateTime processedDate,
+ String realPriceList, DateTime effectiveDate, DateTime processedDate,
boolean reCreate, InternalTenantContext context)
throws CatalogApiException, SubscriptionBaseApiException;
public List<SubscriptionBaseEvent> getEventsOnChangePlan(DefaultSubscriptionBase subscription, Plan newPlan,
- String newPriceList, DateTime requestedDate, DateTime effectiveDate, DateTime processedDate,
+ String newPriceList, DateTime effectiveDate, DateTime processedDate,
boolean addCancellationAddOnForEventsIfRequired, InternalTenantContext context)
throws CatalogApiException, SubscriptionBaseApiException;
public List<SubscriptionBaseEvent> getEventsOnCancelPlan(final DefaultSubscriptionBase subscription,
- final DateTime requestedDate, final DateTime effectiveDate, final DateTime processedDate,
- final boolean addCancellationAddOnForEventsIfRequired, final InternalTenantContext context) throws CatalogApiException;
+ final DateTime effectiveDate, final DateTime processedDate,
+ final boolean addCancellationAddOnForEventsIfRequired, final InternalTenantContext internalTenantContext) throws CatalogApiException;
}
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java b/subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java
index 5155064..64c4d39 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/api/svcs/DefaultSubscriptionInternalApi.java
@@ -125,19 +125,18 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
try {
final String realPriceList = (spec.getPriceListName() == null) ? PriceListSet.DEFAULT_PRICELIST_NAME : spec.getPriceListName();
final DateTime now = clock.getUTCNow();
- final DateTime requestedDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : now;
+ final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : now;
/*
if (requestedDate.isAfter(now)) {
throw new SubscriptionBaseApiException(ErrorCode.SUB_INVALID_REQUESTED_DATE, now.toString(), requestedDate.toString());
}
*/
- final DateTime effectiveDate = requestedDate;
final CallContext callContext = internalCallContextFactory.createCallContext(context);
final Catalog catalog = catalogService.getFullCatalog(context);
final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(overrides, callContext);
- final Plan plan = catalog.createOrFindPlan(spec.getProductName(), spec.getBillingPeriod(), realPriceList, overridesWithContext, requestedDate);
+ final Plan plan = catalog.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",
@@ -150,14 +149,14 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
}
final DefaultSubscriptionBase baseSubscription = (DefaultSubscriptionBase) dao.getBaseSubscription(bundleId, context);
- final DateTime bundleStartDate = getBundleStartDateWithSanity(bundleId, baseSubscription, plan, requestedDate, effectiveDate, context);
+ final DateTime bundleStartDate = getBundleStartDateWithSanity(bundleId, baseSubscription, plan, effectiveDate, context);
return apiService.createPlan(new SubscriptionBuilder()
.setId(UUIDs.randomUUID())
.setBundleId(bundleId)
.setCategory(plan.getProduct().getCategory())
.setBundleStartDate(bundleStartDate)
.setAlignStartDate(effectiveDate),
- plan, spec.getPhaseType(), realPriceList, requestedDate, effectiveDate, now, callContext);
+ plan, spec.getPhaseType(), realPriceList, effectiveDate, now, callContext);
} catch (final CatalogApiException e) {
throw new SubscriptionBaseApiException(e);
}
@@ -167,7 +166,7 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
public SubscriptionBase createBaseSubscriptionWithAddOns(final UUID bundleId, final Iterable<EntitlementSpecifier> entitlements, final DateTime requestedDateWithMs, final InternalCallContext context) throws SubscriptionBaseApiException {
final DateTime now = clock.getUTCNow();
- final DateTime requestedDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : now;
+ final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : now;
try {
final List<SubscriptionSpecifier> subscriptions = new ArrayList<SubscriptionSpecifier>();
@@ -181,7 +180,7 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(entitlement.getOverrides(), callContext);
- final Plan plan = catalog.createOrFindPlan(spec.getProductName(), spec.getBillingPeriod(), realPriceList, overridesWithContext, requestedDate);
+ final Plan plan = catalog.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",
@@ -195,8 +194,7 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
SubscriptionSpecifier subscription = new SubscriptionSpecifier();
subscription.setRealPriceList(realPriceList);
- subscription.setRequestedDate(requestedDate);
- subscription.setEffectiveDate(requestedDate);
+ subscription.setEffectiveDate(effectiveDate);
subscription.setProcessedDate(now);
subscription.setPlan(plan);
subscription.setInitialPhase(spec.getPhaseType());
@@ -204,8 +202,8 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
.setId(UUIDs.randomUUID())
.setBundleId(bundleId)
.setCategory(plan.getProduct().getCategory())
- .setBundleStartDate(requestedDate)
- .setAlignStartDate(requestedDate));
+ .setBundleStartDate(effectiveDate)
+ .setAlignStartDate(effectiveDate));
subscriptions.add(subscription);
}
@@ -485,10 +483,10 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
final DefaultSubscriptionBase baseSubscription = (DefaultSubscriptionBase) dao.getBaseSubscription(bundleId, context);
final DateTime startEffectiveDate = dryRunArguments.getEffectiveDate() != null ? dryRunArguments.getEffectiveDate() : utcNow;
- final DateTime bundleStartDate = getBundleStartDateWithSanity(bundleId, baseSubscription, plan, startEffectiveDate, startEffectiveDate, context);
+ final DateTime bundleStartDate = getBundleStartDateWithSanity(bundleId, baseSubscription, plan, startEffectiveDate, context);
final UUID subscriptionId = UUIDs.randomUUID();
dryRunEvents = apiService.getEventsOnCreation(bundleId, subscriptionId, startEffectiveDate, bundleStartDate, 1L, plan, inputSpec.getPhaseType(), realPriceList,
- utcNow, startEffectiveDate, utcNow, false, context);
+ startEffectiveDate, utcNow, false, context);
final SubscriptionBuilder builder = new SubscriptionBuilder()
.setId(subscriptionId)
.setBundleId(bundleId)
@@ -514,7 +512,7 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
}
changeEffectiveDate = subscriptionForChange.getPlanChangeEffectiveDate(policy);
}
- dryRunEvents = apiService.getEventsOnChangePlan(subscriptionForChange, plan, realPriceList, utcNow, changeEffectiveDate, utcNow, true, context);
+ dryRunEvents = apiService.getEventsOnChangePlan(subscriptionForChange, plan, realPriceList, changeEffectiveDate, utcNow, true, context);
break;
case STOP_BILLING:
@@ -534,7 +532,7 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
}
cancelEffectiveDate = subscriptionForCancellation.getPlanChangeEffectiveDate(policy);
}
- dryRunEvents = apiService.getEventsOnCancelPlan(subscriptionForCancellation, utcNow, cancelEffectiveDate, utcNow, true, context);
+ dryRunEvents = apiService.getEventsOnCancelPlan(subscriptionForCancellation, cancelEffectiveDate, utcNow, true, context);
break;
default:
@@ -587,14 +585,14 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
}
private DateTime getBundleStartDateWithSanity(final UUID bundleId, @Nullable final DefaultSubscriptionBase baseSubscription, final Plan plan,
- final DateTime requestedDate, final DateTime effectiveDate, final InternalTenantContext context) throws SubscriptionBaseApiException, CatalogApiException {
+ final DateTime effectiveDate, final InternalTenantContext context) throws SubscriptionBaseApiException, CatalogApiException {
switch (plan.getProduct().getCategory()) {
case BASE:
if (baseSubscription != null &&
baseSubscription.getState() == EntitlementState.ACTIVE) {
throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_BP_EXISTS, bundleId);
}
- return requestedDate;
+ return effectiveDate;
case ADD_ON:
if (baseSubscription == null) {
@@ -603,7 +601,7 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
if (effectiveDate.isBefore(baseSubscription.getStartDate())) {
throw new SubscriptionBaseApiException(ErrorCode.SUB_INVALID_REQUESTED_DATE, effectiveDate.toString(), baseSubscription.getStartDate().toString());
}
- addonUtils.checkAddonCreationRights(baseSubscription, plan, requestedDate, context);
+ addonUtils.checkAddonCreationRights(baseSubscription, plan, effectiveDate, context);
return baseSubscription.getStartDate();
case STANDALONE:
@@ -611,7 +609,7 @@ public class DefaultSubscriptionInternalApi extends SubscriptionApiBase implemen
throw new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_BP_EXISTS, bundleId);
}
// Not really but we don't care, there is no alignment for STANDALONE subscriptions
- return requestedDate;
+ return effectiveDate;
default:
throw new SubscriptionBaseError(String.format("Can't create subscription of type %s",
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java b/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java
index 6e4b949..2ff39bb 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/api/user/DefaultSubscriptionBaseApiService.java
@@ -100,11 +100,11 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
@Override
public DefaultSubscriptionBase createPlan(final SubscriptionBuilder builder, final Plan plan, final PhaseType initialPhase,
- final String realPriceList, final DateTime requestedDate, final DateTime effectiveDate, final DateTime processedDate,
+ final String realPriceList, final DateTime effectiveDate, final DateTime processedDate,
final CallContext context) throws SubscriptionBaseApiException {
final DefaultSubscriptionBase subscription = new DefaultSubscriptionBase(builder, this, clock);
- createFromSubscription(subscription, plan, initialPhase, realPriceList, requestedDate, effectiveDate, processedDate, false, context);
+ createFromSubscription(subscription, plan, initialPhase, realPriceList, effectiveDate, processedDate, false, context);
return subscription;
}
@@ -120,7 +120,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
final InternalCallContext internalCallContext = createCallContextFromBundleId(subscriptionBase.getBundleId(), context);
final List<SubscriptionBaseEvent> events = getEventsOnCreation(subscriptionBase.getBundleId(), subscriptionBase.getId(), subscriptionBase.getAlignStartDate(),
subscriptionBase.getBundleStartDate(), subscriptionBase.getActiveVersion(), subscription.getPlan(),
- subscription.getInitialPhase(), subscription.getRealPriceList(), subscription.getRequestedDate(),
+ subscription.getInitialPhase(), subscription.getRealPriceList(),
subscription.getEffectiveDate(), subscription.getProcessedDate(), false, internalCallContext);
eventsMap.put(subscriptionBase.getId(), events);
@@ -178,9 +178,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
spec.getProductName(), spec.getBillingPeriod().toString(), realPriceList));
}
- final DateTime processedDate = now;
-
- createFromSubscription(subscription, plan, spec.getPhaseType(), realPriceList, now, effectiveDate, processedDate, true, context);
+ createFromSubscription(subscription, plan, spec.getPhaseType(), realPriceList, effectiveDate, now, true, context);
return true;
} catch (final CatalogApiException e) {
throw new SubscriptionBaseApiException(e);
@@ -188,13 +186,13 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
}
private void createFromSubscription(final DefaultSubscriptionBase subscription, final Plan plan, final PhaseType initialPhase,
- final String realPriceList, final DateTime requestedDate, final DateTime effectiveDate, final DateTime processedDate,
+ final String realPriceList, final DateTime effectiveDate, final DateTime processedDate,
final boolean reCreate, final CallContext context) throws SubscriptionBaseApiException {
final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context);
try {
final List<SubscriptionBaseEvent> events = getEventsOnCreation(subscription.getBundleId(), subscription.getId(), subscription.getAlignStartDate(), subscription.getBundleStartDate(), subscription.getActiveVersion(),
- plan, initialPhase, realPriceList, requestedDate, effectiveDate, processedDate, reCreate, internalCallContext);
+ plan, initialPhase, realPriceList, effectiveDate, processedDate, reCreate, internalCallContext);
if (reCreate) {
dao.recreateSubscription(subscription, events, internalCallContext);
} else {
@@ -260,7 +258,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
validateEffectiveDate(subscription, effectiveDate);
final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context);
- final List<SubscriptionBaseEvent> cancelEvents = getEventsOnCancelPlan(subscription, now, effectiveDate, now, false, internalCallContext);
+ final List<SubscriptionBaseEvent> cancelEvents = getEventsOnCancelPlan(subscription, effectiveDate, now, false, internalCallContext);
// cancelEvents will contain only one item
dao.cancelSubscription(subscription, cancelEvents.get(0), internalCallContext, 0);
final Catalog fullCatalog = catalogService.getFullCatalog(internalCallContext);
@@ -296,7 +294,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
uncancelEvents.add(uncancelEvent);
final InternalCallContext internalCallContext = createCallContextFromBundleId(subscription.getBundleId(), context);
- final TimedPhase nextTimedPhase = planAligner.getNextTimedPhase(subscription, now, now, internalCallContext);
+ final TimedPhase nextTimedPhase = planAligner.getNextTimedPhase(subscription, now, internalCallContext);
final PhaseEvent nextPhaseEvent = (nextTimedPhase != null) ?
PhaseEventData.createNextPhaseEvent(subscription.getId(), subscription.getActiveVersion(), nextTimedPhase.getPhase().getName(), now, nextTimedPhase.getStartPhase()) :
null;
@@ -407,7 +405,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
if (newPlan.getProduct().getCategory() != subscription.getCategory()) {
throw new SubscriptionBaseApiException(ErrorCode.SUB_CHANGE_INVALID, subscription.getId());
}
- final List<SubscriptionBaseEvent> changeEvents = getEventsOnChangePlan(subscription, newPlan, newPriceList, now, effectiveDate, now, false, internalCallContext);
+ final List<SubscriptionBaseEvent> changeEvents = getEventsOnChangePlan(subscription, newPlan, newPriceList, effectiveDate, now, false, internalCallContext);
dao.changePlan(subscription, changeEvents, internalCallContext);
subscription.rebuildTransitions(dao.getEventsForSubscription(subscription.getId(), internalCallContext), catalogService.getFullCatalog(internalCallContext));
@@ -421,10 +419,10 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
@Override
public List<SubscriptionBaseEvent> getEventsOnCreation(final UUID bundleId, final UUID subscriptionId, final DateTime alignStartDate, final DateTime bundleStartDate, final long activeVersion,
final Plan plan, final PhaseType initialPhase,
- final String realPriceList, final DateTime requestedDate, final DateTime effectiveDate, final DateTime processedDate,
+ final String realPriceList, final DateTime effectiveDate, final DateTime processedDate,
final boolean reCreate, final InternalTenantContext internalTenantContext) throws CatalogApiException, SubscriptionBaseApiException {
final TimedPhase[] curAndNextPhases = planAligner.getCurrentAndNextTimedPhaseOnCreate(alignStartDate, bundleStartDate, plan, initialPhase,
- realPriceList, requestedDate, effectiveDate, internalTenantContext);
+ realPriceList, effectiveDate, internalTenantContext);
final ApiEventBuilder createBuilder = new ApiEventBuilder()
.setSubscriptionId(subscriptionId)
@@ -433,7 +431,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
.setEventPriceList(realPriceList)
.setActiveVersion(activeVersion)
.setEffectiveDate(effectiveDate)
- .setRequestedDate(requestedDate)
+ .setRequestedDate(effectiveDate)
.setFromDisk(true);
final ApiEvent creationEvent = (reCreate) ? new ApiEventReCreate(createBuilder) : new ApiEventCreate(createBuilder);
@@ -451,9 +449,9 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
@Override
public List<SubscriptionBaseEvent> getEventsOnChangePlan(final DefaultSubscriptionBase subscription, final Plan newPlan,
- final String newPriceList, final DateTime requestedDate, final DateTime effectiveDate, final DateTime processedDate,
+ final String newPriceList, final DateTime effectiveDate, final DateTime processedDate,
final boolean addCancellationAddOnForEventsIfRequired, final InternalTenantContext internalTenantContext) throws CatalogApiException, SubscriptionBaseApiException {
- final TimedPhase currentTimedPhase = planAligner.getCurrentTimedPhaseOnChange(subscription, newPlan, newPriceList, requestedDate, effectiveDate, internalTenantContext);
+ final TimedPhase currentTimedPhase = planAligner.getCurrentTimedPhaseOnChange(subscription, newPlan, newPriceList, effectiveDate, internalTenantContext);
final SubscriptionBaseEvent changeEvent = new ApiEventChange(new ApiEventBuilder()
.setSubscriptionId(subscription.getId())
@@ -462,10 +460,10 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
.setEventPriceList(newPriceList)
.setActiveVersion(subscription.getActiveVersion())
.setEffectiveDate(effectiveDate)
- .setRequestedDate(requestedDate)
+ .setRequestedDate(effectiveDate)
.setFromDisk(true));
- final TimedPhase nextTimedPhase = planAligner.getNextTimedPhaseOnChange(subscription, newPlan, newPriceList, processedDate, effectiveDate, internalTenantContext);
+ final TimedPhase nextTimedPhase = planAligner.getNextTimedPhaseOnChange(subscription, newPlan, newPriceList, effectiveDate, internalTenantContext);
final PhaseEvent nextPhaseEvent = (nextTimedPhase != null) ?
PhaseEventData.createNextPhaseEvent(subscription.getId(), subscription.getActiveVersion(),
nextTimedPhase.getPhase().getName(), processedDate, nextTimedPhase.getStartPhase()) :
@@ -480,26 +478,26 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
if (subscription.getCategory() == ProductCategory.BASE && addCancellationAddOnForEventsIfRequired) {
final Product currentBaseProduct = changeEvent.getEffectiveDate().compareTo(clock.getUTCNow()) <= 0 ? newPlan.getProduct() : subscription.getCurrentPlan().getProduct();
- addCancellationAddOnForEventsIfRequired(changeEvents, currentBaseProduct, subscription.getBundleId(), requestedDate, effectiveDate, processedDate, internalTenantContext);
+ addCancellationAddOnForEventsIfRequired(changeEvents, currentBaseProduct, subscription.getBundleId(), effectiveDate, internalTenantContext);
}
return changeEvents;
}
@Override
public List<SubscriptionBaseEvent> getEventsOnCancelPlan(final DefaultSubscriptionBase subscription,
- final DateTime requestedDate, final DateTime effectiveDate, final DateTime processedDate,
+ final DateTime effectiveDate, final DateTime processedDate,
final boolean addCancellationAddOnForEventsIfRequired, final InternalTenantContext internalTenantContext) throws CatalogApiException {
final List<SubscriptionBaseEvent> cancelEvents = new ArrayList<SubscriptionBaseEvent>();
final SubscriptionBaseEvent cancelEvent = new ApiEventCancel(new ApiEventBuilder()
.setSubscriptionId(subscription.getId())
.setActiveVersion(subscription.getActiveVersion())
.setEffectiveDate(effectiveDate)
- .setRequestedDate(requestedDate)
+ .setRequestedDate(effectiveDate)
.setFromDisk(true));
cancelEvents.add(cancelEvent);
if (subscription.getCategory() == ProductCategory.BASE && addCancellationAddOnForEventsIfRequired) {
final Product currentBaseProduct = cancelEvent.getEffectiveDate().compareTo(clock.getUTCNow()) <= 0 ? null : subscription.getCurrentPlan().getProduct();
- addCancellationAddOnForEventsIfRequired(cancelEvents, currentBaseProduct, subscription.getBundleId(), requestedDate, effectiveDate, processedDate, internalTenantContext);
+ addCancellationAddOnForEventsIfRequired(cancelEvents, currentBaseProduct, subscription.getBundleId(), effectiveDate, internalTenantContext);
}
return cancelEvents;
}
@@ -513,7 +511,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
final List<SubscriptionBaseEvent> cancelEvents = new LinkedList<SubscriptionBaseEvent>();
final InternalCallContext internalCallContext = createCallContextFromBundleId(bundleId, context);
- final List<DefaultSubscriptionBase> subscriptionsToBeCancelled = addCancellationAddOnForEventsIfRequired(cancelEvents, baseProduct, bundleId, now, effectiveDate, now, internalCallContext);
+ final List<DefaultSubscriptionBase> subscriptionsToBeCancelled = addCancellationAddOnForEventsIfRequired(cancelEvents, baseProduct, bundleId, effectiveDate, internalCallContext);
if (!subscriptionsToBeCancelled.isEmpty()) {
dao.cancelSubscriptions(subscriptionsToBeCancelled, cancelEvents, internalCallContext);
}
@@ -521,7 +519,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
}
private List<DefaultSubscriptionBase> addCancellationAddOnForEventsIfRequired(final List<SubscriptionBaseEvent> events, final Product baseProduct, final UUID bundleId,
- final DateTime requestedDate, final DateTime effectiveDate, final DateTime processedDate, final InternalTenantContext internalTenantContext) throws CatalogApiException {
+ final DateTime effectiveDate, final InternalTenantContext internalTenantContext) throws CatalogApiException {
final List<DefaultSubscriptionBase> subscriptionsToBeCancelled = new ArrayList<DefaultSubscriptionBase>();
@@ -536,8 +534,8 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
final Plan addonCurrentPlan = cur.getCurrentPlan();
if (baseProduct == null ||
- addonUtils.isAddonIncludedFromProdName(baseProduct.getName(), addonCurrentPlan, requestedDate, internalTenantContext) ||
- !addonUtils.isAddonAvailableFromProdName(baseProduct.getName(), addonCurrentPlan, requestedDate, internalTenantContext)) {
+ addonUtils.isAddonIncludedFromProdName(baseProduct.getName(), addonCurrentPlan, effectiveDate, internalTenantContext) ||
+ !addonUtils.isAddonAvailableFromProdName(baseProduct.getName(), addonCurrentPlan, effectiveDate, internalTenantContext)) {
//
// Perform AO cancellation using the effectiveDate of the BP
//
@@ -545,7 +543,7 @@ public class DefaultSubscriptionBaseApiService implements SubscriptionBaseApiSer
.setSubscriptionId(cur.getId())
.setActiveVersion(cur.getActiveVersion())
.setEffectiveDate(effectiveDate)
- .setRequestedDate(requestedDate)
+ .setRequestedDate(effectiveDate)
.setFromDisk(true));
subscriptionsToBeCancelled.add(cur);
events.add(cancelEvent);
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/api/user/SubscriptionSpecifier.java b/subscription/src/main/java/org/killbill/billing/subscription/api/user/SubscriptionSpecifier.java
index 154ee62..aa5ebf4 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/api/user/SubscriptionSpecifier.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/api/user/SubscriptionSpecifier.java
@@ -27,7 +27,6 @@ public class SubscriptionSpecifier {
private Plan plan;
private PhaseType initialPhase;
private String realPriceList;
- private DateTime requestedDate;
private DateTime effectiveDate;
private DateTime processedDate;
@@ -36,13 +35,12 @@ public class SubscriptionSpecifier {
public SubscriptionSpecifier(final SubscriptionBuilder builder, final Plan plan,
final PhaseType initialPhase, final String realPriceList,
- final DateTime requestedDate, final DateTime effectiveDate,
+ final DateTime effectiveDate,
final DateTime processedDate) {
this.builder = builder;
this.plan = plan;
this.initialPhase = initialPhase;
this.realPriceList = realPriceList;
- this.requestedDate = requestedDate;
this.effectiveDate = effectiveDate;
this.processedDate = processedDate;
}
@@ -79,14 +77,6 @@ public class SubscriptionSpecifier {
this.realPriceList = realPriceList;
}
- public DateTime getRequestedDate() {
- return requestedDate;
- }
-
- public void setRequestedDate(final DateTime requestedDate) {
- this.requestedDate = requestedDate;
- }
-
public DateTime getEffectiveDate() {
return effectiveDate;
}
diff --git a/subscription/src/main/java/org/killbill/billing/subscription/engine/core/DefaultSubscriptionBaseService.java b/subscription/src/main/java/org/killbill/billing/subscription/engine/core/DefaultSubscriptionBaseService.java
index a1dcae8..bcd0b26 100644
--- a/subscription/src/main/java/org/killbill/billing/subscription/engine/core/DefaultSubscriptionBaseService.java
+++ b/subscription/src/main/java/org/killbill/billing/subscription/engine/core/DefaultSubscriptionBaseService.java
@@ -185,7 +185,7 @@ public class DefaultSubscriptionBaseService implements EventListener, Subscripti
private void onPhaseEvent(final DefaultSubscriptionBase subscription, final InternalCallContext context) {
try {
final DateTime now = clock.getUTCNow();
- final TimedPhase nextTimedPhase = planAligner.getNextTimedPhase(subscription, now, now, context);
+ final TimedPhase nextTimedPhase = planAligner.getNextTimedPhase(subscription, now, context);
final PhaseEvent nextPhaseEvent = (nextTimedPhase != null) ?
PhaseEventData.createNextPhaseEvent(subscription.getId(), subscription.getActiveVersion(),
nextTimedPhase.getPhase().getName(), now, nextTimedPhase.getStartPhase()) :
diff --git a/subscription/src/test/java/org/killbill/billing/subscription/alignment/TestPlanAligner.java b/subscription/src/test/java/org/killbill/billing/subscription/alignment/TestPlanAligner.java
index 4d7a3e6..85bdaaf 100644
--- a/subscription/src/test/java/org/killbill/billing/subscription/alignment/TestPlanAligner.java
+++ b/subscription/src/test/java/org/killbill/billing/subscription/alignment/TestPlanAligner.java
@@ -85,7 +85,7 @@ public class TestPlanAligner extends SubscriptionTestSuiteNoDB {
Assert.assertEquals(phases[1].getStartPhase(), defaultSubscriptionBase.getBundleStartDate().plusDays(30));
// Verify the next phase via the other API
- final TimedPhase nextTimePhase = planAligner.getNextTimedPhase(defaultSubscriptionBase, effectiveDate, effectiveDate, internalCallContext);
+ final TimedPhase nextTimePhase = planAligner.getNextTimedPhase(defaultSubscriptionBase, effectiveDate, internalCallContext);
Assert.assertEquals(nextTimePhase.getStartPhase(), defaultSubscriptionBase.getBundleStartDate().plusDays(30));
// Now look at the past, before the bundle started
@@ -96,7 +96,7 @@ public class TestPlanAligner extends SubscriptionTestSuiteNoDB {
// Verify the next phase via the other API
try {
- planAligner.getNextTimedPhase(defaultSubscriptionBase, effectiveDateInThePast, effectiveDateInThePast, internalCallContext);
+ planAligner.getNextTimedPhase(defaultSubscriptionBase, effectiveDateInThePast, internalCallContext);
Assert.fail("Can't use getNextTimedPhase(): the effective date is before the initial plan");
} catch (SubscriptionBaseError e) {
Assert.assertTrue(true);
@@ -130,7 +130,7 @@ public class TestPlanAligner extends SubscriptionTestSuiteNoDB {
Assert.assertEquals(phases[1].getStartPhase(), defaultSubscriptionBase.getStartDate().plusMonths(1));
// Verify the next phase via the other API
- final TimedPhase nextTimePhase = planAligner.getNextTimedPhase(defaultSubscriptionBase, effectiveDate, effectiveDate, internalCallContext);
+ final TimedPhase nextTimePhase = planAligner.getNextTimedPhase(defaultSubscriptionBase, effectiveDate, internalCallContext);
Assert.assertEquals(nextTimePhase.getStartPhase(), defaultSubscriptionBase.getStartDate().plusMonths(1));
// Now look at the past, before the subscription started
@@ -141,7 +141,7 @@ public class TestPlanAligner extends SubscriptionTestSuiteNoDB {
// Verify the next phase via the other API
try {
- planAligner.getNextTimedPhase(defaultSubscriptionBase, effectiveDateInThePast, effectiveDateInThePast, internalCallContext);
+ planAligner.getNextTimedPhase(defaultSubscriptionBase, effectiveDateInThePast, internalCallContext);
Assert.fail("Can't use getNextTimedPhase(): the effective date is before the initial plan");
} catch (SubscriptionBaseError e) {
Assert.assertTrue(true);
@@ -232,7 +232,7 @@ public class TestPlanAligner extends SubscriptionTestSuiteNoDB {
// The date is used for different catalog versions - we don't care here
final Plan newPlan = catalogService.getFullCatalog(internalCallContext).findPlan(newProductName, clock.getUTCNow());
- return planAligner.getNextTimedPhaseOnChange(defaultSubscriptionBase, newPlan, priceList, effectiveChangeDate, effectiveChangeDate, internalCallContext);
+ return planAligner.getNextTimedPhaseOnChange(defaultSubscriptionBase, newPlan, priceList, effectiveChangeDate, internalCallContext);
}
private TimedPhase[] getTimedPhasesOnCreate(final String productName,
@@ -244,7 +244,7 @@ public class TestPlanAligner extends SubscriptionTestSuiteNoDB {
// Same here for the requested date
final TimedPhase[] phases = planAligner.getCurrentAndNextTimedPhaseOnCreate(defaultSubscriptionBase.getAlignStartDate(), defaultSubscriptionBase.getBundleStartDate(),
- plan, initialPhase, priceList, clock.getUTCNow(), effectiveDate, internalCallContext);
+ plan, initialPhase, priceList, effectiveDate, internalCallContext);
Assert.assertEquals(phases.length, 2);
return phases;