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();
}
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();
}
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;
}
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());
* */
}
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);
}
}
Aggregations