Source:
<code>public List<SubscriptionBase> createBaseSubscriptionsWithAddOns(final UUID accountId, final Iterable<BaseEntitlementWithAddOnsSpecifier> baseEntitlementWithAddOnsSpecifier, final InternalCallContext context) throws SubscriptionBaseApiException { try { final Catalog catalog = catalogService.getFullCatalog(true, true, context); final CallContext callContext = internalCallContextFactory.createCallContext(context); final List<SubscriptionAndAddOnsSpecifier> subscriptionAndAddOns = new ArrayList<SubscriptionAndAddOnsSpecifier>(); for (BaseEntitlementWithAddOnsSpecifier entitlementWithAddOnsSpecifier : baseEntitlementWithAddOnsSpecifier) { final DateTime now = clock.getUTCNow(); final DateTime effectiveDate = (entitlementWithAddOnsSpecifier.getEntitlementEffectiveDate() != null) ? DefaultClock.truncateMs(entitlementWithAddOnsSpecifier.getEntitlementEffectiveDate().toDateTimeAtCurrentTime()) : now; final SubscriptionBaseBundle bundle = createBundleForAccount(accountId, entitlementWithAddOnsSpecifier.getExternalKey(), context); <START> final List<SubscriptionSpecifier> subscriptions = verifyAndBuildSubscriptionSpecifiers(bundle.getId(), <END> entitlementWithAddOnsSpecifier.getEntitlementSpecifier(), entitlementWithAddOnsSpecifier.isMigrated(), context, now, effectiveDate, catalog, callContext); SubscriptionAndAddOnsSpecifier subscriptionAndAddOnsSpecifier = new SubscriptionAndAddOnsSpecifier(); subscriptionAndAddOnsSpecifier.setSubscriptionSpecifiers(subscriptions); subscriptionAndAddOns.add(subscriptionAndAddOnsSpecifier); } final List<DefaultSubscriptionBase> result = apiService.createPlansWithAddOns(accountId, subscriptionAndAddOns, callContext); return ImmutableList.copyOf(Iterables.transform(result, new Function<DefaultSubscriptionBase, SubscriptionBase>() { @Override public SubscriptionBase apply(final DefaultSubscriptionBase input) { return (SubscriptionBase) input; } })); } catch (CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }</code><technical_language>method verifyAndBuildSubscriptionSpecifiers do for need (and is costly): creating new bundles new subscriptions is need fetch state new bundles/subscriptions (hence call getSubscriptionsForBundle in verifyAndBuildSubscriptionSpecifiers is required). ADD_ON check for SUB_CREATE_AO_MAX_PLAN_ALLOWED_BY_BUNDLE done simply arguments for BaseEntitlementWithAddOnsSpecifier. cut verifyAndBuildSubscriptionSpecifiers in pieces call piece final check</technical_language>

Target:
public List<SubscriptionBaseWithAddOns> createBaseSubscriptionsWithAddOns(final UUID accountId, final Iterable<BaseEntitlementWithAddOnsSpecifier> baseEntitlementWithAddOnsSpecifier, final InternalCallContext context) throws SubscriptionBaseApiException { try { final Catalog catalog = catalogService.getFullCatalog(true, true, context); final CallContext callContext = internalCallContextFactory.createCallContext(context); final DateTime now = clock.getUTCNow(); final List<SubscriptionAndAddOnsSpecifier> subscriptionAndAddOns = new ArrayList<SubscriptionAndAddOnsSpecifier>(); for (BaseEntitlementWithAddOnsSpecifier entitlementWithAddOnsSpecifier : baseEntitlementWithAddOnsSpecifier) { final DateTime effectiveDate = (entitlementWithAddOnsSpecifier.getBillingEffectiveDate() != null) ? DefaultClock.truncateMs(entitlementWithAddOnsSpecifier.getBillingEffectiveDate().toDateTimeAtStartOfDay()) : now; final SubscriptionBaseBundle bundle = createBundleForAccount(accountId, entitlementWithAddOnsSpecifier.getExternalKey(), context); SubscriptionAndAddOnsSpecifier subscriptionAndAddOnsSpecifier = new SubscriptionAndAddOnsSpecifier( bundle.getId(), effectiveDate, verifyAndBuildSubscriptionSpecifiers(bundle.getId(), entitlementWithAddOnsSpecifier.getEntitlementSpecifier(), entitlementWithAddOnsSpecifier.isMigrated(), context, now, effectiveDate, catalog, callContext) ); subscriptionAndAddOns.add(subscriptionAndAddOnsSpecifier); } final List<DefaultSubscriptionBaseWithAddOns> defaultSubscriptionBaseWithAddOnsList = apiService.createPlansWithAddOns(accountId, subscriptionAndAddOns, callContext); List<SubscriptionBaseWithAddOns> subscriptionBaseWithAddOnsList = new ArrayList<SubscriptionBaseWithAddOns>(); for (final DefaultSubscriptionBaseWithAddOns cur : defaultSubscriptionBaseWithAddOnsList) { SubscriptionBaseWithAddOns subscriptionBaseWithAddOns = new SubscriptionBaseWithAddOns() { @Override public UUID getBundleId() { return cur.getBundleId(); } @Override public List<SubscriptionBase> getSubscriptionBaseList() { return cur.getSubscriptionBaseList(); } @Override public DateTime getEffectiveDate() { return cur.getEffectiveDate(); } }; subscriptionBaseWithAddOnsList.add(subscriptionBaseWithAddOns); } return subscriptionBaseWithAddOnsList; } catch (CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }