use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class DefaultOverdueConfigCache method initializeCacheLoaderArgument.
private CacheLoaderArgument initializeCacheLoaderArgument() {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
public OverdueConfig loadOverdueConfig(final String overdueConfigXML) throws OverdueApiException {
final InputStream overdueConfigStream = new ByteArrayInputStream(overdueConfigXML.getBytes());
try {
return XMLLoader.getObjectFromStream(overdueConfigStream, DefaultOverdueConfig.class);
} catch (final Exception e) {
throw new OverdueApiException(ErrorCode.OVERDUE_INVALID_FOR_TENANT, "Problem encountered loading overdue config ", e);
}
}
};
final Object[] args = new Object[1];
args[0] = loaderCallback;
final ObjectType irrelevant = null;
final InternalTenantContext notUsed = null;
return new CacheLoaderArgument(irrelevant, args, notUsed);
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class OverdueListener method insertBusEventIntoNotificationQueue.
private void insertBusEventIntoNotificationQueue(final UUID accountId, final OverdueAsyncBusNotificationAction action, final InternalCallContext callContext) {
final boolean shouldInsertNotification = shouldInsertNotification(callContext);
if (!shouldInsertNotification) {
log.debug("OverdueListener: shouldInsertNotification=false");
return;
}
OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(accountId, action);
asyncPoster.insertOverdueNotification(accountId, callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, callContext);
try {
// Refresh parent
final Account account = accountApi.getAccountById(accountId, callContext);
if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) {
final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext);
final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(parentAccountInternalTenantContext.getAccountRecordId(), callContext);
notificationKey = new OverdueAsyncBusNotificationKey(account.getParentAccountId(), action);
asyncPoster.insertOverdueNotification(account.getParentAccountId(), callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, parentAccountContext);
}
// Refresh children
final List<Account> childrenAccounts = accountApi.getChildrenAccounts(accountId, callContext);
if (childrenAccounts != null) {
for (final Account childAccount : childrenAccounts) {
if (childAccount.isPaymentDelegatedToParent()) {
final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(childAccount.getId(), callContext);
final InternalCallContext accountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), callContext);
notificationKey = new OverdueAsyncBusNotificationKey(childAccount.getId(), action);
asyncPoster.insertOverdueNotification(childAccount.getId(), callContext.getCreatedDate(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, accountContext);
}
}
}
} catch (final Exception e) {
log.error("Error loading child accounts from accountId='{}'", accountId);
}
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class OverdueWrapper method billingState.
public BillingState billingState(final InternalCallContext context) throws OverdueException {
if ((overdueable.getParentAccountId() != null) && (overdueable.isPaymentDelegatedToParent())) {
// calculate billing state from parent account
final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(overdueable.getParentAccountId(), context);
final InternalCallContext parentAccountContext = internalCallContextFactory.createInternalCallContext(internalTenantContext.getAccountRecordId(), context);
return billingStateCalcuator.calculateBillingState(overdueable, parentAccountContext);
}
return billingStateCalcuator.calculateBillingState(overdueable, context);
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class DefaultPaymentDao method getByTransactionStatusAcrossTenants.
@Override
public Pagination<PaymentTransactionModelDao> getByTransactionStatusAcrossTenants(final Iterable<TransactionStatus> transactionStatuses, final DateTime createdBeforeDate, final DateTime createdAfterDate, final Long offset, final Long limit) {
final Collection<String> allTransactionStatus = ImmutableList.copyOf(Iterables.transform(transactionStatuses, Functions.toStringFunction()));
final Date createdBefore = createdBeforeDate.toDate();
final Date createdAfter = createdAfterDate.toDate();
return paginationHelper.getPagination(TransactionSqlDao.class, new PaginationIteratorBuilder<PaymentTransactionModelDao, PaymentTransaction, TransactionSqlDao>() {
@Override
public Long getCount(final TransactionSqlDao sqlDao, final InternalTenantContext context) {
return sqlDao.getCountByTransactionStatusPriorDateAcrossTenants(allTransactionStatus, createdBefore, createdAfter);
}
@Override
public Iterator<PaymentTransactionModelDao> build(final TransactionSqlDao sqlDao, final Long offset, final Long limit, final Ordering ordering, final InternalTenantContext context) {
return sqlDao.getByTransactionStatusPriorDateAcrossTenants(allTransactionStatus, createdBefore, createdAfter, offset, limit, ordering.toString());
}
}, offset, limit, null);
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class InternalCallContextFactory method createInternalTenantContext.
/**
* Create an internal tenant callcontext
*
* @param tenantRecordId tenant_record_id (cannot be null)
* @param accountRecordId account_record_id (cannot be null for INSERT operations)
* @return internal tenant callcontext
*/
public InternalTenantContext createInternalTenantContext(final Long tenantRecordId, @Nullable final Long accountRecordId) {
populateMDCContext(null, accountRecordId, tenantRecordId);
if (accountRecordId == null) {
return new InternalTenantContext(tenantRecordId);
} else {
final ImmutableAccountData immutableAccountData = getImmutableAccountData(accountRecordId, tenantRecordId);
final DateTimeZone fixedOffsetTimeZone = immutableAccountData.getFixedOffsetTimeZone();
final DateTime referenceTime = immutableAccountData.getReferenceTime();
return new InternalTenantContext(tenantRecordId, accountRecordId, fixedOffsetTimeZone, referenceTime);
}
}
Aggregations