@Override
public Entitlement changePlan(final String productName, final BillingPeriod billingPeriod, final String priceList, final CallContext callContext) throws EntitlementApiException {
refresh(callContext);
if (!eventsStream.isEntitlementActive()) {
throw new EntitlementApiException(ErrorCode.SUB_CHANGE_NON_ACTIVE, getId(), getState());
}
final InternalCallContext context = internalCallContextFactory.createInternalCallContext(getAccountId(), callContext);
try {
checker.checkBlockedChange(getSubscriptionBase(), context);
} catch (BlockingApiException e) {
throw new EntitlementApiException(e, e.getCode(), e.getMessage());
}
final DateTime effectiveChangeDate;
try {
effectiveChangeDate = getSubscriptionBase().changePlan(productName, billingPeriod, priceList, callContext);
} catch (SubscriptionBaseApiException e) {
throw new EntitlementApiException(e);
}
blockAddOnsIfRequired(effectiveChangeDate, callContext, context);
return entitlementApi.getEntitlementForId(getId(), callContext);
}