Search in sources :

Example 1 with EntitlementNotificationKey

use of org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey in project killbill by killbill.

the class DefaultEntitlement method computeAddOnBlockingStates.

public Collection<BlockingState> computeAddOnBlockingStates(final DateTime effectiveDate, final Collection<NotificationEvent> notificationEvents, final TenantContext context, final InternalCallContext internalCallContext) throws EntitlementApiException {
    // Optimization - bail early
    if (!ProductCategory.BASE.equals(getSubscriptionBase().getCategory())) {
        // Only base subscriptions have add-ons
        return ImmutableList.<BlockingState>of();
    }
    // Get the latest state from disk (we just got cancelled or changed plan)
    refresh(context);
    // If cancellation/change occurs in the future, do nothing for now but add a notification entry.
    // This is to distinguish whether a future cancellation was requested by the user, or was a side effect
    // (e.g. base plan cancellation): future entitlement cancellations for add-ons on disk always reflect
    // an explicit cancellation. This trick lets us determine what to do when un-cancelling.
    // This mirror the behavior in subscription base (see DefaultSubscriptionBaseApiService).
    final DateTime now = clock.getUTCNow();
    if (effectiveDate.compareTo(now) > 0) {
        // Note that usually we record the notification from the DAO. We cannot do it here because not all calls
        // go through the DAO (e.g. change)
        final boolean isBaseEntitlementCancelled = eventsStream.isEntitlementCancelled();
        final NotificationEvent notificationEvent = new EntitlementNotificationKey(getId(), getBundleId(), isBaseEntitlementCancelled ? EntitlementNotificationKeyAction.CANCEL : EntitlementNotificationKeyAction.CHANGE, effectiveDate);
        notificationEvents.add(notificationEvent);
        return ImmutableList.<BlockingState>of();
    }
    return eventsStream.computeAddonsBlockingStatesForNextSubscriptionBaseEvent(effectiveDate);
}
Also used : EntitlementNotificationKey(org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) DefaultBlockingState(org.killbill.billing.junction.DefaultBlockingState) DateTime(org.joda.time.DateTime)

Example 2 with EntitlementNotificationKey

use of org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey in project killbill by killbill.

the class DefaultEntitlementService method initialize.

@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE)
public void initialize() {
    try {
        final NotificationQueueHandler queueHandler = new NotificationQueueHandler() {

            @Override
            public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) {
                final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "EntitlementQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken);
                if (inputKey instanceof EntitlementNotificationKey) {
                    final CallContext callContext = internalCallContextFactory.createCallContext(internalCallContext);
                    processEntitlementNotification((EntitlementNotificationKey) inputKey, internalCallContext, callContext);
                } else if (inputKey instanceof BlockingTransitionNotificationKey) {
                    processBlockingNotification((BlockingTransitionNotificationKey) inputKey, internalCallContext);
                } else if (inputKey != null) {
                    log.error("Entitlement service received an unexpected event className='{}", inputKey.getClass());
                } else {
                    log.error("Entitlement service received an unexpected null event");
                }
            }
        };
        entitlementEventQueue = notificationQueueService.createNotificationQueue(ENTITLEMENT_SERVICE_NAME, NOTIFICATION_QUEUE_NAME, queueHandler);
    } catch (final NotificationQueueAlreadyExists e) {
        throw new RuntimeException(e);
    }
}
Also used : EntitlementNotificationKey(org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey) BlockingTransitionNotificationKey(org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) NotificationQueueAlreadyExists(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) DateTime(org.joda.time.DateTime) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Aggregations

DateTime (org.joda.time.DateTime)2 EntitlementNotificationKey (org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey)2 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)2 UUID (java.util.UUID)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 BlockingTransitionNotificationKey (org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey)1 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)1 LifecycleHandlerType (org.killbill.billing.platform.api.LifecycleHandlerType)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1 NotificationQueueAlreadyExists (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists)1 NotificationQueueHandler (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler)1