Search in sources :

Example 61 with Path

use of javax.ws.rs.Path 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 62 with Path

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

the class AccountResource method payAllInvoices.

@TimedResource
@POST
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/{accountId:" + UUID_PATTERN + "}/" + INVOICE_PAYMENTS)
@ApiOperation(value = "Trigger a payment for all unpaid invoices")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response payAllInvoices(@PathParam("accountId") final String accountId, @QueryParam(QUERY_PAYMENT_EXTERNAL) @DefaultValue("false") final Boolean externalPayment, @QueryParam(QUERY_PAYMENT_AMOUNT) final BigDecimal paymentAmount, @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, InvoiceApiException {
    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 Collection<Invoice> unpaidInvoices = invoiceApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext);
    BigDecimal remainingRequestPayment = paymentAmount;
    if (remainingRequestPayment == null) {
        remainingRequestPayment = BigDecimal.ZERO;
        for (final Invoice invoice : unpaidInvoices) {
            remainingRequestPayment = remainingRequestPayment.add(invoice.getBalance());
        }
    }
    for (final Invoice invoice : unpaidInvoices) {
        final BigDecimal amountToPay = (remainingRequestPayment.compareTo(invoice.getBalance()) >= 0) ? invoice.getBalance() : remainingRequestPayment;
        if (amountToPay.compareTo(BigDecimal.ZERO) > 0) {
            final UUID paymentMethodId = externalPayment ? null : account.getPaymentMethodId();
            createPurchaseForInvoice(account, invoice.getId(), amountToPay, paymentMethodId, externalPayment, null, null, pluginProperties, callContext);
        }
        remainingRequestPayment = remainingRequestPayment.subtract(amountToPay);
        if (remainingRequestPayment.compareTo(BigDecimal.ZERO) == 0) {
            break;
        }
    }
    //
    if (externalPayment && remainingRequestPayment.compareTo(BigDecimal.ZERO) > 0) {
        invoiceApi.insertCredit(account.getId(), remainingRequestPayment, clock.getUTCToday(), account.getCurrency(), true, "pay all invoices", callContext);
    }
    return Response.status(Status.OK).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) BigDecimal(java.math.BigDecimal) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 63 with Path

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

the class AbstractJsonapiResource method storeJsonapiCollection.

/**
     * Replace an item in the collection. Input Content-Type is
     * application/vnd.api+json Output Content-Type is application/vnd.api+json
     *
     * The input item must be wrapped in a collection. The output item is always
     * wrapped in a collection.
     *
     * @param locator
     * @param collection
     * @return
     */
@Path("/{id}")
@PUT
@Consumes(DataMediaType.APPLICATION_VND_API_JSON)
@Produces(DataMediaType.APPLICATION_VND_API_JSON)
public C storeJsonapiCollection(@BeanParam L locator, C collection) {
    // misnomer, what we really mean is "store one but wrapped ina  collection for jsonapi"
    log.debug("storeCollection");
    ValidationUtil.validate(collection);
    List<T> list = collection.getDocuments();
    if (list == null || list.isEmpty()) {
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }
    T item = list.get(0);
    locator.copyTo(item);
    if (item == null) {
        getRepository().create(item);
    } else {
        getRepository().store(item);
    }
    return collection;
}
Also used : POST(javax.ws.rs.POST) GET(javax.ws.rs.GET) PUT(javax.ws.rs.PUT) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 64 with Path

use of javax.ws.rs.Path 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)

Example 65 with Path

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

the class Host method get.

/**
     * Returns the trust status of a host.
     * 
     * Sample request:
     * GET http://localhost:8080/AttestationService/resources/hosts/trust?hostName=Some+TXT+Host
     * 
     * Sample output for untrusted host:
     * BIOS:0,VMM:0
     * 
     * Sample output for trusted host:
     * BIOS:1,VMM:1
     * 
     * @param hostName unique name of the host to query
     * @return a string like BIOS:0,VMM:0 representing the trust status
     */
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("/trust")
public HostTrustResponse get(@QueryParam("hostName") String hostName) {
    try {
        // 0.5.1 returned MediaType.TEXT_PLAIN string like "BIOS:0,VMM:0" :  return new HostTrustBO().getTrustStatusString(new Hostname(hostName)); // datatype.Hostname            
        Hostname hostname = new Hostname(hostName);
        HostTrustStatus trust = new ASComponentFactory().getHostTrustBO().getTrustStatus(hostname);
        return new HostTrustResponse(hostname, trust);
    } catch (ASException e) {
        throw e;
    } catch (Exception e) {
        throw new ASException(e);
    }
}
Also used : ASComponentFactory(com.intel.mtwilson.as.helper.ASComponentFactory) Hostname(com.intel.mtwilson.util.net.Hostname) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Path (javax.ws.rs.Path)6273 Produces (javax.ws.rs.Produces)3678 GET (javax.ws.rs.GET)3072 POST (javax.ws.rs.POST)1783 Consumes (javax.ws.rs.Consumes)1440 ApiOperation (io.swagger.annotations.ApiOperation)1213 ApiResponses (io.swagger.annotations.ApiResponses)997 PUT (javax.ws.rs.PUT)850 IOException (java.io.IOException)677 DELETE (javax.ws.rs.DELETE)662 ArrayList (java.util.ArrayList)591 WebApplicationException (javax.ws.rs.WebApplicationException)556 Response (javax.ws.rs.core.Response)540 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)490 HashMap (java.util.HashMap)394 Timed (com.codahale.metrics.annotation.Timed)383 URI (java.net.URI)374 List (java.util.List)287 Map (java.util.Map)259 NotFoundException (javax.ws.rs.NotFoundException)258