Search in sources :

Example 1 with EventBaseBuilder

use of org.killbill.billing.subscription.events.EventBaseBuilder in project killbill by killbill.

the class DefaultSubscriptionDao method mergeDryRunEvents.

private void mergeDryRunEvents(final UUID subscriptionId, final List<SubscriptionBaseEvent> events, @Nullable final Collection<SubscriptionBaseEvent> dryRunEvents) {
    if (dryRunEvents == null || dryRunEvents.isEmpty()) {
        return;
    }
    for (final SubscriptionBaseEvent curDryRun : dryRunEvents) {
        if (curDryRun.getSubscriptionId() != null && curDryRun.getSubscriptionId().equals(subscriptionId)) {
            //boolean inserted = false;
            final Iterator<SubscriptionBaseEvent> it = events.iterator();
            while (it.hasNext()) {
                final SubscriptionBaseEvent event = it.next();
                if (event.getEffectiveDate().isAfter(curDryRun.getEffectiveDate())) {
                    it.remove();
                }
            }
            // Set total ordering value of the fake dryRun event to make sure billing events are correctly ordered
            final SubscriptionBaseEvent curAdjustedDryRun;
            if (!events.isEmpty()) {
                final EventBaseBuilder eventBuilder;
                switch(curDryRun.getType()) {
                    case PHASE:
                        eventBuilder = new PhaseEventBuilder((PhaseEvent) curDryRun);
                        break;
                    case BCD_UPDATE:
                        eventBuilder = new BCDEventBuilder((BCDEvent) curDryRun);
                        break;
                    case API_USER:
                    default:
                        eventBuilder = new ApiEventBuilder((ApiEvent) curDryRun);
                        break;
                }
                eventBuilder.setTotalOrdering(events.get(events.size() - 1).getTotalOrdering() + 1);
                curAdjustedDryRun = eventBuilder.build();
            } else {
                curAdjustedDryRun = curDryRun;
            }
            events.add(curAdjustedDryRun);
        }
    }
}
Also used : PhaseEvent(org.killbill.billing.subscription.events.phase.PhaseEvent) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) ApiEvent(org.killbill.billing.subscription.events.user.ApiEvent) BCDEventBuilder(org.killbill.billing.subscription.events.bcd.BCDEventBuilder) EventBaseBuilder(org.killbill.billing.subscription.events.EventBaseBuilder) BCDEvent(org.killbill.billing.subscription.events.bcd.BCDEvent) PhaseEventBuilder(org.killbill.billing.subscription.events.phase.PhaseEventBuilder) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent)

Aggregations

EventBaseBuilder (org.killbill.billing.subscription.events.EventBaseBuilder)1 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)1 BCDEvent (org.killbill.billing.subscription.events.bcd.BCDEvent)1 BCDEventBuilder (org.killbill.billing.subscription.events.bcd.BCDEventBuilder)1 PhaseEvent (org.killbill.billing.subscription.events.phase.PhaseEvent)1 PhaseEventBuilder (org.killbill.billing.subscription.events.phase.PhaseEventBuilder)1 ApiEvent (org.killbill.billing.subscription.events.user.ApiEvent)1 ApiEventBuilder (org.killbill.billing.subscription.events.user.ApiEventBuilder)1