Search in sources :

Example 16 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class EventsStreamBuilder method buildForEntitlement.

public EventsStream buildForEntitlement(final SubscriptionBaseBundle bundle, final SubscriptionBase subscription, final Collection<SubscriptionBase> allSubscriptionsForBundle, final int accountBCD, final InternalTenantContext internalTenantContext) throws EntitlementApiException {
    final SubscriptionBase baseSubscription = findBaseSubscription(allSubscriptionsForBundle);
    final ImmutableAccountData account;
    try {
        account = accountInternalApi.getImmutableAccountDataById(bundle.getAccountId(), internalTenantContext);
    } catch (final AccountApiException e) {
        throw new EntitlementApiException(e);
    }
    final VersionedCatalog catalog = getCatalog(internalTenantContext);
    // Retrieve the blocking states
    final ImmutableSet<UUID> blockingStateIds = baseSubscription != null ? ImmutableSet.of(account.getId(), bundle.getId(), baseSubscription.getId(), subscription.getId()) : ImmutableSet.of(account.getId(), bundle.getId(), subscription.getId());
    final List<BlockingState> blockingStatesForAccount = defaultBlockingStateDao.getByBlockingIds(blockingStateIds, internalTenantContext);
    final Map<UUID, Integer> bcdCache = new HashMap<UUID, Integer>();
    return buildForEntitlement(blockingStatesForAccount, account, bundle, baseSubscription, subscription, allSubscriptionsForBundle, accountBCD, bcdCache, catalog, internalTenantContext);
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) ImmutableAccountData(org.killbill.billing.account.api.ImmutableAccountData) VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) HashMap(java.util.HashMap) AccountApiException(org.killbill.billing.account.api.AccountApiException) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) BlockingState(org.killbill.billing.entitlement.api.BlockingState) UUID(java.util.UUID)

Example 17 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class EntitlementTestSuiteWithEmbeddedDB method initCatalog.

private VersionedCatalog initCatalog(final CatalogService catalogService) throws Exception {
    ((DefaultCatalogService) catalogService).loadCatalog();
    final VersionedCatalog catalog = catalogService.getFullCatalog(true, true, internalCallContext);
    assertNotNull(catalog);
    return catalog;
}
Also used : VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) DefaultCatalogService(org.killbill.billing.catalog.DefaultCatalogService)

Example 18 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class EventsStreamBuilder method buildForAccount.

public AccountEventsStreams buildForAccount(final InternalTenantContext internalTenantContext) throws EntitlementApiException {
    // Retrieve the subscriptions (map bundle id -> subscriptions)
    final Map<UUID, List<SubscriptionBase>> subscriptions;
    try {
        final VersionedCatalog catalog = getCatalog(internalTenantContext);
        subscriptions = subscriptionInternalApi.getSubscriptionsForAccount(catalog, null, internalTenantContext);
        return buildForAccount(subscriptions, catalog, internalTenantContext);
    } catch (final SubscriptionBaseApiException e) {
        throw new EntitlementApiException(e);
    }
}
Also used : VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) UUID(java.util.UUID) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

Example 19 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class DefaultCatalogUserApi method getCatalog.

@Override
public VersionedCatalog getCatalog(final String catalogName, final TenantContext tenantContext) throws CatalogApiException {
    final InternalTenantContext internalTenantContext;
    if (tenantContext.getAccountId() != null) {
        internalTenantContext = internalCallContextFactory.createInternalTenantContext(tenantContext.getAccountId(), tenantContext);
    } else {
        internalTenantContext = createInternalTenantContext(tenantContext);
    }
    final VersionedCatalog fullCatalog = catalogService.getFullCatalog(true, true, internalTenantContext);
    return fullCatalog;
}
Also used : VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) DefaultVersionedCatalog(org.killbill.billing.catalog.DefaultVersionedCatalog) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext)

Example 20 with VersionedCatalog

use of org.killbill.billing.catalog.api.VersionedCatalog in project killbill by killbill.

the class DefaultCatalogUserApi method uploadCatalog.

@Override
public void uploadCatalog(final String catalogXML, final CallContext callContext) throws CatalogApiException {
    final InternalTenantContext internalTenantContext = createInternalTenantContext(callContext);
    try {
        VersionedCatalog versionedCatalog = catalogService.getFullCatalog(false, true, internalTenantContext);
        if (versionedCatalog == null) {
            // If this is the first version
            versionedCatalog = new DefaultVersionedCatalog();
        }
        // Validation purpose:  Will throw if bad XML or catalog validation fails
        final InputStream stream = new ByteArrayInputStream(catalogXML.getBytes());
        final StaticCatalog newCatalogVersion = XMLLoader.getObjectFromStream(stream, StandaloneCatalog.class);
        final ValidationErrors errors = new ValidationErrors();
        // Fix for https://github.com/killbill/killbill/issues/1481
        ((DefaultVersionedCatalog) versionedCatalog).add((StandaloneCatalog) newCatalogVersion);
        ((DefaultVersionedCatalog) versionedCatalog).validate(null, errors);
        if (!errors.isEmpty()) {
            // Bummer ValidationException CTOR is private to package...
            // final ValidationException validationException = new ValidationException(errors);
            // throw new CatalogApiException(errors, ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
            logger.info("Failed to load new catalog version: " + errors.toString());
            throw new CatalogApiException(ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
        }
        tenantApi.addTenantKeyValue(TenantKey.CATALOG.toString(), catalogXML, callContext);
        catalogCache.clearCatalog(internalTenantContext);
    } catch (final TenantApiException e) {
        throw new CatalogApiException(e);
    } catch (final ValidationException e) {
        throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
    } catch (final JAXBException e) {
        throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, internalTenantContext.getTenantRecordId());
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    } catch (final TransformerException e) {
        throw new IllegalStateException(e);
    } catch (final SAXException e) {
        throw new IllegalStateException(e);
    }
}
Also used : ValidationException(org.killbill.xmlloader.ValidationException) ValidationErrors(org.killbill.xmlloader.ValidationErrors) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) DefaultVersionedCatalog(org.killbill.billing.catalog.DefaultVersionedCatalog) IOException(java.io.IOException) StaticCatalog(org.killbill.billing.catalog.api.StaticCatalog) SAXException(org.xml.sax.SAXException) VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) DefaultVersionedCatalog(org.killbill.billing.catalog.DefaultVersionedCatalog) ByteArrayInputStream(java.io.ByteArrayInputStream) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantApiException(org.killbill.billing.tenant.api.TenantApiException) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) TransformerException(javax.xml.transform.TransformerException)

Aggregations

VersionedCatalog (org.killbill.billing.catalog.api.VersionedCatalog)33 Test (org.testng.annotations.Test)14 DefaultVersionedCatalog (org.killbill.billing.catalog.DefaultVersionedCatalog)11 UUID (java.util.UUID)10 DateTime (org.joda.time.DateTime)8 LocalDate (org.joda.time.LocalDate)8 BigDecimal (java.math.BigDecimal)7 ArrayList (java.util.ArrayList)7 Account (org.killbill.billing.account.api.Account)7 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)7 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)7 Invoice (org.killbill.billing.invoice.api.Invoice)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)6 StaticCatalog (org.killbill.billing.catalog.api.StaticCatalog)6 DefaultEntitlementSpecifier (org.killbill.billing.entitlement.api.DefaultEntitlementSpecifier)6 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4