use of org.killbill.billing.jaxrs.json.CatalogJson.ProductJson in project killbill by killbill.
the class CatalogResource method getProductForSubscriptionAndDate.
@TimedResource
@GET
@Path("/product")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve product for a given subscription and date", response = ProductJson.class)
@ApiResponses(value = {})
public Response getProductForSubscriptionAndDate(@QueryParam("subscriptionId") final UUID subscriptionId, @QueryParam("requestedDate") final String requestedDateString, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException {
verifyNonNullOrEmpty(subscriptionId, "Subscription id needs to be specified");
final SubscriptionEvent lastEventBeforeRequestedDate = getLastEventBeforeDate(subscriptionId, requestedDateString, request);
if (lastEventBeforeRequestedDate == null) {
return Response.status(Status.BAD_REQUEST).entity(String.format("%s is before the subscription start date", requestedDateString)).type("text/plain").build();
}
final Product product = lastEventBeforeRequestedDate.getNextProduct();
if (product == null) {
// Subscription was cancelled at that point
return Response.status(Status.BAD_REQUEST).entity(String.format("%s is after the subscription cancel date", requestedDateString)).type("text/plain").build();
}
final ProductJson productJson = new ProductJson(product);
return Response.status(Status.OK).entity(productJson).build();
}
Aggregations