Search in sources :

Example 1 with BCDEventBuilder

use of org.killbill.billing.subscription.events.bcd.BCDEventBuilder 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)

Example 2 with BCDEventBuilder

use of org.killbill.billing.subscription.events.bcd.BCDEventBuilder in project killbill by killbill.

the class SubscriptionEventModelDao method toSubscriptionEvent.

public static SubscriptionBaseEvent toSubscriptionEvent(final SubscriptionEventModelDao src) {
    if (src == null) {
        return null;
    }
    final EventBaseBuilder<?> base;
    if (src.getEventType() == EventType.PHASE) {
        base = new PhaseEventBuilder();
    } else if (src.getEventType() == EventType.BCD_UPDATE) {
        base = new BCDEventBuilder();
    } else {
        base = new ApiEventBuilder();
    }
    base.setTotalOrdering(src.getTotalOrdering()).setUuid(src.getId()).setSubscriptionId(src.getSubscriptionId()).setCreatedDate(src.getCreatedDate()).setUpdatedDate(src.getUpdatedDate()).setEffectiveDate(src.getEffectiveDate()).setActive(src.isActive());
    SubscriptionBaseEvent result;
    if (src.getEventType() == EventType.PHASE) {
        result = (new PhaseEventBuilder(base).setPhaseName(src.getPhaseName())).build();
    } else if (src.getEventType() == EventType.API_USER) {
        final ApiEventBuilder builder = new ApiEventBuilder(base).setEventPlan(src.getPlanName()).setEventPlanPhase(src.getPhaseName()).setEventPriceList(src.getPriceListName()).setApiEventType(src.getUserType()).setApiEventType(src.getUserType()).setFromDisk(true);
        result = builder.build();
    } else if (src.getEventType() == EventType.BCD_UPDATE) {
        result = (new BCDEventBuilder(base).setBillCycleDayLocal(src.getBillingCycleDayLocal())).build();
    } else {
        throw new SubscriptionBaseError(String.format("Can't figure out event %s", src.getEventType()));
    }
    return result;
}
Also used : ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) SubscriptionBaseError(org.killbill.billing.subscription.exceptions.SubscriptionBaseError) BCDEventBuilder(org.killbill.billing.subscription.events.bcd.BCDEventBuilder) PhaseEventBuilder(org.killbill.billing.subscription.events.phase.PhaseEventBuilder) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent)

Aggregations

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