use of org.killbill.billing.catalog.override.PriceOverride in project killbill by killbill.
the class VersionedCatalogLoader method loadDefaultCatalog.
@Override
public VersionedCatalog loadDefaultCatalog(final String uriString) throws CatalogApiException {
try {
final List<URI> xmlURIs;
if (uriString.endsWith(XML_EXTENSION)) {
// Assume its an xml file
xmlURIs = new ArrayList<URI>();
xmlURIs.add(new URI(uriString));
} else {
// Assume its a directory
final URL url = getURLFromString(uriString);
final String directoryContents = UriAccessor.accessUriAsString(uriString);
xmlURIs = findXmlReferences(directoryContents, url);
}
final DefaultVersionedCatalog result = new DefaultVersionedCatalog();
for (final URI u : xmlURIs) {
final StandaloneCatalog catalog = XMLLoader.getObjectFromUri(u, StandaloneCatalog.class);
result.add(new StandaloneCatalogWithPriceOverride(catalog, priceOverride, InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, internalCallContextFactory));
}
// Perform initialization and validation for VersionedCatalog
XMLLoader.initializeAndValidate(result);
return result;
} catch (final ValidationException e) {
logger.warn("Failed to load default catalog", e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_DEFAULT, uriString);
} catch (final JAXBException e) {
logger.warn("Failed to load default catalog", e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_DEFAULT, uriString);
} catch (IllegalArgumentException e) {
logger.warn("Failed to load default catalog", e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_DEFAULT, uriString);
} catch (Exception e) {
logger.warn("Failed to load default catalog", e);
throw new IllegalStateException(e);
}
}
use of org.killbill.billing.catalog.override.PriceOverride in project killbill by killbill.
the class EhCacheCatalogCache method getCatalog.
@Override
public VersionedCatalog getCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final InternalTenantContext tenantContext) throws CatalogApiException {
// STEPH TODO what are the possibilities for caching here ?
final VersionedCatalog pluginVersionedCatalog = getCatalogFromPlugins(tenantContext);
if (pluginVersionedCatalog != null) {
return pluginVersionedCatalog;
}
if (tenantContext.getTenantRecordId() == InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID) {
return useDefaultCatalog ? defaultCatalog : null;
}
// but to be on the safe side;;
try {
VersionedCatalog tenantCatalog = (VersionedCatalog) cacheController.get(tenantContext.getTenantRecordId(), filterTemplateCatalog ? cacheLoaderArgumentWithTemplateFiltering : cacheLoaderArgument);
// for test purpose.
if (useDefaultCatalog && tenantCatalog == null) {
tenantCatalog = new VersionedCatalog(defaultCatalog.getClock());
for (final StandaloneCatalog cur : defaultCatalog.getVersions()) {
final StandaloneCatalogWithPriceOverride curWithOverride = new StandaloneCatalogWithPriceOverride(cur, priceOverride, tenantContext.getTenantRecordId(), internalCallContextFactory);
tenantCatalog.add(curWithOverride);
}
cacheController.add(tenantContext.getTenantRecordId(), tenantCatalog);
}
return tenantCatalog;
} catch (final IllegalStateException e) {
throw new CatalogApiException(ErrorCode.CAT_INVALID_FOR_TENANT, tenantContext.getTenantRecordId());
}
}
use of org.killbill.billing.catalog.override.PriceOverride in project killbill by killbill.
the class DefaultCatalogCache method getCatalog.
@Override
public VersionedCatalog getCatalog(final boolean useDefaultCatalog, final boolean filterTemplateCatalog, final boolean internalUse, final InternalTenantContext tenantContext) throws CatalogApiException {
//
if (internalUse) {
Preconditions.checkState(tenantContext.getAccountRecordId() != null, "Unexpected null accountRecordId in context issued from internal Kill Bill service");
}
final VersionedCatalog pluginVersionedCatalog = getCatalogFromPlugins(tenantContext);
if (pluginVersionedCatalog != null) {
return pluginVersionedCatalog;
}
if (InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID.equals(tenantContext.getTenantRecordId())) {
return useDefaultCatalog ? defaultCatalog : null;
}
// but to be on the safe side;;
try {
DefaultVersionedCatalog tenantCatalog = cacheController.get(tenantContext.getTenantRecordId(), filterTemplateCatalog ? cacheLoaderArgumentWithTemplateFiltering : cacheLoaderArgument);
// for test purpose.
if (useDefaultCatalog && tenantCatalog == null) {
tenantCatalog = new DefaultVersionedCatalog();
for (final StaticCatalog cur : defaultCatalog.getVersions()) {
final StandaloneCatalogWithPriceOverride curWithOverride = new StandaloneCatalogWithPriceOverride(cur, priceOverride, tenantContext.getTenantRecordId(), internalCallContextFactory);
tenantCatalog.add(curWithOverride);
}
initializeCatalog(tenantCatalog);
cacheController.putIfAbsent(tenantContext.getTenantRecordId(), tenantCatalog);
}
return tenantCatalog;
} catch (final IllegalStateException e) {
throw new CatalogApiException(ErrorCode.CAT_INVALID_FOR_TENANT, tenantContext.getTenantRecordId());
}
}
use of org.killbill.billing.catalog.override.PriceOverride in project killbill by killbill.
the class TestWithCatalogPlugin method beforeClass.
@BeforeClass(groups = "slow")
public void beforeClass() throws Exception {
if (hasFailed()) {
return;
}
super.beforeClass();
this.testCatalogPluginApi = new TestCatalogPluginApi(priceOverride, clock, internalCallContext, internalCallContextFactory);
pluginRegistry.registerService(new OSGIServiceDescriptor() {
@Override
public String getPluginSymbolicName() {
return "TestCatalogPluginApi";
}
@Override
public String getPluginName() {
return "TestCatalogPluginApi";
}
@Override
public String getRegistrationName() {
return "TestCatalogPluginApi";
}
}, testCatalogPluginApi);
}
use of org.killbill.billing.catalog.override.PriceOverride in project killbill by killbill.
the class TestHardenCatalogPlugin method beforeClass.
@BeforeClass(groups = "slow")
public void beforeClass() throws Exception {
if (hasFailed()) {
return;
}
super.beforeClass();
this.testCatalogPluginApi = new TestCatalogPluginApi(priceOverride, clock, internalCallContext, internalCallContextFactory);
pluginRegistry.registerService(new OSGIServiceDescriptor() {
@Override
public String getPluginSymbolicName() {
return "TestHardenCatalogPlugin";
}
@Override
public String getPluginName() {
return "TestHardenCatalogPlugin";
}
@Override
public String getRegistrationName() {
return "TestHardenCatalogPlugin";
}
}, testCatalogPluginApi);
}
Aggregations