use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.
the class TenantResource method getUserKeyValue.
@TimedResource
@GET
@Path("/" + USER_KEY_VALUE + "/{keyName:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a per tenant user key/value", response = TenantKeyJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tenantId supplied") })
public Response getUserKeyValue(@PathParam("keyName") final String key, @javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
final TenantContext tenantContext = context.createContext(request);
final List<String> values = tenantApi.getTenantValuesForKey(key, tenantContext);
final TenantKeyJson result = new TenantKeyJson(key, values);
return Response.status(Status.OK).entity(result).build();
}
use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.
the class TestResource method waitForNotificationToComplete.
private boolean waitForNotificationToComplete(final ServletRequest request, final Long timeoutSec) {
final TenantContext tenantContext = context.createContext(request);
final Long tenantRecordId = recordIdApi.getRecordId(tenantContext.getTenantId(), ObjectType.TENANT, tenantContext);
int nbTryLeft = timeoutSec != null ? timeoutSec.intValue() : 0;
boolean areAllNotificationsProcessed = false;
try {
while (!areAllNotificationsProcessed && nbTryLeft > 0) {
areAllNotificationsProcessed = areAllNotificationsProcessed(tenantRecordId);
// Processing of notifications may have triggered bus events, which may trigger other notifications
// effective immediately. Hence, we need to make sure all bus events have been processed too.
areAllNotificationsProcessed = areAllNotificationsProcessed && areAllBusEventsProcessed(tenantRecordId);
// We do a re-check of the notification queues in case of race conditions.
areAllNotificationsProcessed = areAllNotificationsProcessed && areAllNotificationsProcessed(tenantRecordId);
areAllNotificationsProcessed = areAllNotificationsProcessed && areAllBusEventsProcessed(tenantRecordId);
if (!areAllNotificationsProcessed) {
Thread.sleep(MILLIS_IN_SEC);
nbTryLeft--;
}
}
} catch (final InterruptedException ignore) {
}
if (!areAllNotificationsProcessed) {
log.warn("TestResource: there are more notifications or bus events to process, consider increasing the timeout (currently {}s)", timeoutSec);
}
return areAllNotificationsProcessed;
}
use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.
the class TransactionResource method getTags.
@TimedResource
@GET
@Path("/{transactionId:" + UUID_PATTERN + "}/" + TAGS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve payment transaction tags", response = TagJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid transaction 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 Payment payment = paymentApi.getPaymentByTransactionId(UUID.fromString(id), false, false, ImmutableList.<PluginProperty>of(), tenantContext);
return super.getTags(payment.getAccountId(), UUID.fromString(id), auditMode, includedDeleted, tenantContext);
}
use of org.killbill.billing.util.callcontext.TenantContext 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();
}
use of org.killbill.billing.util.callcontext.TenantContext 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();
}
Aggregations