Search in sources :

Example 1 with PriceOverride

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);
    }
}
Also used : StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride) ValidationException(org.killbill.xmlloader.ValidationException) JAXBException(javax.xml.bind.JAXBException) DefaultVersionedCatalog(org.killbill.billing.catalog.DefaultVersionedCatalog) URI(java.net.URI) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) MalformedURLException(java.net.MalformedURLException) JAXBException(javax.xml.bind.JAXBException) ExecutionException(java.util.concurrent.ExecutionException) ValidationException(org.killbill.xmlloader.ValidationException) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PriceOverride(org.killbill.billing.catalog.override.PriceOverride) StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)

Example 2 with PriceOverride

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());
    }
}
Also used : StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride) VersionedCatalog(org.killbill.billing.catalog.VersionedCatalog) StandaloneCatalog(org.killbill.billing.catalog.StandaloneCatalog) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) PriceOverride(org.killbill.billing.catalog.override.PriceOverride) StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)

Example 3 with PriceOverride

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());
    }
}
Also used : StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride) VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) DefaultVersionedCatalog(org.killbill.billing.catalog.DefaultVersionedCatalog) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) DefaultVersionedCatalog(org.killbill.billing.catalog.DefaultVersionedCatalog) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) PriceOverride(org.killbill.billing.catalog.override.PriceOverride) StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)

Example 4 with PriceOverride

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);
}
Also used : OSGIServiceDescriptor(org.killbill.billing.osgi.api.OSGIServiceDescriptor) PriceOverride(org.killbill.billing.catalog.override.PriceOverride) StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with PriceOverride

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);
}
Also used : OSGIServiceDescriptor(org.killbill.billing.osgi.api.OSGIServiceDescriptor) PriceOverride(org.killbill.billing.catalog.override.PriceOverride) StandaloneCatalogWithPriceOverride(org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

StandaloneCatalogWithPriceOverride (org.killbill.billing.catalog.StandaloneCatalogWithPriceOverride)5 PriceOverride (org.killbill.billing.catalog.override.PriceOverride)5 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)3 DefaultVersionedCatalog (org.killbill.billing.catalog.DefaultVersionedCatalog)2 StandaloneCatalog (org.killbill.billing.catalog.StandaloneCatalog)2 OSGIServiceDescriptor (org.killbill.billing.osgi.api.OSGIServiceDescriptor)2 BeforeClass (org.testng.annotations.BeforeClass)2 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ExecutionException (java.util.concurrent.ExecutionException)1 JAXBException (javax.xml.bind.JAXBException)1 VersionedCatalog (org.killbill.billing.catalog.VersionedCatalog)1 StaticCatalog (org.killbill.billing.catalog.api.StaticCatalog)1 VersionedCatalog (org.killbill.billing.catalog.api.VersionedCatalog)1 ValidationException (org.killbill.xmlloader.ValidationException)1