Search in sources :

Example 41 with TenantContext

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();
}
Also used : ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) List(java.util.List) ArrayList(java.util.ArrayList) TenantKeyJson(org.killbill.billing.jaxrs.json.TenantKeyJson) 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 42 with TenantContext

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();
}
Also used : TenantContext(org.killbill.billing.util.callcontext.TenantContext) TenantKeyJson(org.killbill.billing.jaxrs.json.TenantKeyJson)

Example 43 with TenantContext

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();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Payment(org.killbill.billing.payment.api.Payment) TenantContext(org.killbill.billing.util.callcontext.TenantContext) PaymentJson(org.killbill.billing.jaxrs.json.PaymentJson) UUID(java.util.UUID) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) 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 44 with TenantContext

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;
}
Also used : Tenant(org.killbill.billing.tenant.api.Tenant) TenantContext(org.killbill.billing.util.callcontext.TenantContext)

Example 45 with 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);
    }
}
Also used : NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantContext(org.killbill.billing.util.callcontext.TenantContext) NotificationQueue(org.killbill.notificationq.api.NotificationQueue) NoSuchNotificationQueue(org.killbill.notificationq.api.NotificationQueueService.NoSuchNotificationQueue) IOException(java.io.IOException) DateTime(org.joda.time.DateTime)

Aggregations

TenantContext (org.killbill.billing.util.callcontext.TenantContext)69 ApiOperation (io.swagger.annotations.ApiOperation)58 ApiResponses (io.swagger.annotations.ApiResponses)58 Produces (javax.ws.rs.Produces)58 GET (javax.ws.rs.GET)57 TimedResource (org.killbill.commons.metrics.TimedResource)54 Path (javax.ws.rs.Path)51 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)31 UUID (java.util.UUID)30 Account (org.killbill.billing.account.api.Account)17 PluginProperty (org.killbill.billing.payment.api.PluginProperty)15 URI (java.net.URI)14 Payment (org.killbill.billing.payment.api.Payment)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Invoice (org.killbill.billing.invoice.api.Invoice)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 Map (java.util.Map)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 List (java.util.List)7