Search in sources :

Example 1 with TimedResource

use of org.killbill.commons.metrics.TimedResource 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 2 with TimedResource

use of org.killbill.commons.metrics.TimedResource 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)

Example 3 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class BundleResource method transferBundle.

@TimedResource
@PUT
@Path("/{bundleId:" + UUID_PATTERN + "}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Transfer a bundle to another account")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid bundle id, requested date or policy supplied"), @ApiResponse(code = 404, message = "Bundle not found") })
public Response transferBundle(final BundleJson json, @PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_BILLING_POLICY) @DefaultValue("END_OF_TERM") final String policyString, @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 UriInfo uriInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws EntitlementApiException, SubscriptionApiException, AccountApiException {
    verifyNonNullOrEmpty(json, "BundleJson body should be specified");
    verifyNonNullOrEmpty(json.getAccountId(), "BundleJson accountId needs to be set");
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final BillingActionPolicy policy = BillingActionPolicy.valueOf(policyString.toUpperCase());
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID bundleId = UUID.fromString(id);
    final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, callContext);
    final LocalDate inputLocalDate = toLocalDate(requestedDate);
    final UUID newBundleId = entitlementApi.transferEntitlementsOverrideBillingPolicy(bundle.getAccountId(), UUID.fromString(json.getAccountId()), bundle.getExternalKey(), inputLocalDate, policy, pluginProperties, callContext);
    return uriBuilder.buildResponse(uriInfo, BundleResource.class, "getBundle", newBundleId, request);
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) BillingActionPolicy(org.killbill.billing.catalog.api.BillingActionPolicy) SubscriptionBundle(org.killbill.billing.entitlement.api.SubscriptionBundle) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) LocalDate(org.joda.time.LocalDate) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class BundleResource method getBundles.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List bundles", response = BundleJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getBundles(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Pagination<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundles(offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(BundleResource.class, "getBundles", bundles.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()));
    final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
    return buildStreamingPaginationResponse(bundles, new Function<SubscriptionBundle, BundleJson>() {

        @Override
        public BundleJson apply(final SubscriptionBundle bundle) {
            // Cache audit logs per account
            if (accountsAuditLogs.get().get(bundle.getAccountId()) == null) {
                accountsAuditLogs.get().put(bundle.getAccountId(), auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext));
            }
            try {
                return new BundleJson(bundle, null, accountsAuditLogs.get().get(bundle.getAccountId()));
            } catch (final CatalogApiException unused) {
                // Does not happen because we pass a null Currency
                throw new RuntimeException(unused);
            }
        }
    }, nextPageUri);
}
Also used : TenantContext(org.killbill.billing.util.callcontext.TenantContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) URI(java.net.URI) 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) 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 5 with TimedResource

use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.

the class BundleResource method pauseBundle.

@TimedResource
@PUT
@Path("/{bundleId:" + UUID_PATTERN + "}/" + PAUSE)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Pause a bundle")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid bundle id supplied"), @ApiResponse(code = 404, message = "Bundle not found") })
public Response pauseBundle(@PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @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 SubscriptionApiException, EntitlementApiException, AccountApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID bundleId = UUID.fromString(id);
    final LocalDate inputLocalDate = toLocalDate(requestedDate);
    entitlementApi.pause(bundleId, inputLocalDate, pluginProperties, callContext);
    return Response.status(Status.OK).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) LocalDate(org.joda.time.LocalDate) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)112 TimedResource (org.killbill.commons.metrics.TimedResource)112 ApiResponses (io.swagger.annotations.ApiResponses)111 Produces (javax.ws.rs.Produces)109 Path (javax.ws.rs.Path)95 UUID (java.util.UUID)59 GET (javax.ws.rs.GET)58 TenantContext (org.killbill.billing.util.callcontext.TenantContext)54 Consumes (javax.ws.rs.Consumes)48 CallContext (org.killbill.billing.util.callcontext.CallContext)48 Account (org.killbill.billing.account.api.Account)47 POST (javax.ws.rs.POST)36 PluginProperty (org.killbill.billing.payment.api.PluginProperty)35 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)31 Payment (org.killbill.billing.payment.api.Payment)19 LocalDate (org.joda.time.LocalDate)16 URI (java.net.URI)15 Invoice (org.killbill.billing.invoice.api.Invoice)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)11