tenantApi.addTenantKeyValue(TenantKey.CATALOG.toString(), catalogXML, callContext); catalogCache.clearCatalog(internalTenantContext); } catch (final TenantApiException e) {
@Override public boolean apply(final TenantKey input) { return input.isSingleValue() && key.startsWith(input.toString()); } }).orNull() != null;
private TenantKeyAndCookie extractTenantKeyAndCookie(final String key) { final TenantKey tenantKey = Iterables.tryFind(ImmutableList.copyOf(TenantKey.values()), new Predicate<TenantKey>() { @Override public boolean apply(final TenantKey input) { return key.startsWith(input.toString()); } }).orNull(); if (tenantKey == null) { return null; } final String cookie = !key.equals(tenantKey.toString()) ? key.substring(tenantKey.toString().length()) : null; return new TenantKeyAndCookie(tenantKey, cookie); }
tenantApi.addTenantKeyValue(TenantKey.CATALOG.toString(), catalogXML, callContext); catalogCache.clearCatalog(internalTenantContext); } catch (final TenantApiException e) {
@Test(groups = "slow") public void testSystemKeySingleValue() throws Exception { final String tenantKey = TenantKey.PLUGIN_CONFIG_.toString() + "MyPluginName"; tenantUserApi.addTenantKeyValue(tenantKey, "TheValue", callContext); List<String> value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 1); Assert.assertEquals(value.get(0), "TheValue"); // Warm cache value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 1); Assert.assertEquals(value.get(0), "TheValue"); tenantUserApi.addTenantKeyValue(tenantKey, "TheSecondValue", callContext); value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 1); Assert.assertEquals(value.get(0), "TheSecondValue"); // Warm cache value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 1); Assert.assertEquals(value.get(0), "TheSecondValue"); tenantUserApi.deleteTenantKey(tenantKey, callContext); value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 0); }
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/297") public void testVerifyCacheOnAbsentValues() throws Exception { final String tenantKey = TenantKey.PLUGIN_CONFIG_.toString() + "MyPluginName"; // Warm the cache with the empty value List<String> value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 0); // Update the DAO directly (caching is done at the API layer) tenantDao.addTenantKeyValue(tenantKey, "TheValue-hidden!", true, internalCallContext); // Verify we still hit the cache value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 0); // Update the cache tenantUserApi.addTenantKeyValue(tenantKey, "TheValue", callContext); // Verify the cache now has the right value value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 1); Assert.assertEquals(value.get(0), "TheValue"); }
@Override public void addSimplePlan(final SimplePlanDescriptor descriptor, @Nullable final DateTime effectiveDate, final CallContext callContext) throws CatalogApiException { try { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(callContext); final StandaloneCatalog currentCatalog = getCurrentStandaloneCatalogForTenant(internalTenantContext); final CatalogUpdater catalogUpdater = (currentCatalog != null) ? new CatalogUpdater(currentCatalog) : new CatalogUpdater(getSafeFirstCatalogEffectiveDate(effectiveDate, callContext), descriptor.getCurrency()); catalogUpdater.addSimplePlanDescriptor(descriptor); tenantApi.updateTenantKeyValue(TenantKey.CATALOG.toString(), catalogUpdater.getCatalogXML(), callContext); catalogCache.clearCatalog(internalTenantContext); } catch (TenantApiException e) { throw new CatalogApiException(e); } }
@Override public void uploadOverdueConfig(final String overdueXML, final CallContext callContext) throws OverdueApiException { try { final InternalTenantContext internalTenantContext = createInternalTenantContext(callContext); final String tenantKey = TenantKey.OVERDUE_CONFIG.toString(); if (!tenantApi.getTenantValuesForKey(tenantKey, callContext).isEmpty()) { tenantApi.deleteTenantKey(tenantKey, callContext); } tenantApi.addTenantKeyValue(tenantKey, overdueXML, callContext); overdueConfigCache.clearOverdueConfig(internalTenantContext); } catch (final TenantApiException e) { throw new OverdueApiException(e); } }
private TenantKeyAndCookie extractTenantKeyAndCookie(final String key) { final TenantKey tenantKey = Iterables.tryFind(ImmutableList.copyOf(TenantKey.values()), new Predicate<TenantKey>() { @Override public boolean apply(final TenantKey input) { return key.startsWith(input.toString()); } }).orNull(); if (tenantKey == null) { return null; } final String cookie = !key.equals(tenantKey.toString()) ? key.substring(tenantKey.toString().length()) : null; return new TenantKeyAndCookie(tenantKey, cookie); }
private Response insertTenantKey(final TenantKey key, @Nullable final String keyPostfix, final String value, final UriInfo uriInfo, final String getMethodStr, final String createdBy, final String reason, final String comment, final HttpServletRequest request) throws TenantApiException { final CallContext callContext = context.createCallContextNoAccountId(createdBy, reason, comment, request); final String tenantKey = keyPostfix != null ? key.toString() + keyPostfix : key.toString(); tenantApi.addTenantKeyValue(tenantKey, value, callContext); return uriBuilder.buildResponse(uriInfo, TenantResource.class, getMethodStr, keyPostfix, request); }
@Test(groups = "slow") public void testSystemKeyMultipleValue() throws Exception { final String tenantKey = TenantKey.CATALOG.toString(); tenantUserApi.addTenantKeyValue(tenantKey, "TheValue", callContext); List<String> value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 1); Assert.assertEquals(value.get(0), "TheValue"); tenantUserApi.addTenantKeyValue(tenantKey, "TheSecondValue", callContext); value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 2); tenantUserApi.deleteTenantKey(tenantKey, callContext); value = tenantUserApi.getTenantValuesForKey(tenantKey, callContext); Assert.assertEquals(value.size(), 0); }
@Override public void createDefaultEmptyCatalog(@Nullable final DateTime effectiveDate, final CallContext callContext) throws CatalogApiException { try { final InternalTenantContext internalTenantContext = internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(callContext); final StandaloneCatalog currentCatalog = getCurrentStandaloneCatalogForTenant(internalTenantContext); final CatalogUpdater catalogUpdater = (currentCatalog != null) ? new CatalogUpdater(currentCatalog) : new CatalogUpdater(getSafeFirstCatalogEffectiveDate(effectiveDate, callContext), null); tenantApi.updateTenantKeyValue(TenantKey.CATALOG.toString(), catalogUpdater.getCatalogXML(), callContext); catalogCache.clearCatalog(internalTenantContext); } catch (TenantApiException e) { throw new CatalogApiException(e); } }
@Override public List<String> getTenantCatalogs(final InternalTenantContext tenantContext) { return tenantDao.getTenantValueForKey(TenantKey.CATALOG.toString(), tenantContext); }
@Override public void invalidateCache(TenantKey tenantKey, final Object cookie, final InternalTenantContext tenantContext) { final StringBuilder keyBuilder = new StringBuilder(tenantKey.toString()); if (cookie instanceof String) { keyBuilder.append((String) cookie); } keyBuilder.append(CacheControllerDispatcher.CACHE_KEY_SEPARATOR); keyBuilder.append(tenantContext.getTenantRecordId()); final String key = keyBuilder.toString(); log.info("Invalidate cache for tenant {} and key {} ", tenantContext.getTenantRecordId(), key); tenantKVCache.remove(key); } }
@Override public String getCatalogTranslation(final Locale locale, final InternalTenantContext tenantContext) { final List<String> values = tenantDao.getTenantValueForKey(LocaleUtils.localeString(locale, TenantKey.CATALOG_TRANSLATION_.toString()), tenantContext); return getUniqueValue(values, "catalog translation", tenantContext); }
@Override public String getInvoiceTemplate(final Locale locale, final InternalTenantContext tenantContext) { final List<String> values = tenantDao.getTenantValueForKey(TenantKey.INVOICE_TEMPLATE.toString(), tenantContext); return getUniqueValue(values, "invoice template", tenantContext); }
@Override public String getTenantConfig(final InternalTenantContext tenantContext) { final List<String> values = tenantDao.getTenantValueForKey(TenantKey.PER_TENANT_CONFIG.toString(), tenantContext); return getUniqueValue(values, "per tenant config", tenantContext); }
private boolean isSystemKey(final String key) { return Iterables.tryFind(ImmutableList.copyOf(TenantKey.values()), new Predicate<TenantKey>() { @Override public boolean apply(final TenantKey input) { return key.startsWith(input.toString()); } }).orNull() != null; }
private Response getTemplateResource(@Nullable final String localeStr, final TenantKey tenantKey, final HttpServletRequest request) throws InvoiceApiException, TenantApiException { final TenantContext tenantContext = context.createTenantContextNoAccountId(request); final String tenantKeyStr = localeStr != null ? LocaleUtils.localeString(LocaleUtils.toLocale(localeStr), tenantKey.toString()) : tenantKey.toString(); final List<String> result = tenantApi.getTenantValuesForKey(tenantKeyStr, tenantContext); return result.isEmpty() ? Response.status(Status.NOT_FOUND).build() : Response.status(Status.OK).entity(result.get(0)).build(); }