@Override public List<SubscriptionBase> getSubscriptionsForBundle(final UUID bundleId, @Nullable final DryRunArguments dryRunArguments, final InternalTenantContext context) throws SubscriptionBaseApiException { try { final Catalog catalog = catalogInternalApi.getFullCatalog(true, true, context); final TenantContext tenantContext = internalCallContextFactory.createTenantContext(context); final List<DefaultSubscriptionBase> subscriptionsForBundle = super.getSubscriptionsForBundle(bundleId, dryRunArguments, catalog, addonUtils, tenantContext, context); return new ArrayList<SubscriptionBase>(subscriptionsForBundle); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }
private DefaultVersionedCatalog getCatalogFromPlugins(final InternalTenantContext internalTenantContext) throws CatalogApiException { final TenantContext tenantContext = internalCallContextFactory.createTenantContext(internalTenantContext); final Set<String> allServices = pluginRegistry.getAllServices(); for (final String service : allServices) {
@Override public DateTime getDryRunChangePlanEffectiveDate(final SubscriptionBase subscription, final EntitlementSpecifier spec, final DateTime requestedDateWithMs, final BillingActionPolicy requestedPolicy, final InternalCallContext context) throws SubscriptionBaseApiException, CatalogApiException { final TenantContext tenantContext = internalCallContextFactory.createTenantContext(context); final CallContext callContext = internalCallContextFactory.createCallContext(context); // verify the number of subscriptions (of the same kind) allowed per bundle final Catalog catalog = catalogInternalApi.getFullCatalog(true, true, context); final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : null; final DateTime effectiveCatalogDate = effectiveDate != null ? effectiveDate : context.getCreatedDate(); final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(spec.getOverrides(), callContext); final Plan plan = catalog.createOrFindPlan(spec.getPlanPhaseSpecifier(), overridesWithContext, effectiveCatalogDate, subscription.getStartDate()); if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(plan.getProduct().getCategory().toString())) { if (plan.getPlansAllowedInBundle() != -1 && plan.getPlansAllowedInBundle() > 0 && addonUtils.countExistingAddOnsWithSamePlanName(getSubscriptionsForBundle(subscription.getBundleId(), null, catalog, addonUtils, callContext, context), plan.getName()) >= plan.getPlansAllowedInBundle()) { // the plan can be changed to the new value, because it has reached its limit by bundle throw new SubscriptionBaseApiException(ErrorCode.SUB_CHANGE_AO_MAX_PLAN_ALLOWED_BY_BUNDLE, plan.getName()); } } return apiService.dryRunChangePlan((DefaultSubscriptionBase) subscription, spec, effectiveDate, requestedPolicy, tenantContext); }
private TenantContext buildTenantContext(final InternalTenantContext context) { return internalCallContextFactory.createTenantContext(context); }
@Override public List<SubscriptionBase> getSubscriptionsForBundle(final UUID bundleId, @Nullable final DryRunArguments dryRunArguments, final InternalTenantContext context) throws SubscriptionBaseApiException { try { final Catalog catalog = catalogInternalApi.getFullCatalog(true, true, context); final TenantContext tenantContext = internalCallContextFactory.createTenantContext(context); final List<DefaultSubscriptionBase> subscriptionsForBundle = super.getSubscriptionsForBundle(bundleId, dryRunArguments, catalog, addonUtils, tenantContext, context); return new ArrayList<SubscriptionBase>(subscriptionsForBundle); } catch (final CatalogApiException e) { throw new SubscriptionBaseApiException(e); } }
final Long parentAccountRecordId = internalCallContextFactory.getRecordIdFromObject(parentAccountId, ObjectType.ACCOUNT, internalCallContextFactory.createTenantContext(childContext)); final InternalTenantContext parentContext = internalCallContextFactory.createInternalTenantContext(childContext.getTenantRecordId(), parentAccountRecordId);
@BeforeMethod(groups = "fast") public void setUp() throws Exception { externalBus = mock(PersistentBus.class); internalCallContextFactory = mock(InternalCallContextFactory.class); beatrixListener = new BeatrixListener(externalBus, internalCallContextFactory); objectMapper = mock(ObjectMapper.class); beatrixListener.objectMapper = objectMapper; InternalCallContext internalContext = new InternalCallContext( TENANT_RECORD_ID, ACCOUNT_RECORD_ID, null, null, USER_TOKEN, null, null, null, null, null, null, null ); when(internalCallContextFactory.createInternalCallContext( SEARCH_KEY_2, SEARCH_KEY_1, "BeatrixListener", CallOrigin.INTERNAL, UserType.SYSTEM, USER_TOKEN)).thenReturn(internalContext); tenantContext = mock(TenantContext.class); when(tenantContext.getTenantId()).thenReturn(TENANT_ID); when(internalCallContextFactory.createTenantContext(internalContext)).thenReturn(tenantContext); }
private DefaultVersionedCatalog getCatalogFromPlugins(final InternalTenantContext internalTenantContext) throws CatalogApiException { final TenantContext tenantContext = internalCallContextFactory.createTenantContext(internalTenantContext); final Set<String> allServices = pluginRegistry.getAllServices(); for (final String service : allServices) {
@Override public DateTime getDryRunChangePlanEffectiveDate(final SubscriptionBase subscription, final EntitlementSpecifier spec, final DateTime requestedDateWithMs, final BillingActionPolicy requestedPolicy, final InternalCallContext context) throws SubscriptionBaseApiException, CatalogApiException { final TenantContext tenantContext = internalCallContextFactory.createTenantContext(context); final CallContext callContext = internalCallContextFactory.createCallContext(context); // verify the number of subscriptions (of the same kind) allowed per bundle final Catalog catalog = catalogInternalApi.getFullCatalog(true, true, context); final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : null; final DateTime effectiveCatalogDate = effectiveDate != null ? effectiveDate : context.getCreatedDate(); final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(spec.getOverrides(), callContext); final Plan plan = catalog.createOrFindPlan(spec.getPlanPhaseSpecifier(), overridesWithContext, effectiveCatalogDate, subscription.getStartDate()); if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(plan.getProduct().getCategory().toString())) { if (plan.getPlansAllowedInBundle() != -1 && plan.getPlansAllowedInBundle() > 0 && addonUtils.countExistingAddOnsWithSamePlanName(getSubscriptionsForBundle(subscription.getBundleId(), null, catalog, addonUtils, callContext, context), plan.getName()) >= plan.getPlansAllowedInBundle()) { // the plan can be changed to the new value, because it has reached its limit by bundle throw new SubscriptionBaseApiException(ErrorCode.SUB_CHANGE_AO_MAX_PLAN_ALLOWED_BY_BUNDLE, plan.getName()); } } return apiService.dryRunChangePlan((DefaultSubscriptionBase) subscription, spec, effectiveDate, requestedPolicy, tenantContext); }