Search in sources :

Example 1 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.

the class DefaultSubscriptionInternalApi method getDryRunChangePlanEffectiveDate.

@Override
public DateTime getDryRunChangePlanEffectiveDate(final SubscriptionBase subscription, final PlanSpecifier spec, final DateTime requestedDateWithMs, final BillingActionPolicy requestedPolicy, final List<PlanPhasePriceOverride> overrides, 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 = catalogService.getFullCatalog(true, true, context);
    final DateTime now = clock.getUTCNow();
    final DateTime effectiveDate = (requestedDateWithMs != null) ? DefaultClock.truncateMs(requestedDateWithMs) : now;
    final PlanPhasePriceOverridesWithCallContext overridesWithContext = new DefaultPlanPhasePriceOverridesWithCallContext(overrides, callContext);
    final Plan plan = catalog.createOrFindPlan(spec, overridesWithContext, effectiveDate);
    if (ProductCategory.ADD_ON.toString().equalsIgnoreCase(plan.getProduct().getCategory().toString())) {
        if (plan.getPlansAllowedInBundle() != -1 && plan.getPlansAllowedInBundle() > 0 && addonUtils.countExistingAddOnsWithSamePlanName(getSubscriptionsForBundle(subscription.getBundleId(), null, 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, requestedDateWithMs, requestedPolicy, tenantContext);
}
Also used : PlanPhasePriceOverridesWithCallContext(org.killbill.billing.catalog.api.PlanPhasePriceOverridesWithCallContext) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantContext(org.killbill.billing.util.callcontext.TenantContext) Plan(org.killbill.billing.catalog.api.Plan) PlanPhasePriceOverridesWithCallContext(org.killbill.billing.catalog.api.PlanPhasePriceOverridesWithCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) Catalog(org.killbill.billing.catalog.api.Catalog) DateTime(org.joda.time.DateTime) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride)

Example 2 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.

the class PushNotificationListener method triggerPushNotifications.

@AllowConcurrentEvents
@Subscribe
public void triggerPushNotifications(final ExtBusEvent event) {
    final TenantContext context = contextFactory.createTenantContext(event.getTenantId());
    try {
        final List<String> callbacks = getCallbacksForTenant(context);
        if (callbacks.isEmpty()) {
            // Optimization - see https://github.com/killbill/killbill/issues/297
            return;
        }
        dispatchCallback(event.getTenantId(), event, callbacks);
    } catch (final TenantApiException e) {
        log.warn("Failed to retrieve push notification callback for tenant {}", event.getTenantId());
    } catch (final IOException e) {
        log.warn("Failed to retrieve push notification callback for tenant {}", event.getTenantId());
    }
}
Also used : TenantApiException(org.killbill.billing.tenant.api.TenantApiException) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantContext(org.killbill.billing.util.callcontext.TenantContext) IOException(java.io.IOException) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.

the class EhCacheCatalogCache method getCatalogFromPlugins.

private VersionedCatalog getCatalogFromPlugins(final InternalTenantContext internalTenantContext) throws CatalogApiException {
    final TenantContext tenantContext = internalCallContextFactory.createTenantContext(internalTenantContext);
    for (final String service : pluginRegistry.getAllServices()) {
        final CatalogPluginApi plugin = pluginRegistry.getServiceForName(service);
        final VersionedPluginCatalog pluginCatalog = plugin.getVersionedPluginCatalog(ImmutableList.<PluginProperty>of(), tenantContext);
        // First plugin that gets something (for that tenant) returns it
        if (pluginCatalog != null) {
            logger.info("Returning catalog from plugin {} on tenant {} ", service, internalTenantContext.getTenantRecordId());
            return versionedCatalogMapper.toVersionedCatalog(pluginCatalog, internalTenantContext);
        }
    }
    return null;
}
Also used : VersionedPluginCatalog(org.killbill.billing.catalog.plugin.api.VersionedPluginCatalog) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantContext(org.killbill.billing.util.callcontext.TenantContext) CatalogPluginApi(org.killbill.billing.catalog.plugin.api.CatalogPluginApi)

Example 4 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.

the class AccountResource method searchAccounts.

@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search accounts", response = AccountJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchAccounts(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE) @DefaultValue("false") final Boolean accountWithBalance, @QueryParam(QUERY_ACCOUNT_WITH_BALANCE_AND_CBA) @DefaultValue("false") final Boolean accountWithBalanceAndCBA, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<Account> accounts = accountUserApi.searchAccounts(searchKey, offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(AccountResource.class, "searchAccounts", accounts.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_ACCOUNT_WITH_BALANCE, accountWithBalance.toString(), QUERY_ACCOUNT_WITH_BALANCE_AND_CBA, accountWithBalanceAndCBA.toString(), QUERY_AUDIT, auditMode.getLevel().toString()));
    return buildStreamingPaginationResponse(accounts, new Function<Account, AccountJson>() {

        @Override
        public AccountJson apply(final Account account) {
            final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext);
            return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext);
        }
    }, nextPageUri);
}
Also used : AccountJson(org.killbill.billing.jaxrs.json.AccountJson) Account(org.killbill.billing.account.api.Account) TenantContext(org.killbill.billing.util.callcontext.TenantContext) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) URI(java.net.URI) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with TenantContext

use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.

the class AccountResource method getAllTags.

@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + ALL_TAGS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account tags", response = TagJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getAllTags(@PathParam(ID_PARAM_NAME) final String accountIdString, @QueryParam(QUERY_OBJECT_TYPE) final ObjectType objectType, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException {
    final UUID accountId = UUID.fromString(accountIdString);
    final TenantContext tenantContext = context.createContext(request);
    final List<Tag> tags = objectType != null ? tagUserApi.getTagsForAccountType(accountId, objectType, includedDeleted, tenantContext) : tagUserApi.getTagsForAccount(accountId, includedDeleted, tenantContext);
    return createTagResponse(accountId, tags, auditMode, tenantContext);
}
Also used : TenantContext(org.killbill.billing.util.callcontext.TenantContext) Tag(org.killbill.billing.util.tag.Tag) MetricTag(org.killbill.commons.metrics.MetricTag) UUID(java.util.UUID) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

TenantContext (org.killbill.billing.util.callcontext.TenantContext)69 ApiOperation (io.swagger.annotations.ApiOperation)58 ApiResponses (io.swagger.annotations.ApiResponses)58 Produces (javax.ws.rs.Produces)58 GET (javax.ws.rs.GET)57 TimedResource (org.killbill.commons.metrics.TimedResource)54 Path (javax.ws.rs.Path)51 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)31 UUID (java.util.UUID)30 Account (org.killbill.billing.account.api.Account)17 PluginProperty (org.killbill.billing.payment.api.PluginProperty)15 URI (java.net.URI)14 Payment (org.killbill.billing.payment.api.Payment)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Invoice (org.killbill.billing.invoice.api.Invoice)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Map (java.util.Map)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 List (java.util.List)7