use of org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData in project killbill by killbill.
the class DefaultSubscriptionBaseService method processEventReady.
@Override
public void processEventReady(final SubscriptionBaseEvent event, final int seqId, final InternalCallContext context) {
if (!event.isActive()) {
return;
}
try {
final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) dao.getSubscriptionFromId(event.getSubscriptionId(), context);
if (subscription == null) {
log.warn("Error retrieving subscriptionId='{}'", event.getSubscriptionId());
return;
}
final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(event, seqId);
if (transition == null) {
log.warn("Skipping event ='{}', no matching transition was built", event.getType());
return;
}
boolean eventSent = false;
if (event.getType() == EventType.PHASE) {
eventSent = onPhaseEvent(subscription, event, context);
} else if (event.getType() == EventType.API_USER && subscription.getCategory() == ProductCategory.BASE) {
final CallContext callContext = internalCallContextFactory.createCallContext(context);
eventSent = onBasePlanEvent(subscription, event, callContext);
} else if (event.getType() == EventType.BCD_UPDATE) {
eventSent = false;
}
if (!eventSent) {
// Methods above invoking the DAO will send this event directly from the transaction
final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
eventBus.post(busEvent);
}
} catch (final EventBusException e) {
log.warn("Failed to post event {}", event, e);
} catch (final CatalogApiException e) {
log.warn("Failed to post event {}", event, e);
}
}
use of org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData in project killbill by killbill.
the class TestDefaultSubscriptionBundleTimeline method createTransition.
private SubscriptionBaseTransition createTransition(final UUID entitlementId, final EventType eventType, final ApiEventType apiEventType, final DateTime effectiveDate, final DateTime createdDate, final String prevPhaseName, final String nextPhaseName) throws CatalogApiException {
final PlanPhase prevPhase;
final Plan prevPlan;
final Product prevProduct;
final PriceList prevPriceList;
if (prevPhaseName == null) {
prevPhase = null;
prevPlan = null;
prevProduct = null;
prevPriceList = null;
} else {
prevPhase = Mockito.mock(PlanPhase.class);
Mockito.when(prevPhase.getName()).thenReturn(prevPhaseName);
prevProduct = Mockito.mock(Product.class);
Mockito.when(prevProduct.getName()).thenReturn("product");
prevPlan = Mockito.mock(Plan.class);
Mockito.when(prevPlan.getName()).thenReturn("plan");
Mockito.when(prevPlan.getProduct()).thenReturn(prevProduct);
prevPriceList = Mockito.mock(PriceList.class);
Mockito.when(prevPriceList.getName()).thenReturn("pricelist");
}
final PlanPhase nextPhase;
final Plan nextPlan;
final Product nextProduct;
final PriceList nextPriceList;
if (nextPhaseName == null) {
nextPhase = null;
nextPlan = null;
nextProduct = null;
nextPriceList = null;
} else {
nextPhase = Mockito.mock(PlanPhase.class);
Mockito.when(nextPhase.getName()).thenReturn(nextPhaseName);
nextProduct = Mockito.mock(Product.class);
Mockito.when(nextProduct.getName()).thenReturn("product");
nextPlan = Mockito.mock(Plan.class);
Mockito.when(nextPlan.getName()).thenReturn("plan");
Mockito.when(nextPlan.getProduct()).thenReturn(nextProduct);
nextPriceList = Mockito.mock(PriceList.class);
Mockito.when(nextPriceList.getName()).thenReturn("pricelist");
}
return new SubscriptionBaseTransitionData(UUID.randomUUID(), entitlementId, bundleId, bundleExternalKey, eventType, apiEventType, effectiveDate, null, null, null, prevPlan, prevPhase, prevPriceList, null, null, null, null, nextPlan, nextPhase, nextPriceList, null, 1L, createdDate, UUID.randomUUID(), true);
}
use of org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData in project killbill by killbill.
the class MockSubscriptionDaoMemory method notifyBusOfEffectiveImmediateChange.
private void notifyBusOfEffectiveImmediateChange(final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) {
try {
final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(immediateEvent, seqId);
final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
eventBus.post(busEvent);
} catch (final EventBusException e) {
log.warn("Failed to post effective event for subscription " + subscription.getId(), e);
}
}
use of org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData in project killbill by killbill.
the class DefaultSubscriptionDao method notifyBusOfEffectiveImmediateChange.
private void notifyBusOfEffectiveImmediateChange(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) {
try {
final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(immediateEvent, seqId);
if (transition != null) {
final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
eventBus.postFromTransaction(busEvent, entitySqlDaoWrapperFactory.getHandle().getConnection());
}
} catch (final EventBusException e) {
log.warn("Failed to post effective event for subscriptionId='{}'", subscription.getId(), e);
}
}
Aggregations