use of org.killbill.bus.api.PersistentBus.EventBusException 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.bus.api.PersistentBus.EventBusException in project killbill by killbill.
the class PaymentEnteringStateCallback method enteringState.
@Override
public void enteringState(final State newState, final Operation.OperationCallback operationCallback, final OperationResult operationResult, final LeavingStateCallback leavingStateCallback) {
logger.debug("Entering state {} with result {}", newState.getName(), operationResult);
// If the transaction was not created -- for instance we had an exception in leavingState callback then we bail; if not, then update state:
if (paymentStateContext.getPaymentTransactionModelDao() != null && paymentStateContext.getPaymentTransactionModelDao().getId() != null) {
final PaymentTransactionInfoPlugin paymentInfoPlugin = paymentStateContext.getPaymentTransactionInfoPlugin();
final TransactionStatus transactionStatus = PaymentTransactionInfoPluginConverter.toTransactionStatus(paymentInfoPlugin);
// The bus event will be posted from the transaction
daoHelper.processPaymentInfoPlugin(transactionStatus, paymentInfoPlugin, newState.getName());
} else if (!paymentStateContext.isApiPayment()) {
//
// If there is NO transaction to update (because payment transaction did not occur), then there is something wrong happening (maybe a missing defaultPaymentMethodId, ...)
// so, if the call does NOT originates from api then we still want to send a bus event so the system can react to it if needed.
//
final BusInternalEvent event = new DefaultPaymentErrorEvent(paymentStateContext.getAccount().getId(), null, null, paymentStateContext.getAmount(), paymentStateContext.getCurrency(), null, paymentStateContext.getTransactionType(), null, "Early abortion of payment transaction", paymentStateContext.getInternalCallContext().getAccountRecordId(), paymentStateContext.getInternalCallContext().getTenantRecordId(), paymentStateContext.getInternalCallContext().getUserToken());
try {
daoHelper.getEventBus().post(event);
} catch (EventBusException e) {
logger.warn("Failed to post event {}", event, e);
}
}
}
use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.
the class MockAccountDao method update.
@Override
public void update(final AccountModelDao account, final InternalCallContext context) {
super.update(account, context);
final AccountModelDao currentAccount = getById(account.getId(), context);
final Long accountRecordId = getRecordId(account.getId(), context);
final long tenantRecordId = context == null ? InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID : context.getTenantRecordId();
final AccountChangeInternalEvent changeEvent = new DefaultAccountChangeEvent(account.getId(), currentAccount, account, accountRecordId, tenantRecordId, UUID.randomUUID(), clock.getUTCNow());
if (changeEvent.hasChanges()) {
try {
eventBus.post(changeEvent);
} catch (final EventBusException ex) {
Assert.fail(ex.toString());
}
}
}
use of org.killbill.bus.api.PersistentBus.EventBusException in project killbill by killbill.
the class DefaultInvoiceDao method notifyBusOfInvoiceCreation.
private void notifyBusOfInvoiceCreation(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InvoiceModelDao invoice, final InternalCallContext context) {
try {
final BigDecimal balance = InvoiceModelDaoHelper.getBalance(invoice);
final DefaultInvoiceCreationEvent event = new DefaultInvoiceCreationEvent(invoice.getId(), invoice.getAccountId(), balance, invoice.getCurrency(), context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken());
eventBus.postFromTransaction(event, entitySqlDaoWrapperFactory.getHandle().getConnection());
} catch (final EventBusException e) {
log.error(String.format("Failed to post invoice creation event %s for account %s", invoice.getAccountId()), e);
}
}
use of org.killbill.bus.api.PersistentBus.EventBusException 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);
}
}
Aggregations