Search in sources :

Example 1 with SubscriptionBaseWithAddOns

use of org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns in project killbill by killbill.

the class DefaultEntitlementApi method createBaseEntitlementsWithAddOns.

@Override
public List<Entitlement> createBaseEntitlementsWithAddOns(final UUID accountId, final Iterable<BaseEntitlementWithAddOnsSpecifier> baseEntitlementWithAddOnsSpecifiers, final Iterable<PluginProperty> properties, final CallContext callContext) throws EntitlementApiException {
    logCreateEntitlementsWithAOs(log, baseEntitlementWithAddOnsSpecifiers);
    final EntitlementContext pluginContext = new DefaultEntitlementContext(OperationType.CREATE_SHOPPING_CART_SUBSCRIPTIONS, accountId, null, baseEntitlementWithAddOnsSpecifiers, null, properties, callContext);
    final WithEntitlementPlugin<List<Entitlement>> createBaseEntitlementsWithAddOns = new WithEntitlementPlugin<List<Entitlement>>() {

        @Override
        public List<Entitlement> doCall(final EntitlementApi entitlementApi, final EntitlementContext updatedPluginContext) throws EntitlementApiException {
            final InternalCallContext contextWithValidAccountRecordId = internalCallContextFactory.createInternalCallContext(accountId, callContext);
            try {
                // First verify bundleKey
                for (final BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifier : baseEntitlementWithAddOnsSpecifiers) {
                    if (entitlementUtils.getFirstActiveSubscriptionIdForKeyOrNull(baseEntitlementWithAddOnsSpecifier.getExternalKey(), contextWithValidAccountRecordId) != null) {
                        throw new EntitlementApiException(new SubscriptionBaseApiException(ErrorCode.SUB_CREATE_ACTIVE_BUNDLE_KEY_EXISTS, baseEntitlementWithAddOnsSpecifier.getExternalKey()));
                    }
                }
                final List<SubscriptionBaseWithAddOns> subscriptionsWithAddOns = subscriptionBaseInternalApi.createBaseSubscriptionsWithAddOns(accountId, baseEntitlementWithAddOnsSpecifiers, contextWithValidAccountRecordId);
                final Map<BlockingState, UUID> blockingStateMap = new HashMap<BlockingState, UUID>();
                int i = 0;
                for (final Iterator<BaseEntitlementWithAddOnsSpecifier> it = baseEntitlementWithAddOnsSpecifiers.iterator(); it.hasNext(); i++) {
                    final BaseEntitlementWithAddOnsSpecifier baseEntitlementWithAddOnsSpecifier = it.next();
                    for (final SubscriptionBase subscriptionBase : subscriptionsWithAddOns.get(i).getSubscriptionBaseList()) {
                        final BlockingState blockingState = new DefaultBlockingState(subscriptionBase.getId(), BlockingStateType.SUBSCRIPTION, DefaultEntitlementApi.ENT_STATE_START, EntitlementService.ENTITLEMENT_SERVICE_NAME, false, false, false, dateHelper.fromLocalDateAndReferenceTime(baseEntitlementWithAddOnsSpecifier.getEntitlementEffectiveDate(), contextWithValidAccountRecordId));
                        blockingStateMap.put(blockingState, subscriptionsWithAddOns.get(i).getBundleId());
                    }
                }
                entitlementUtils.setBlockingStateAndPostBlockingTransitionEvent(blockingStateMap, contextWithValidAccountRecordId);
                return buildEntitlementList(accountId, subscriptionsWithAddOns, callContext);
            } catch (final SubscriptionBaseApiException e) {
                throw new EntitlementApiException(e);
            }
        }
    };
    return pluginExecution.executeWithPlugin(createBaseEntitlementsWithAddOns, pluginContext);
}
Also used : SubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns) WithEntitlementPlugin(org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin) HashMap(java.util.HashMap) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) EntitlementLoggingHelper.logPauseResumeEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logPauseResumeEntitlement) EntitlementLoggingHelper.logTransferEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logTransferEntitlement) EntitlementLoggingHelper.logCreateEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logCreateEntitlement) UUID(java.util.UUID) EntitlementContext(org.killbill.billing.entitlement.plugin.api.EntitlementContext) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 2 with SubscriptionBaseWithAddOns

use of org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns in project killbill by killbill.

the class DefaultEntitlementApi method buildEntitlementList.

private List<Entitlement> buildEntitlementList(final UUID accountId, final Iterable<SubscriptionBaseWithAddOns> subscriptionsWithAddOns, final CallContext callContext) throws EntitlementApiException {
    final List<Entitlement> result = new ArrayList<Entitlement>();
    for (final SubscriptionBaseWithAddOns subscriptionWithAddOns : subscriptionsWithAddOns) {
        for (final SubscriptionBase subscriptionBase : subscriptionWithAddOns.getSubscriptionBaseList()) {
            final Entitlement entitlement = new DefaultEntitlement(accountId, subscriptionBase.getId(), eventsStreamBuilder, entitlementApi, pluginExecution, blockingStateDao, subscriptionBaseInternalApi, checker, notificationQueueService, entitlementUtils, dateHelper, clock, securityApi, internalCallContextFactory, callContext);
            result.add(entitlement);
        }
    }
    return result;
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) SubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns) ArrayList(java.util.ArrayList) EntitlementLoggingHelper.logPauseResumeEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logPauseResumeEntitlement) EntitlementLoggingHelper.logTransferEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logTransferEntitlement) EntitlementLoggingHelper.logCreateEntitlement(org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logCreateEntitlement)

Example 3 with SubscriptionBaseWithAddOns

use of org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns in project killbill by killbill.

the class MockSubscriptionDaoMemory method createSubscriptionsWithAddOns.

@Override
public void createSubscriptionsWithAddOns(final List<SubscriptionBaseWithAddOns> subscriptions, final Map<UUID, List<SubscriptionBaseEvent>> initialEventsMap, final InternalCallContext context) {
    synchronized (events) {
        for (final SubscriptionBaseWithAddOns subscription : subscriptions) {
            for (final SubscriptionBase subscriptionBase : subscription.getSubscriptionBaseList()) {
                final List<SubscriptionBaseEvent> initialEvents = initialEventsMap.get(subscriptionBase.getId());
                events.addAll(initialEvents);
                for (final SubscriptionBaseEvent cur : initialEvents) {
                    recordFutureNotificationFromTransaction(null, cur.getEffectiveDate(), new SubscriptionNotificationKey(cur.getId()), context);
                }
                final SubscriptionBase updatedSubscription = buildSubscription((DefaultSubscriptionBase) subscriptionBase, context);
                this.subscriptions.add(updatedSubscription);
                mockNonEntityDao.addTenantRecordIdMapping(updatedSubscription.getId(), context);
            }
        }
    }
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) SubscriptionNotificationKey(org.killbill.billing.subscription.engine.core.SubscriptionNotificationKey) DefaultSubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseWithAddOns) SubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent)

Example 4 with SubscriptionBaseWithAddOns

use of org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns in project killbill by killbill.

the class DefaultSubscriptionBaseApiService method createPlansWithAddOns.

@Override
public List<SubscriptionBaseWithAddOns> createPlansWithAddOns(final UUID accountId, final Iterable<SubscriptionAndAddOnsSpecifier> subscriptionsAndAddOns, final CallContext context) throws SubscriptionBaseApiException {
    final Map<UUID, List<SubscriptionBaseEvent>> eventsMap = new HashMap<UUID, List<SubscriptionBaseEvent>>();
    final Collection<List<SubscriptionBase>> subscriptionBaseAndAddOnsList = new ArrayList<List<SubscriptionBase>>();
    final List<SubscriptionBaseWithAddOns> allSubscriptions = new ArrayList<SubscriptionBaseWithAddOns>();
    for (final SubscriptionAndAddOnsSpecifier subscriptionAndAddOns : subscriptionsAndAddOns) {
        final List<SubscriptionBase> subscriptionBaseList = new ArrayList<SubscriptionBase>();
        createEvents(subscriptionAndAddOns.getSubscriptionSpecifiers(), context, eventsMap, subscriptionBaseList);
        subscriptionBaseAndAddOnsList.add(subscriptionBaseList);
        final SubscriptionBaseWithAddOns subscriptionBaseWithAddOns = new DefaultSubscriptionBaseWithAddOns(subscriptionAndAddOns.getBundleId(), subscriptionBaseList, subscriptionAndAddOns.getEffectiveDate());
        allSubscriptions.add(subscriptionBaseWithAddOns);
    }
    final InternalCallContext internalCallContext = createCallContextFromAccountId(accountId, context);
    dao.createSubscriptionsWithAddOns(allSubscriptions, eventsMap, internalCallContext);
    for (final List<SubscriptionBase> subscriptions : subscriptionBaseAndAddOnsList) {
        final SubscriptionBase baseSubscription = findBaseSubscription(subscriptions);
        rebuildTransitions(internalCallContext, subscriptions, baseSubscription);
    }
    return allSubscriptions;
}
Also used : SubscriptionBaseWithAddOns(org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) UUID(java.util.UUID) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Aggregations

SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)4 SubscriptionBaseWithAddOns (org.killbill.billing.subscription.api.SubscriptionBaseWithAddOns)4 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 UUID (java.util.UUID)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)2 EntitlementLoggingHelper.logCreateEntitlement (org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logCreateEntitlement)2 EntitlementLoggingHelper.logPauseResumeEntitlement (org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logPauseResumeEntitlement)2 EntitlementLoggingHelper.logTransferEntitlement (org.killbill.billing.entitlement.logging.EntitlementLoggingHelper.logTransferEntitlement)2 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)2 LinkedList (java.util.LinkedList)1 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)1 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)1 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)1 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)1 DefaultSubscriptionBaseWithAddOns (org.killbill.billing.subscription.api.user.DefaultSubscriptionBaseWithAddOns)1 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)1