use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class AccountResource method getAccount.
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an account by id", response = AccountJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getAccount(@PathParam("accountId") final String accountId, @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 Account account = accountUserApi.getAccountById(UUID.fromString(accountId), 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();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class AccountResource method setDefaultPaymentMethod.
@TimedResource
@PUT
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS + "/{paymentMethodId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS_DEFAULT_PATH_POSTFIX)
@ApiOperation(value = "Set the default payment method")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id or payment method id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response setDefaultPaymentMethod(@PathParam("accountId") final String accountId, @PathParam("paymentMethodId") final String paymentMethodId, @QueryParam(QUERY_PAY_ALL_UNPAID_INVOICES) @DefaultValue("false") final Boolean payAllUnpaidInvoices, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), callContext);
final UUID newPaymentMethodId = UUID.fromString(paymentMethodId);
paymentApi.setDefaultPaymentMethod(account, newPaymentMethodId, pluginProperties, callContext);
if (payAllUnpaidInvoices) {
final Collection<Invoice> unpaidInvoices = invoiceApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext);
for (final Invoice invoice : unpaidInvoices) {
createPurchaseForInvoice(account, invoice.getId(), invoice.getBalance(), newPaymentMethodId, false, null, null, pluginProperties, callContext);
}
}
return Response.status(Status.OK).build();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class AccountResource method rebalanceExistingCBAOnAccount.
/*
* ************************** INVOICE CBA REBALANCING ********************************
*/
@TimedResource
@POST
@Path("/{accountId:" + UUID_PATTERN + "}/" + CBA_REBALANCING)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Rebalance account CBA")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied") })
public Response rebalanceExistingCBAOnAccount(@PathParam("accountId") final String accountIdString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException {
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final UUID accountId = UUID.fromString(accountIdString);
invoiceApi.consumeExstingCBAOnAccountWithUnpaidInvoices(accountId, callContext);
return Response.status(Status.OK).build();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class AccountResource method getPayments.
/*
* ************************* PAYMENTS *****************************
*/
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENTS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account payments", response = PaymentJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied") })
public Response getPayments(@PathParam("accountId") final String accountIdStr, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
final UUID accountId = UUID.fromString(accountIdStr);
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final TenantContext tenantContext = context.createContext(request);
final List<Payment> payments = paymentApi.getAccountPayments(accountId, withPluginInfo, withAttempts, pluginProperties, tenantContext);
final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(accountId, auditMode.getLevel(), tenantContext);
final List<PaymentJson> result = ImmutableList.copyOf(Iterables.transform(payments, new Function<Payment, PaymentJson>() {
@Override
public PaymentJson apply(final Payment payment) {
return new PaymentJson(payment, accountAuditLogs);
}
}));
return Response.status(Response.Status.OK).entity(result).build();
}
use of org.killbill.commons.metrics.TimedResource 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(@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.createContext(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();
}
Aggregations