Search in sources :

Example 71 with GET

use of javax.ws.rs.GET 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 72 with GET

use of javax.ws.rs.GET in project killbill by killbill.

the class AccountResource method getEmails.

/*
     * *************************     EMAILS     *****************************
     */
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + EMAILS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an account emails", response = AccountEmailJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied") })
public Response getEmails(@PathParam(ID_PARAM_NAME) final String id, @javax.ws.rs.core.Context final HttpServletRequest request) {
    final UUID accountId = UUID.fromString(id);
    final List<AccountEmail> emails = accountUserApi.getEmails(accountId, context.createContext(request));
    final List<AccountEmailJson> emailsJson = new ArrayList<AccountEmailJson>();
    for (final AccountEmail email : emails) {
        emailsJson.add(new AccountEmailJson(email.getAccountId().toString(), email.getEmail()));
    }
    return Response.status(Status.OK).entity(emailsJson).build();
}
Also used : AccountEmailJson(org.killbill.billing.jaxrs.json.AccountEmailJson) AccountEmail(org.killbill.billing.account.api.AccountEmail) ArrayList(java.util.ArrayList) 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 73 with GET

use of javax.ws.rs.GET in project killbill by killbill.

the class AccountResource method getEmailNotificationsForAccount.

/*
    * ************************** EMAIL NOTIFICATIONS FOR INVOICES ********************************
    */
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + EMAIL_NOTIFICATIONS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account email notification", response = InvoiceEmailJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getEmailNotificationsForAccount(@PathParam("accountId") final String accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException {
    final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), context.createContext(request));
    final InvoiceEmailJson invoiceEmailJson = new InvoiceEmailJson(accountId, account.isNotifiedForInvoices());
    return Response.status(Status.OK).entity(invoiceEmailJson).build();
}
Also used : Account(org.killbill.billing.account.api.Account) InvoiceEmailJson(org.killbill.billing.jaxrs.json.InvoiceEmailJson) 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 74 with GET

use of javax.ws.rs.GET in project killbill by killbill.

the class AccountResource method getAccounts.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List accounts", response = AccountJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getAccounts(@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.getAccounts(offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(AccountResource.class, "getAccounts", accounts.getNextOffset(), limit, ImmutableMap.<String, String>of(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 75 with GET

use of javax.ws.rs.GET in project OpenAttestation by OpenAttestation.

the class AbstractSimpleResource method deleteOne.

//    /**
//     * Add an item to the collection. Input Content-Type is any of
//     * application/json, application/xml, application/yaml, or text/yaml Output
//     * Content-Type is any of application/json, application/xml,
//     * application/yaml, or text/yaml
//     *
//     * The input must represent a single item NOT wrapped in a collection.
//     *
//     * @param item
//     * @return
//     */
//    @POST
//    public T createOne(@BeanParam L locator, T item, @Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse){
//        //try { log.debug("createOne: {}", mapper.writeValueAsString(locator)); } catch(JsonProcessingException e) { log.debug("createOne: cannot serialize locator: {}", e.getMessage()); }
//        try { log.debug("createOne: {}", mapper.writeValueAsString(locator)); } catch(Exception e) { log.debug("createOne: cannot serialize locator: {}", e.getMessage()); }
//        locator.copyTo(item);
//        ValidationUtil.validate(item); // throw new MWException(e, ErrorCode.AS_INPUT_VALIDATION_ERROR, input, method.getName());
//        if (item.getId() == null) {
//            item.setId(new UUID());
//        }
//        getRepository().create(item);
//        httpServletResponse.setStatus(Status.CREATED.getStatusCode());
//        return item;
//    }
// the delete method is on a specific resource id and because we don't return any content it's the same whether its simple object or json api 
// jersey automatically returns status code 204 No Content (successful) to the client because
// we have a void return type
@Path("/{id}")
@DELETE
public void deleteOne(@BeanParam L locator, @Context HttpServletRequest httpServletRequest, @Context HttpServletResponse httpServletResponse) throws IOException {
    try {
        log.debug("deleteOne: {}", mapper.writeValueAsString(locator));
    } catch (JsonProcessingException e) {
        log.debug("deleteOne: cannot serialize locator: {}", e.getMessage());
    }
    // subclass is responsible for validating the id in whatever manner it needs to;  most will return null if !UUID.isValid(id)  but we don't do it here because a resource might want to allow using something other than uuid as the url key, for example uuid OR hostname for hosts
    T item = getRepository().retrieve(locator);
    if (item == null) {
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    getRepository().delete(locator);
    httpServletResponse.setStatus(Status.NO_CONTENT.getStatusCode());
/*
        T item = getRepository().retrieve(id); // subclass is responsible for validating the id in whatever manner it needs to;  most will return null if !UUID.isValid(id)  but we don't do it here because a resource might want to allow using something other than uuid as the url key, for example uuid OR hostname for hosts
        if (item == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND); 
        }
        getRepository().delete(id);*/
/*
//        C collection = getRepository().search(selector);
//        if( collection.getDocuments().isEmpty() ) {            
//            throw new WebApplicationException(Response.Status.NOT_FOUND); 
//        }
//        T item = collection.getDocuments().get(0);
        
//        getRepository().delete(item.getId().toString());
* */
}
Also used : GET(javax.ws.rs.GET) POST(javax.ws.rs.POST) PUT(javax.ws.rs.PUT) WebApplicationException(javax.ws.rs.WebApplicationException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

GET (javax.ws.rs.GET)1140 Path (javax.ws.rs.Path)902 Produces (javax.ws.rs.Produces)734 ApiOperation (io.swagger.annotations.ApiOperation)230 ApiResponses (io.swagger.annotations.ApiResponses)163 IOException (java.io.IOException)139 Response (javax.ws.rs.core.Response)116 WebApplicationException (javax.ws.rs.WebApplicationException)113 Timed (com.codahale.metrics.annotation.Timed)103 ArrayList (java.util.ArrayList)100 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)91 List (java.util.List)83 Map (java.util.Map)80 HashMap (java.util.HashMap)78 URI (java.net.URI)70 TimedResource (org.killbill.commons.metrics.TimedResource)58 TenantContext (org.killbill.billing.util.callcontext.TenantContext)57 ApiResponse (io.swagger.annotations.ApiResponse)52 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)39 Consumes (javax.ws.rs.Consumes)36