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);
}
}
}
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;
}
Aggregations