Search in sources :

Example 51 with AccountAuditLogs

use of org.killbill.billing.util.audit.AccountAuditLogs in project killbill by killbill.

the class PaymentMethodResource method getPaymentMethodByKey.

@TimedResource(name = "getPaymentMethod")
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment method by external key", response = PaymentMethodJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Account or payment method not found") })
public Response getPaymentMethodByKey(@ApiParam(required = true) @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
    final PaymentMethod paymentMethod = paymentApi.getPaymentMethodByExternalKey(externalKey, includedDeleted, withPluginInfo, pluginProperties, tenantContext);
    final Account account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext);
    final PaymentMethodJson json = PaymentMethodJson.toPaymentMethodJson(account, paymentMethod, accountAuditLogs);
    return Response.status(Status.OK).entity(json).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) PaymentMethodJson(org.killbill.billing.jaxrs.json.PaymentMethodJson) TenantContext(org.killbill.billing.util.callcontext.TenantContext) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) 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 52 with AccountAuditLogs

use of org.killbill.billing.util.audit.AccountAuditLogs in project killbill by killbill.

the class PaymentMethodResource method getPaymentMethods.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List payment methods", response = PaymentMethodJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getPaymentMethods(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_PAYMENT_METHOD_PLUGIN_NAME) final String pluginName, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
    final Pagination<PaymentMethod> paymentMethods;
    if (Strings.isNullOrEmpty(pluginName)) {
        paymentMethods = paymentApi.getPaymentMethods(offset, limit, withPluginInfo, pluginProperties, tenantContext);
    } else {
        paymentMethods = paymentApi.getPaymentMethods(offset, limit, pluginName, withPluginInfo, pluginProperties, tenantContext);
    }
    final URI nextPageUri = uriBuilder.nextPage(PaymentMethodResource.class, "getPaymentMethods", paymentMethods.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString()), ImmutableMap.<String, String>of());
    final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
    final Map<UUID, Account> accounts = new HashMap<UUID, Account>();
    return buildStreamingPaginationResponse(paymentMethods, new Function<PaymentMethod, PaymentMethodJson>() {

        @Override
        public PaymentMethodJson apply(final PaymentMethod paymentMethod) {
            // Cache audit logs per account
            if (accountsAuditLogs.get().get(paymentMethod.getAccountId()) == null) {
                accountsAuditLogs.get().put(paymentMethod.getAccountId(), auditUserApi.getAccountAuditLogs(paymentMethod.getAccountId(), auditMode.getLevel(), tenantContext));
            }
            // Lookup the associated account(s)
            if (accounts.get(paymentMethod.getAccountId()) == null) {
                final Account account;
                try {
                    account = accountUserApi.getAccountById(paymentMethod.getAccountId(), tenantContext);
                    accounts.put(paymentMethod.getAccountId(), account);
                } catch (final AccountApiException e) {
                    log.warn("Error retrieving accountId='{}'", paymentMethod.getAccountId(), e);
                    return null;
                }
            }
            return PaymentMethodJson.toPaymentMethodJson(accounts.get(paymentMethod.getAccountId()), paymentMethod, accountsAuditLogs.get().get(paymentMethod.getAccountId()));
        }
    }, nextPageUri);
}
Also used : Account(org.killbill.billing.account.api.Account) HashMap(java.util.HashMap) TenantContext(org.killbill.billing.util.callcontext.TenantContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) URI(java.net.URI) PluginProperty(org.killbill.billing.payment.api.PluginProperty) PaymentMethodJson(org.killbill.billing.jaxrs.json.PaymentMethodJson) AccountApiException(org.killbill.billing.account.api.AccountApiException) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) UUID(java.util.UUID) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) 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 53 with AccountAuditLogs

use of org.killbill.billing.util.audit.AccountAuditLogs in project killbill by killbill.

the class SubscriptionResource method getSubscription.

@TimedResource
@GET
@Path("/{subscriptionId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a subscription by id", response = SubscriptionJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Subscription not found") })
public Response getSubscription(@PathParam("subscriptionId") final UUID subscriptionId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException {
    final TenantContext context = this.context.createTenantContextNoAccountId(request);
    final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(subscriptionId, context);
    final Account account = accountUserApi.getAccountById(subscription.getAccountId(), context);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(subscription.getAccountId(), auditMode.getLevel(), context);
    final SubscriptionJson json = new SubscriptionJson(subscription, account.getCurrency(), accountAuditLogs);
    return Response.status(Status.OK).entity(json).build();
}
Also used : Account(org.killbill.billing.account.api.Account) SubscriptionJson(org.killbill.billing.jaxrs.json.SubscriptionJson) TenantContext(org.killbill.billing.util.callcontext.TenantContext) Subscription(org.killbill.billing.entitlement.api.Subscription) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) 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 54 with AccountAuditLogs

use of org.killbill.billing.util.audit.AccountAuditLogs in project killbill by killbill.

the class AccountResource method getAccountByKey.

@TimedResource
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an account by external key", response = AccountJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Account not found") })
public Response getAccountByKey(@ApiParam(required = true) @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @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.createTenantContextNoAccountId(request);
    final Account account = accountUserApi.getAccountByKey(externalKey, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext);
    final AccountJson accountJson = getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext);
    return Response.status(Status.OK).entity(accountJson).build();
}
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) 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 55 with AccountAuditLogs

use of org.killbill.billing.util.audit.AccountAuditLogs in project killbill by killbill.

the class AccountResource method getAccountBundles.

@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + BUNDLES)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve bundles for account", response = BundleJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getAccountBundles(@PathParam("accountId") final UUID accountId, @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey, @QueryParam(QUERY_BUNDLES_FILTER) final String bundlesFilter, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, SubscriptionApiException, CatalogApiException {
    final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request);
    final Account account = accountUserApi.getAccountById(accountId, tenantContext);
    final List<SubscriptionBundle> bundles = (externalKey != null) ? subscriptionApi.getSubscriptionBundlesForAccountIdAndExternalKey(accountId, externalKey, tenantContext) : subscriptionApi.getSubscriptionBundlesForAccountId(accountId, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext);
    final boolean filter = (null != bundlesFilter && !bundlesFilter.isEmpty());
    final List<SubscriptionBundle> subscriptionBundles = filter ? filterBundles(bundles, Arrays.asList(bundlesFilter.split(","))) : bundles;
    final Collection<BundleJson> result = new LinkedList<BundleJson>();
    for (final SubscriptionBundle subscriptionBundle : subscriptionBundles) {
        result.add(new BundleJson(subscriptionBundle, account.getCurrency(), accountAuditLogs));
    }
    return Response.status(Status.OK).entity(result).build();
}
Also used : Account(org.killbill.billing.account.api.Account) SubscriptionBundle(org.killbill.billing.entitlement.api.SubscriptionBundle) TenantContext(org.killbill.billing.util.callcontext.TenantContext) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) BundleJson(org.killbill.billing.jaxrs.json.BundleJson) LinkedList(java.util.LinkedList) 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

AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)57 TenantContext (org.killbill.billing.util.callcontext.TenantContext)54 ApiOperation (io.swagger.annotations.ApiOperation)53 ApiResponses (io.swagger.annotations.ApiResponses)53 GET (javax.ws.rs.GET)53 Produces (javax.ws.rs.Produces)53 TimedResource (org.killbill.commons.metrics.TimedResource)53 Path (javax.ws.rs.Path)47 Account (org.killbill.billing.account.api.Account)27 UUID (java.util.UUID)24 PluginProperty (org.killbill.billing.payment.api.PluginProperty)21 Payment (org.killbill.billing.payment.api.Payment)17 Invoice (org.killbill.billing.invoice.api.Invoice)13 URI (java.net.URI)12 ImmutableMap (com.google.common.collect.ImmutableMap)10 HashMap (java.util.HashMap)10 Map (java.util.Map)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 SubscriptionBundle (org.killbill.billing.entitlement.api.SubscriptionBundle)10 InvoiceJson (org.killbill.billing.jaxrs.json.InvoiceJson)10