use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class DefaultCatalogCache method initializeCacheLoaderArgument.
//
// Build the LoaderCallback that is required to build the catalog from the xml from a module that knows
// nothing about catalog.
//
// This is a contract between the TenantCatalogCacheLoader and the DefaultCatalogCache
private CacheLoaderArgument initializeCacheLoaderArgument(final boolean filterTemplateCatalog) {
final LoaderCallback loaderCallback = new LoaderCallback() {
@Override
public VersionedCatalog loadCatalog(final List<String> catalogXMLs, final Long tenantRecordId) throws CatalogApiException {
final VersionedCatalog versionedCatalog = loader.load(catalogXMLs, filterTemplateCatalog, tenantRecordId);
if (versionedCatalog != null) {
initializeCatalog(versionedCatalog);
}
return versionedCatalog;
}
};
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 DefaultInvoiceUserApi method getInvoiceItemsByParentInvoice.
@Override
public List<InvoiceItem> getInvoiceItemsByParentInvoice(final UUID parentInvoiceId, final TenantContext context) throws InvoiceApiException {
final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(parentInvoiceId, ObjectType.INVOICE, context);
final VersionedCatalog catalog = getCatalogSafelyForPrettyNames(internalTenantContext);
return ImmutableList.copyOf(Collections2.transform(dao.getInvoiceItemsByParentInvoice(parentInvoiceId, internalTenantContext), new Function<InvoiceItemModelDao, InvoiceItem>() {
@Override
public InvoiceItem apply(final InvoiceItemModelDao input) {
return InvoiceItemFactory.fromModelDaoWithCatalog(input, catalog);
}
}));
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class InvoiceDaoHelper method setParentInvoice.
private void setParentInvoice(final Iterable<InvoiceModelDao> childInvoices, final List<Tag> invoicesTags, final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final InternalTenantContext childContext) {
final Collection<String> childInvoiceIds = new HashSet<String>();
for (final InvoiceModelDao childInvoice : childInvoices) {
childInvoiceIds.add(childInvoice.getId().toString());
}
// DAO: retrieve the mappings between parent and child invoices
final InvoiceParentChildrenSqlDao invoiceParentChildrenSqlDao = entitySqlDaoWrapperFactory.become(InvoiceParentChildrenSqlDao.class);
final List<InvoiceParentChildModelDao> mappings = invoiceParentChildrenSqlDao.getParentChildMappingsByChildInvoiceIds(childInvoiceIds, childContext);
if (mappings.isEmpty()) {
return;
}
final Map<UUID, InvoiceParentChildModelDao> mappingPerChildInvoiceId = new HashMap<UUID, InvoiceParentChildModelDao>();
final Collection<String> parentInvoiceIdsAsStrings = new HashSet<String>();
for (final InvoiceParentChildModelDao mapping : mappings) {
mappingPerChildInvoiceId.put(mapping.getChildInvoiceId(), mapping);
parentInvoiceIdsAsStrings.add(mapping.getParentInvoiceId().toString());
}
// DAO: retrieve all parents invoices in bulk, for all child invoices
final InvoiceSqlDao invoiceSqlDao = entitySqlDaoWrapperFactory.become(InvoiceSqlDao.class);
final List<InvoiceModelDao> parentInvoices = invoiceSqlDao.getByIds(parentInvoiceIdsAsStrings, childContext);
// Group the parent invoices by (parent) account id (most likely, we only have one parent account group, except in re-parenting cases)
final Map<UUID, List<InvoiceModelDao>> parentInvoicesGroupedByParentAccountId = new HashMap<UUID, List<InvoiceModelDao>>();
// Create also a convenient mapping (needed below later)
final Map<UUID, InvoiceModelDao> parentInvoiceByParentInvoiceId = new HashMap<UUID, InvoiceModelDao>();
for (final InvoiceModelDao parentInvoice : parentInvoices) {
if (parentInvoicesGroupedByParentAccountId.get(parentInvoice.getAccountId()) == null) {
parentInvoicesGroupedByParentAccountId.put(parentInvoice.getAccountId(), new LinkedList<InvoiceModelDao>());
}
parentInvoicesGroupedByParentAccountId.get(parentInvoice.getAccountId()).add(parentInvoice);
parentInvoiceByParentInvoiceId.put(parentInvoice.getId(), parentInvoice);
}
// DAO: populate the parent invoices in bulk
for (final Entry<UUID, List<InvoiceModelDao>> entry : parentInvoicesGroupedByParentAccountId.entrySet()) {
final List<InvoiceModelDao> parentInvoicesForOneParentAccountId = entry.getValue();
final Long parentAccountRecordId = internalCallContextFactory.getRecordIdFromObject(entry.getKey(), ObjectType.ACCOUNT, internalCallContextFactory.createTenantContext(childContext));
final InternalTenantContext parentContext = internalCallContextFactory.createInternalTenantContext(childContext.getTenantRecordId(), parentAccountRecordId);
// Note the misnomer here, populateChildren simply populates the content of these invoices (unrelated to HA)
populateChildren(parentInvoicesForOneParentAccountId, invoicesTags, entitySqlDaoWrapperFactory, parentContext);
}
for (final InvoiceModelDao invoice : childInvoices) {
final InvoiceParentChildModelDao mapping = mappingPerChildInvoiceId.get(invoice.getId());
if (mapping == null) {
continue;
}
final InvoiceModelDao parentInvoice = parentInvoiceByParentInvoiceId.get(mapping.getParentInvoiceId());
if (parentInvoice != null) {
invoice.addParentInvoice(parentInvoice);
}
}
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class DefaultInvoiceUserApi method getInvoiceByPayment.
@Override
public Invoice getInvoiceByPayment(final UUID paymentId, final TenantContext context) throws InvoiceApiException {
final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(paymentId, ObjectType.PAYMENT, context);
final UUID invoiceId = dao.getInvoiceIdByPaymentId(paymentId, internalTenantContext);
if (invoiceId == null) {
throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, paymentId);
}
final InvoiceModelDao invoiceModelDao = dao.getById(invoiceId, internalTenantContext);
return new DefaultInvoice(invoiceModelDao, getCatalogSafelyForPrettyNames(internalTenantContext));
}
use of org.killbill.billing.callcontext.InternalTenantContext in project killbill by killbill.
the class DefaultInvoiceUserApi method getInvoicesByAccount.
@Override
public List<Invoice> getInvoicesByAccount(final UUID accountId, boolean includesMigrated, final boolean includeVoidedInvoices, final TenantContext context) {
final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContext(accountId, context);
final List<InvoiceModelDao> invoicesByAccount = includesMigrated ? dao.getAllInvoicesByAccount(includeVoidedInvoices, internalTenantContext) : dao.getInvoicesByAccount(includeVoidedInvoices, internalTenantContext);
return fromInvoiceModelDao(invoicesByAccount, getCatalogSafelyForPrettyNames(internalTenantContext));
}
Aggregations