Search in sources :

Example 41 with ApiOperation

use of io.swagger.annotations.ApiOperation in project killbill by killbill.

the class InvoiceResource method getInvoice.

@TimedResource
@GET
@Path("/{invoiceId:" + UUID_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an invoice by id", response = InvoiceJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid invoice id supplied"), @ApiResponse(code = 404, message = "Invoice not found") })
public Response getInvoice(@PathParam("invoiceId") final String invoiceId, @QueryParam(QUERY_INVOICE_WITH_ITEMS) @DefaultValue("false") final boolean withItems, @QueryParam(QUERY_INVOICE_WITH_CHILDREN_ITEMS) @DefaultValue("false") final boolean withChildrenItems, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException {
    final TenantContext tenantContext = context.createContext(request);
    final Invoice invoice = invoiceApi.getInvoice(UUID.fromString(invoiceId), tenantContext);
    final List<InvoiceItem> childInvoiceItems = withChildrenItems ? invoiceApi.getInvoiceItemsByParentInvoice(invoice.getId(), tenantContext) : null;
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext);
    if (invoice == null) {
        throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceId);
    } else {
        final InvoiceJson json = new InvoiceJson(invoice, withItems, childInvoiceItems, accountAuditLogs);
        return Response.status(Status.OK).entity(json).build();
    }
}
Also used : InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) Invoice(org.killbill.billing.invoice.api.Invoice) InvoiceItem(org.killbill.billing.invoice.api.InvoiceItem) InvoiceJson(org.killbill.billing.jaxrs.json.InvoiceJson) 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 42 with ApiOperation

use of io.swagger.annotations.ApiOperation in project killbill by killbill.

the class PaymentResource method searchPayments.

@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search payments", response = PaymentJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchPayments(@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_PAYMENT_PLUGIN_NAME) final String pluginName, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @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, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final TenantContext tenantContext = context.createContext(request);
    // Search the plugin(s)
    final Pagination<Payment> payments;
    if (Strings.isNullOrEmpty(pluginName)) {
        payments = paymentApi.searchPayments(searchKey, offset, limit, withPluginInfo, withAttempts, pluginProperties, tenantContext);
    } else {
        payments = paymentApi.searchPayments(searchKey, offset, limit, pluginName, withPluginInfo, withAttempts, pluginProperties, tenantContext);
    }
    final URI nextPageUri = uriBuilder.nextPage(PaymentResource.class, "searchPayments", payments.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_PAYMENT_METHOD_PLUGIN_NAME, Strings.nullToEmpty(pluginName), QUERY_AUDIT, auditMode.getLevel().toString()));
    final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
    return buildStreamingPaginationResponse(payments, new Function<Payment, PaymentJson>() {

        @Override
        public PaymentJson apply(final Payment payment) {
            // Cache audit logs per account
            if (accountsAuditLogs.get().get(payment.getAccountId()) == null) {
                accountsAuditLogs.get().put(payment.getAccountId(), auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext));
            }
            final AccountAuditLogs accountAuditLogs = accountsAuditLogs.get().get(payment.getAccountId());
            return new PaymentJson(payment, accountAuditLogs);
        }
    }, nextPageUri);
}
Also used : TenantContext(org.killbill.billing.util.callcontext.TenantContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) URI(java.net.URI) PluginProperty(org.killbill.billing.payment.api.PluginProperty) Payment(org.killbill.billing.payment.api.Payment) PaymentJson(org.killbill.billing.jaxrs.json.PaymentJson) 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 43 with ApiOperation

use of io.swagger.annotations.ApiOperation in project killbill by killbill.

the class PaymentResource method cancelScheduledPaymentTransactionById.

@TimedResource(name = "cancelScheduledPaymentTransaction")
@DELETE
@Path("/{paymentTransactionId:" + UUID_PATTERN + "}/" + CANCEL_SCHEDULED_PAYMENT_TRANSACTION)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Cancels a scheduled payment attempt retry")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid paymentTransactionId supplied") })
public Response cancelScheduledPaymentTransactionById(@PathParam("paymentTransactionId") final String paymentTransactionId, @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 PaymentApiException, AccountApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    paymentApi.cancelScheduledPaymentTransaction(UUID.fromString(paymentTransactionId), callContext);
    return Response.status(Status.OK).build();
}
Also used : CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 44 with ApiOperation

use of io.swagger.annotations.ApiOperation in project killbill by killbill.

the class PaymentResource method cancelScheduledPaymentTransactionByExternalKey.

@TimedResource(name = "cancelScheduledPaymentTransaction")
@DELETE
@Path("/" + CANCEL_SCHEDULED_PAYMENT_TRANSACTION)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Cancels a scheduled payment attempt retry")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid paymentTransactionExternalKey supplied") })
public Response cancelScheduledPaymentTransactionByExternalKey(@QueryParam(QUERY_TRANSACTION_EXTERNAL_KEY) final String paymentTransactionExternalKey, @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 PaymentApiException, AccountApiException {
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    paymentApi.cancelScheduledPaymentTransaction(paymentTransactionExternalKey, callContext);
    return Response.status(Status.OK).build();
}
Also used : CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 45 with ApiOperation

use of io.swagger.annotations.ApiOperation in project killbill by killbill.

the class PaymentResource method getTags.

@TimedResource
@GET
@Path("/{paymentId:" + UUID_PATTERN + "}/" + TAGS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve payment payment tags", response = TagJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid payment id supplied"), @ApiResponse(code = 404, message = "Invoice not found") })
public Response getTags(@PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @QueryParam(QUERY_TAGS_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException, PaymentApiException {
    final TenantContext tenantContext = context.createContext(request);
    final UUID paymentId = UUID.fromString(id);
    final Payment payment = paymentApi.getPayment(paymentId, false, false, ImmutableList.<PluginProperty>of(), tenantContext);
    return super.getTags(payment.getAccountId(), paymentId, auditMode, includedDeleted, tenantContext);
}
Also used : Payment(org.killbill.billing.payment.api.Payment) TenantContext(org.killbill.billing.util.callcontext.TenantContext) 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)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)680 ApiResponses (io.swagger.annotations.ApiResponses)499 Path (javax.ws.rs.Path)409 Produces (javax.ws.rs.Produces)280 Timed (com.codahale.metrics.annotation.Timed)255 GET (javax.ws.rs.GET)237 POST (javax.ws.rs.POST)149 Consumes (javax.ws.rs.Consumes)134 TimedResource (org.killbill.commons.metrics.TimedResource)112 Counted (com.codahale.metrics.annotation.Counted)107 AuditEvent (org.graylog2.audit.jersey.AuditEvent)99 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)94 ApiResponse (io.swagger.annotations.ApiResponse)87 PUT (javax.ws.rs.PUT)84 Response (javax.ws.rs.core.Response)81 DELETE (javax.ws.rs.DELETE)77 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)68 URI (java.net.URI)62 UUID (java.util.UUID)62 TenantContext (org.killbill.billing.util.callcontext.TenantContext)58