Search in sources :

Example 1 with RolledUpUsageJson

use of org.killbill.billing.jaxrs.json.RolledUpUsageJson in project killbill by killbill.

the class UsageResource method getUsage.

@TimedResource
@GET
@Path("/{subscriptionId:" + UUID_PATTERN + "}/{unitType}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve usage for a subscription and unit type", response = RolledUpUsageJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Missing start date or end date") })
public Response getUsage(@PathParam("subscriptionId") final String subscriptionId, @PathParam("unitType") final String unitType, @QueryParam(QUERY_START_DATE) final String startDate, @QueryParam(QUERY_END_DATE) final String endDate, @javax.ws.rs.core.Context final HttpServletRequest request) {
    if (startDate == null || endDate == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    final TenantContext tenantContext = context.createContext(request);
    final LocalDate usageStartDate = LOCAL_DATE_FORMATTER.parseLocalDate(startDate);
    final LocalDate usageEndDate = LOCAL_DATE_FORMATTER.parseLocalDate(endDate);
    final RolledUpUsage usage = usageUserApi.getUsageForSubscription(UUID.fromString(subscriptionId), unitType, usageStartDate, usageEndDate, tenantContext);
    final RolledUpUsageJson result = new RolledUpUsageJson(usage);
    return Response.status(Status.OK).entity(result).build();
}
Also used : RolledUpUsageJson(org.killbill.billing.jaxrs.json.RolledUpUsageJson) RolledUpUsage(org.killbill.billing.usage.api.RolledUpUsage) TenantContext(org.killbill.billing.util.callcontext.TenantContext) LocalDate(org.joda.time.LocalDate) 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 2 with RolledUpUsageJson

use of org.killbill.billing.jaxrs.json.RolledUpUsageJson in project killbill by killbill.

the class UsageResource method getAllUsage.

@TimedResource
@GET
@Path("/{subscriptionId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve usage for a subscription", response = RolledUpUsageJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Missing start date or end date") })
public Response getAllUsage(@PathParam("subscriptionId") final String subscriptionId, @QueryParam(QUERY_START_DATE) final String startDate, @QueryParam(QUERY_END_DATE) final String endDate, @javax.ws.rs.core.Context final HttpServletRequest request) {
    if (startDate == null || endDate == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    final TenantContext tenantContext = context.createContext(request);
    final LocalDate usageStartDate = LOCAL_DATE_FORMATTER.parseLocalDate(startDate);
    final LocalDate usageEndDate = LOCAL_DATE_FORMATTER.parseLocalDate(endDate);
    // The current JAXRS API only allows to look for one transition
    final List<LocalDate> startEndDate = ImmutableList.<LocalDate>builder().add(usageStartDate).add(usageEndDate).build();
    final List<RolledUpUsage> usage = usageUserApi.getAllUsageForSubscription(UUID.fromString(subscriptionId), startEndDate, tenantContext);
    final RolledUpUsageJson result = new RolledUpUsageJson(usage.get(0));
    return Response.status(Status.OK).entity(result).build();
}
Also used : RolledUpUsageJson(org.killbill.billing.jaxrs.json.RolledUpUsageJson) RolledUpUsage(org.killbill.billing.usage.api.RolledUpUsage) TenantContext(org.killbill.billing.util.callcontext.TenantContext) LocalDate(org.joda.time.LocalDate) 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)2 ApiResponses (io.swagger.annotations.ApiResponses)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 LocalDate (org.joda.time.LocalDate)2 RolledUpUsageJson (org.killbill.billing.jaxrs.json.RolledUpUsageJson)2 RolledUpUsage (org.killbill.billing.usage.api.RolledUpUsage)2 TenantContext (org.killbill.billing.util.callcontext.TenantContext)2 TimedResource (org.killbill.commons.metrics.TimedResource)2