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);
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations