@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE) public synchronized void initialize() throws ServiceException { tenantInternalApi.initializeCacheInvalidationCallback(TenantKey.CATALOG, cacheInvalidationCallback); }
@Override public Object compute(final String key, final CacheLoaderArgument cacheLoaderArgument) { final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR); final String rawKey = parts[0]; final Matcher matcher = PATTERN.matcher(rawKey); if (!matcher.matches()) { throw new IllegalArgumentException("Unexpected key " + rawKey); } final String pluginName = matcher.group(1); final String tenantRecordId = parts[1]; final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId)); final String stateMachineConfigXML = tenantApi.getPluginPaymentStateMachineConfig(pluginName, internalTenantContext); if (stateMachineConfigXML == null) { return null; } try { log.info("Loading config state machine cache for pluginName='{}', tenantRecordId='{}'", pluginName, internalTenantContext.getTenantRecordId()); return callback.loadStateMachineConfig(stateMachineConfigXML); } catch (final PaymentApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize state machine config for tenantRecordId='%s'", internalTenantContext.getTenantRecordId()), e); } }
@Override public Catalog compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) { final Long tenantRecordId = key; final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId); if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) { throw new IllegalArgumentException("Missing LoaderCallback from the arguments "); } final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final List<String> catalogXMLs = tenantApi.getTenantCatalogs(internalTenantContext); if (catalogXMLs.isEmpty()) { return null; } try { log.info("Loading catalog cache for tenantRecordId='{}'", internalTenantContext.getTenantRecordId()); return callback.loadCatalog(catalogXMLs, tenantRecordId); } catch (final CatalogApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize catalog for tenantRecordId='%s'", internalTenantContext.getTenantRecordId()), e); } }
@Override public PerTenantConfig compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) { final Long tenantRecordId = key; final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId); if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) { throw new IllegalArgumentException("Missing LoaderCallback from the arguments "); } final LoaderCallback loader = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final String jsonValue = tenantApi.getTenantConfig(internalTenantContext); try { return loader.loadConfig(jsonValue); } catch (final IOException e) { throw new IllegalArgumentException("Failed to deserialize per tenant config for tenant recordId = " + tenantRecordId, e); } }
@Override public Object compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) { final Long tenantRecordId = key; final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId); if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) { throw new IllegalArgumentException("Missing LoaderCallback from the arguments"); } final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final String overdueXML = tenantApi.getTenantOverdueConfig(internalTenantContext); if (overdueXML == null) { return EMPTY_VALUE_PLACEHOLDER; } try { log.info("Loading overdue cache for tenant " + internalTenantContext.getTenantRecordId()); return callback.loadOverdueConfig(overdueXML); } catch (final OverdueApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize overdue config for tenant %s : %s", internalTenantContext.getTenantRecordId(), e.getMessage()), e); } }
private String getTenantBundleForType(final Locale locale, final ResourceBundleType type, final InternalTenantContext tenantContext) { switch (type) { case CATALOG_TRANSLATION: return tenantApi.getCatalogTranslation(locale, tenantContext); case INVOICE_TRANSLATION: return tenantApi.getInvoiceTranslation(locale, tenantContext); default: logger.warn("Unexpected bundle type {} ", type); return null; } }
private String getTemplateText(final Locale locale, final boolean manualPay, final InternalTenantContext context) throws IOException { if (InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID.equals(context.getTenantRecordId())) { return getDefaultTemplate(manualPay ? config.getManualPayTemplateName() : config.getTemplateName()); } final String template = manualPay ? tenantApi.getManualPayInvoiceTemplate(locale, context) : tenantApi.getInvoiceTemplate(locale, context); return template == null ? getDefaultTemplate(manualPay ? config.getManualPayTemplateName() : config.getTemplateName()) : template; }
@Test(groups = "fast") public void testWithNoConfig() throws Exception { // We Use the per-tenant config and specify a empty list of plugins Mockito.when(tenantInternalApi.getTenantConfig(Mockito.any(InternalCallContext.class))).thenReturn("{\"org.killbill.invoice.plugin\":\"\"}"); // We register one plugin registerPlugin(PLUGIN_1); final Collection<String> result = invoicePluginDispatcher.getResultingPluginNameList(internalCallContext); // Se expect to seee the list of registered plugins assertEquals(result.size(), 1); final Iterator<String> iterator = result.iterator(); assertEquals(iterator.next(), PLUGIN_1); }
final InputStream otherTenantInputOverdueConfig = UriAccessor.accessUri(new URI(Resources.getResource("OverdueConfig.xml").toExternalForm())); final String otherTenantOverdueConfigXML = CharStreams.toString(new InputStreamReader(otherTenantInputOverdueConfig, "UTF-8")); Mockito.when(tenantInternalApi.getTenantOverdueConfig(Mockito.any(InternalTenantContext.class))).thenAnswer(new Answer<String>() { @Override public String answer(final InvocationOnMock invocation) throws Throwable {
@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE) public synchronized void initialize() throws ServiceException { tenantInternalApi.initializeCacheInvalidationCallback(TenantKey.PER_TENANT_CONFIG, cacheInvalidationCallback); }
final InputStream otherTenantInputCatalog = UriAccessor.accessUri(new URI(Resources.getResource("SpyCarBasic.xml").toExternalForm())); final String otherTenantCatalogXML = CharStreams.toString(new InputStreamReader(otherTenantInputCatalog, "UTF-8")); Mockito.when(tenantInternalApi.getTenantCatalogs(Mockito.any(InternalTenantContext.class))).thenAnswer(new Answer<List<String>>() { @Override public List<String> answer(final InvocationOnMock invocation) throws Throwable {
@Override public Object compute(final String key, final CacheLoaderArgument cacheLoaderArgument) { final String[] parts = key.split(CacheControllerDispatcher.CACHE_KEY_SEPARATOR); final String rawKey = parts[0]; final Matcher matcher = PATTERN.matcher(rawKey); if (!matcher.matches()) { throw new IllegalArgumentException("Unexpected key " + rawKey); } final String pluginName = matcher.group(1); final String tenantRecordId = parts[1]; final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final InternalTenantContext internalTenantContext = new InternalTenantContext(Long.valueOf(tenantRecordId)); final String stateMachineConfigXML = tenantApi.getPluginPaymentStateMachineConfig(pluginName, internalTenantContext); if (stateMachineConfigXML == null) { return null; } try { log.info("Loading config state machine cache for pluginName='{}', tenantRecordId='{}'", pluginName, internalTenantContext.getTenantRecordId()); return callback.loadStateMachineConfig(stateMachineConfigXML); } catch (final PaymentApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize state machine config for tenantRecordId='%s'", internalTenantContext.getTenantRecordId()), e); } }
@Override public PerTenantConfig compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) { final Long tenantRecordId = key; final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId); if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) { throw new IllegalArgumentException("Missing LoaderCallback from the arguments "); } final LoaderCallback loader = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final String jsonValue = tenantApi.getTenantConfig(internalTenantContext); try { return loader.loadConfig(jsonValue); } catch (final IOException e) { throw new IllegalArgumentException("Failed to deserialize per tenant config for tenant recordId = " + tenantRecordId, e); } }
@Override public Object compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) { final Long tenantRecordId = key; final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId); if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) { throw new IllegalArgumentException("Missing LoaderCallback from the arguments"); } final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final String overdueXML = tenantApi.getTenantOverdueConfig(internalTenantContext); if (overdueXML == null) { return EMPTY_VALUE_PLACEHOLDER; } try { log.info("Loading overdue cache for tenant " + internalTenantContext.getTenantRecordId()); return callback.loadOverdueConfig(overdueXML); } catch (final OverdueApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize overdue config for tenant %s : %s", internalTenantContext.getTenantRecordId(), e.getMessage()), e); } }
@LifecycleHandlerType(LifecycleHandlerType.LifecycleLevel.INIT_SERVICE) public void initialize() { registerForBus(); checkNotifier.initialize(); asyncNotifier.initialize(); tenantInternalApi.initializeCacheInvalidationCallback(TenantKey.OVERDUE_CONFIG, overdueCacheInvalidationCallback); }
@Override public Catalog compute(final Long key, final CacheLoaderArgument cacheLoaderArgument) { final Long tenantRecordId = key; final InternalTenantContext internalTenantContext = new InternalTenantContext(tenantRecordId); if (cacheLoaderArgument.getArgs() == null || !(cacheLoaderArgument.getArgs()[0] instanceof LoaderCallback)) { throw new IllegalArgumentException("Missing LoaderCallback from the arguments "); } final LoaderCallback callback = (LoaderCallback) cacheLoaderArgument.getArgs()[0]; final List<String> catalogXMLs = tenantApi.getTenantCatalogs(internalTenantContext); if (catalogXMLs.isEmpty()) { return null; } try { log.info("Loading catalog cache for tenantRecordId='{}'", internalTenantContext.getTenantRecordId()); return callback.loadCatalog(catalogXMLs, tenantRecordId); } catch (final CatalogApiException e) { throw new IllegalStateException(String.format("Failed to de-serialize catalog for tenantRecordId='%s'", internalTenantContext.getTenantRecordId()), e); } }
Mockito.when(tenantInternalApi.getPluginPaymentStateMachineConfig(Mockito.eq(pluginName), Mockito.any(InternalTenantContext.class))).thenAnswer(new Answer<String>() { @Override public String answer(final InvocationOnMock invocation) throws Throwable {
@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE) public synchronized void initialize() throws ServiceException { tenantInternalApi.initializeCacheInvalidationCallback(TenantKey.PER_TENANT_CONFIG, cacheInvalidationCallback); }
final InputStream otherTenantInputCatalog = UriAccessor.accessUri(new URI(Resources.getResource("SpyCarBasic.xml").toExternalForm())); final String otherTenantCatalogXML = CharStreams.toString(new InputStreamReader(otherTenantInputCatalog, "UTF-8")); Mockito.when(tenantInternalApi.getTenantCatalogs(Mockito.any(InternalTenantContext.class))).thenAnswer(new Answer<List<String>>() { @Override public List<String> answer(final InvocationOnMock invocation) throws Throwable {
final Long otherMultiTenantRecordId = otherMultiTenantContext.getTenantRecordId(); Mockito.when(tenantInternalApi.getPluginPaymentStateMachineConfig(Mockito.eq(pluginName), Mockito.any(InternalTenantContext.class))).thenAnswer(new Answer<String>() { @Override public String answer(final InvocationOnMock invocation) throws Throwable {