use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.
the class TenantResource method getAllPluginConfiguration.
@TimedResource
@GET
@Path("/" + UPLOAD_PER_TENANT_CONFIG + "/{keyPrefix:" + ANYTHING_PATTERN + "}" + "/" + SEARCH)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a per tenant key value based on key prefix", response = TenantKeyJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tenantId supplied") })
public Response getAllPluginConfiguration(@PathParam("keyPrefix") final String keyPrefix, @javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
final TenantContext tenantContext = context.createContext(request);
final Map<String, List<String>> apiResult = tenantApi.searchTenantKeyValues(keyPrefix, tenantContext);
final List<TenantKeyJson> result = new ArrayList<TenantKeyJson>();
for (final String cur : apiResult.keySet()) {
result.add(new TenantKeyJson(cur, apiResult.get(cur)));
}
return Response.status(Status.OK).entity(result).build();
}
use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.
the class TenantResource method getTenantKey.
private Response getTenantKey(final TenantKey key, @Nullable final String keyPostfix, final HttpServletRequest request) throws TenantApiException {
final TenantContext tenantContext = context.createContext(request);
final String tenantKey = keyPostfix != null ? key.toString() + keyPostfix : key.toString();
final List<String> values = tenantApi.getTenantValuesForKey(tenantKey, tenantContext);
final TenantKeyJson result = new TenantKeyJson(tenantKey, values);
return Response.status(Status.OK).entity(result).build();
}
use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.
the class TransactionResource method getPaymentByTransactionId.
@TimedResource(name = "getPaymentByTransactionId")
@GET
@Path("/{transactionId:" + UUID_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment by transaction id", response = PaymentJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Payment not found") })
public Response getPaymentByTransactionId(@PathParam("transactionId") final String transactionIdStr, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final UUID transactionIdId = UUID.fromString(transactionIdStr);
final TenantContext tenantContext = context.createContext(request);
final Payment payment = paymentApi.getPaymentByTransactionId(transactionIdId, withPluginInfo, withAttempts, pluginProperties, tenantContext);
final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext);
final PaymentJson result = new PaymentJson(payment, accountAuditLogs);
return Response.status(Response.Status.OK).entity(result).build();
}
use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.
the class Context method createContext.
public TenantContext createContext(final ServletRequest request) {
final TenantContext tenantContext;
final Tenant tenant = getTenantFromRequest(request);
if (tenant == null) {
// Multi-tenancy may not have been configured - default to "default" tenant (see InternalCallContextFactory)
tenantContext = contextFactory.createTenantContext(null);
} else {
tenantContext = contextFactory.createTenantContext(tenant.getId());
}
populateMDCContext(tenantContext);
return tenantContext;
}
use of org.killbill.billing.util.callcontext.TenantContext in project killbill by killbill.
the class PushNotificationListener method saveRetryPushNotificationInQueue.
private void saveRetryPushNotificationInQueue(final UUID tenantId, final String url, final NotificationJson notificationJson, final int attemptRetryNumber) {
final PushNotificationKey key = new PushNotificationKey(tenantId, notificationJson.getAccountId() != null ? UUID.fromString(notificationJson.getAccountId()) : null, notificationJson.getEventType(), notificationJson.getObjectType(), notificationJson.getObjectId() != null ? UUID.fromString(notificationJson.getObjectId()) : null, attemptRetryNumber + 1, url);
final TenantContext tenantContext = contextFactory.createTenantContext(tenantId);
final DateTime nextNotificationTime = getNextNotificationTime(key.getAttemptNumber(), internalCallContextFactory.createInternalTenantContextWithoutAccountRecordId(tenantContext));
if (nextNotificationTime == null) {
log.warn("Max attempt number reached for push notification url='{}', tenantId='{}'", key.getUrl(), key.getTenantId());
return;
}
log.debug("Push notification is scheduled to send at {} for url='{}', tenantId='{}'", nextNotificationTime, key.getUrl(), key.getTenantId());
final Long accountRecordId = internalCallContextFactory.getRecordIdFromObject(key.getAccountId(), ObjectType.ACCOUNT, tenantContext);
final Long tenantRecordId = internalCallContextFactory.getRecordIdFromObject(key.getTenantId(), ObjectType.TENANT, tenantContext);
try {
final NotificationQueue notificationQueue = notificationQueueService.getNotificationQueue(DefaultServerService.SERVER_SERVICE, PushNotificationRetryService.QUEUE_NAME);
notificationQueue.recordFutureNotification(nextNotificationTime, key, null, MoreObjects.firstNonNull(accountRecordId, new Long(0)), tenantRecordId);
} catch (NoSuchNotificationQueue noSuchNotificationQueue) {
log.error("Failed to push notification url='{}', tenantId='{}'", key.getUrl(), key.getTenantId(), noSuchNotificationQueue);
} catch (IOException e) {
log.error("Failed to push notification url='{}', tenantId='{}'", key.getUrl(), key.getTenantId(), e);
}
}
Aggregations