use of org.killbill.billing.catalog.plugin.api.CatalogPluginApi in project killbill by killbill.
the class EhCacheCatalogCache method getCatalogFromPlugins.
private VersionedCatalog getCatalogFromPlugins(final InternalTenantContext internalTenantContext) throws CatalogApiException {
final TenantContext tenantContext = internalCallContextFactory.createTenantContext(internalTenantContext);
for (final String service : pluginRegistry.getAllServices()) {
final CatalogPluginApi plugin = pluginRegistry.getServiceForName(service);
final VersionedPluginCatalog pluginCatalog = plugin.getVersionedPluginCatalog(ImmutableList.<PluginProperty>of(), tenantContext);
// First plugin that gets something (for that tenant) returns it
if (pluginCatalog != null) {
logger.info("Returning catalog from plugin {} on tenant {} ", service, internalTenantContext.getTenantRecordId());
return versionedCatalogMapper.toVersionedCatalog(pluginCatalog, internalTenantContext);
}
}
return null;
}
use of org.killbill.billing.catalog.plugin.api.CatalogPluginApi in project killbill by killbill.
the class DefaultCatalogCache method getCatalogFromPlugins.
private VersionedCatalog getCatalogFromPlugins(final InternalTenantContext internalTenantContext) throws CatalogApiException {
final TenantContext tenantContext = internalCallContextFactory.createTenantContext(internalTenantContext);
final Set<String> allServices = pluginRegistry.getAllServices();
for (final String service : allServices) {
final CatalogPluginApi plugin = pluginRegistry.getServiceForName(service);
//
// Beware plugin implementors: latestCatalogUpdatedDate returned by the plugin should also match the effectiveDate of the VersionedCatalog.
//
// However, this is the plugin choice to return one, or many catalog versions (StandaloneCatalog), Kill Bill catalog module does not care.
// As a guideline, if plugin keeps seeing new Plans/Products, this can all fit into the same version; however if there is a true versioning
// (e.g deleted Plans...), then multiple versions must be returned.
//
final DateTime latestCatalogUpdatedDate = plugin.getLatestCatalogVersion(ImmutableList.<PluginProperty>of(), tenantContext);
// A null latestCatalogUpdatedDate bypasses caching, by fetching full catalog from plugin below (compatibility mode with 0.18.x or non optimized plugin api mode)
final boolean cacheable = latestCatalogUpdatedDate != null;
if (cacheable) {
final DefaultVersionedCatalog versionedCatalog = cacheController.get(internalTenantContext.getTenantRecordId(), cacheLoaderArgument);
if (versionedCatalog != null) {
if (versionedCatalog.getCurrentVersion().getEffectiveDate().compareTo(latestCatalogUpdatedDate.toDate()) == 0) {
// Current cached version matches the one from the plugin
return versionedCatalog;
}
}
}
final VersionedPluginCatalog pluginCatalog = plugin.getVersionedPluginCatalog(ImmutableList.<PluginProperty>of(), tenantContext);
// First plugin that gets something (for that tenant) returns it
if (pluginCatalog != null) {
// The log entry is only interesting if there are multiple plugins
if (allServices.size() > 1) {
logger.info("Returning catalog from plugin {} on tenant {} ", service, internalTenantContext.getTenantRecordId());
}
final DefaultVersionedCatalog resolvedPluginCatalog = versionedCatalogMapper.toVersionedCatalog(pluginCatalog);
// Always clear the cache for safety
cacheController.remove(internalTenantContext.getTenantRecordId());
if (cacheable) {
cacheController.putIfAbsent(internalTenantContext.getTenantRecordId(), resolvedPluginCatalog);
}
return resolvedPluginCatalog;
}
}
return null;
}
Aggregations