Search in sources :

Example 1 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 String 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 {
    final TenantContext tenantContext = context.createContext(request);
    final UUID uuid = UUID.fromString(accountId);
    final Account account = accountUserApi.getAccountById(uuid, tenantContext);
    final List<SubscriptionBundle> bundles = (externalKey != null) ? subscriptionApi.getSubscriptionBundlesForAccountIdAndExternalKey(uuid, externalKey, tenantContext) : subscriptionApi.getSubscriptionBundlesForAccountId(uuid, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext);
    boolean filter = (null != bundlesFilter && !bundlesFilter.isEmpty());
    final Collection<BundleJson> result = Collections2.transform((filter) ? filterBundles(bundles, Arrays.asList(bundlesFilter.split(","))) : bundles, new Function<SubscriptionBundle, BundleJson>() {

        @Override
        public BundleJson apply(final SubscriptionBundle input) {
            try {
                return new BundleJson(input, account.getCurrency(), accountAuditLogs);
            } catch (final CatalogApiException e) {
                // Not the cleanest thing, but guava Api don't allow throw..
                throw new RuntimeException(e);
            }
        }
    });
    return Response.status(Status.OK).entity(result).build();
}
Also used : Account(org.killbill.billing.account.api.Account) TenantContext(org.killbill.billing.util.callcontext.TenantContext) BundleJson(org.killbill.billing.jaxrs.json.BundleJson) SubscriptionBundle(org.killbill.billing.entitlement.api.SubscriptionBundle) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) UUID(java.util.UUID) 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 2 with AccountAuditLogs

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

the class AccountResource method getChildrenAccounts.

// -------------------------------------
//      Parent and child accounts
// -------------------------------------
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + CHILDREN)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List children accounts", response = AccountJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid parent account id supplied"), @ApiResponse(code = 404, message = "Parent Account not found") })
public Response getChildrenAccounts(@PathParam("accountId") final String parentAccountId, @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 List<Account> accounts = accountUserApi.getChildrenAccounts(UUID.fromString(parentAccountId), tenantContext);
    final List<AccountJson> accountJson = new ArrayList<AccountJson>();
    for (final Account account : accounts) {
        final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext);
        accountJson.add(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) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) 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 3 with AccountAuditLogs

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

the class AccountResource method getInvoices.

/*
     * ************************** INVOICES ********************************
     */
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + INVOICES)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account invoices", response = InvoiceJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getInvoices(@PathParam("accountId") final String accountIdString, @QueryParam(QUERY_INVOICE_WITH_ITEMS) @DefaultValue("false") final boolean withItems, @QueryParam(QUERY_WITH_MIGRATION_INVOICES) @DefaultValue("false") final boolean withMigrationInvoices, @QueryParam(QUERY_UNPAID_INVOICES_ONLY) @DefaultValue("false") final boolean unpaidInvoicesOnly, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException {
    final TenantContext tenantContext = context.createContext(request);
    // Verify the account exists
    final UUID accountId = UUID.fromString(accountIdString);
    accountUserApi.getAccountById(accountId, tenantContext);
    final List<Invoice> invoices = unpaidInvoicesOnly ? new ArrayList<Invoice>(invoiceApi.getUnpaidInvoicesByAccountId(accountId, null, tenantContext)) : invoiceApi.getInvoicesByAccount(accountId, withMigrationInvoices, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext);
    final List<InvoiceJson> result = new LinkedList<InvoiceJson>();
    for (final Invoice invoice : invoices) {
        result.add(new InvoiceJson(invoice, withItems, null, accountAuditLogs));
    }
    return Response.status(Status.OK).entity(result).build();
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) InvoiceJson(org.killbill.billing.jaxrs.json.InvoiceJson) TenantContext(org.killbill.billing.util.callcontext.TenantContext) UUID(java.util.UUID) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) 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)

Example 4 with AccountAuditLogs

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

the class AccountResource method getInvoicePayments.

/*
     * ************************** PAYMENTS ********************************
     */
// STEPH should refactor code since very similar to @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENTS)
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + INVOICE_PAYMENTS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account invoice payments", response = InvoicePaymentJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getInvoicePayments(@PathParam("accountId") final String accountIdStr, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException, AccountApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final UUID accountId = UUID.fromString(accountIdStr);
    final TenantContext tenantContext = context.createContext(request);
    final Account account = accountUserApi.getAccountById(accountId, tenantContext);
    final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), withPluginInfo, withAttempts, pluginProperties, tenantContext);
    final List<InvoicePayment> invoicePayments = invoicePaymentApi.getInvoicePaymentsByAccount(accountId, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext);
    final List<InvoicePaymentJson> result = new ArrayList<InvoicePaymentJson>(payments.size());
    for (final Payment payment : payments) {
        final UUID invoiceId = getInvoiceId(invoicePayments, payment);
        result.add(new InvoicePaymentJson(payment, invoiceId, accountAuditLogs));
    }
    return Response.status(Status.OK).entity(result).build();
}
Also used : Account(org.killbill.billing.account.api.Account) InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) InvoicePaymentJson(org.killbill.billing.jaxrs.json.InvoicePaymentJson) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) PluginProperty(org.killbill.billing.payment.api.PluginProperty) InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) Payment(org.killbill.billing.payment.api.Payment) UUID(java.util.UUID) 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 5 with AccountAuditLogs

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

the class SubscriptionResource method getEntitlement.

@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 getEntitlement(@PathParam("subscriptionId") final String subscriptionId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException, AccountApiException, CatalogApiException {
    final UUID uuid = UUID.fromString(subscriptionId);
    final TenantContext context = this.context.createContext(request);
    final Subscription subscription = subscriptionApi.getSubscriptionForEntitlementId(uuid, 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) UUID(java.util.UUID) 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)

Aggregations

AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)55 ApiOperation (io.swagger.annotations.ApiOperation)53 ApiResponses (io.swagger.annotations.ApiResponses)53 GET (javax.ws.rs.GET)53 Produces (javax.ws.rs.Produces)53 TenantContext (org.killbill.billing.util.callcontext.TenantContext)53 TimedResource (org.killbill.commons.metrics.TimedResource)53 Path (javax.ws.rs.Path)47 Account (org.killbill.billing.account.api.Account)26 UUID (java.util.UUID)23 PluginProperty (org.killbill.billing.payment.api.PluginProperty)21 Payment (org.killbill.billing.payment.api.Payment)16 URI (java.net.URI)12 Invoice (org.killbill.billing.invoice.api.Invoice)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 InvoiceJson (org.killbill.billing.jaxrs.json.InvoiceJson)10 PaymentJson (org.killbill.billing.jaxrs.json.PaymentJson)10