use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class TenantResource method insertUserKeyValue.
@TimedResource
@POST
@Path("/" + USER_KEY_VALUE + "/{keyName:" + ANYTHING_PATTERN + "}")
@Consumes(TEXT_PLAIN)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a per tenant user key/value")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tenantId supplied") })
public Response insertUserKeyValue(@PathParam("keyName") final String key, final String value, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws TenantApiException {
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
tenantApi.addTenantKeyValue(key, value, callContext);
return uriBuilder.buildResponse(uriInfo, TenantResource.class, "getUserKeyValue", key, request);
}
use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class TransactionResource method notifyStateChanged.
@TimedResource
@POST
@Path("/{transactionId:" + UUID_PATTERN + "}/")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Mark a pending payment transaction as succeeded or failed")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid paymentId supplied"), @ApiResponse(code = 404, message = "Account or Payment not found") })
public Response notifyStateChanged(final PaymentTransactionJson json, @PathParam("transactionId") final String transactionIdStr, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final UriInfo uriInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException, AccountApiException {
verifyNonNullOrEmpty(json, "PaymentTransactionJson body should be specified");
verifyNonNullOrEmpty(json.getPaymentId(), "PaymentTransactionJson paymentId needs to be set", json.getStatus(), "PaymentTransactionJson status needs to be set");
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final UUID paymentId = UUID.fromString(json.getPaymentId());
final Payment payment = paymentApi.getPayment(paymentId, false, false, ImmutableList.<PluginProperty>of(), callContext);
final Account account = accountUserApi.getAccountById(payment.getAccountId(), callContext);
final boolean success = TransactionStatus.SUCCESS.name().equals(json.getStatus());
final Payment result = paymentApi.notifyPendingTransactionOfStateChanged(account, UUID.fromString(transactionIdStr), success, callContext);
return uriBuilder.buildResponse(uriInfo, PaymentResource.class, "getPayment", result.getId(), request);
}
use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class UsageResource method recordUsage.
@TimedResource
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Record usage for a subscription")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid subscription (e.g. inactive)") })
public Response recordUsage(final SubscriptionUsageRecordJson json, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws EntitlementApiException, AccountApiException, UsageApiException {
verifyNonNullOrEmpty(json, "SubscriptionUsageRecordJson body should be specified");
verifyNonNullOrEmpty(json.getSubscriptionId(), "SubscriptionUsageRecordJson subscriptionId needs to be set", json.getUnitUsageRecords(), "SubscriptionUsageRecordJson unitUsageRecords needs to be set");
Preconditions.checkArgument(!json.getUnitUsageRecords().isEmpty());
for (final UnitUsageRecordJson unitUsageRecordJson : json.getUnitUsageRecords()) {
verifyNonNullOrEmpty(unitUsageRecordJson.getUnitType(), "UnitUsageRecordJson unitType need to be set");
Preconditions.checkArgument(Iterables.size(unitUsageRecordJson.getUsageRecords()) > 0, "UnitUsageRecordJson usageRecords must have at least one element.");
for (final UsageRecordJson usageRecordJson : unitUsageRecordJson.getUsageRecords()) {
verifyNonNull(usageRecordJson.getAmount(), "UsageRecordJson amount needs to be set");
verifyNonNull(usageRecordJson.getRecordDate(), "UsageRecordJson recordDate needs to be set");
}
}
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
// Verify subscription exists..
final Entitlement entitlement = entitlementApi.getEntitlementForId(UUID.fromString(json.getSubscriptionId()), callContext);
if (entitlement.getState() != EntitlementState.ACTIVE) {
return Response.status(Status.BAD_REQUEST).build();
}
final SubscriptionUsageRecord record = json.toSubscriptionUsageRecord();
usageUserApi.recordRolledUpUsage(record, callContext);
return Response.status(Status.CREATED).build();
}
use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class Context method createContext.
public CallContext createContext(final String createdBy, final String reason, final String comment, final ServletRequest request) throws IllegalArgumentException {
try {
Preconditions.checkNotNull(createdBy, String.format("Header %s needs to be set", JaxrsResource.HDR_CREATED_BY));
final Tenant tenant = getTenantFromRequest(request);
final CallContext callContext = contextFactory.createCallContext(tenant == null ? null : tenant.getId(), createdBy, origin, userType, reason, comment, getOrCreateUserToken());
populateMDCContext(callContext);
return callContext;
} catch (final NullPointerException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
use of org.killbill.billing.util.callcontext.CallContext in project killbill by killbill.
the class DefaultEntitlementService method initialize.
@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE)
public void initialize() {
try {
final NotificationQueueHandler queueHandler = new NotificationQueueHandler() {
@Override
public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) {
final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "EntitlementQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken);
if (inputKey instanceof EntitlementNotificationKey) {
final CallContext callContext = internalCallContextFactory.createCallContext(internalCallContext);
processEntitlementNotification((EntitlementNotificationKey) inputKey, internalCallContext, callContext);
} else if (inputKey instanceof BlockingTransitionNotificationKey) {
processBlockingNotification((BlockingTransitionNotificationKey) inputKey, internalCallContext);
} else if (inputKey != null) {
log.error("Entitlement service received an unexpected event className='{}", inputKey.getClass());
} else {
log.error("Entitlement service received an unexpected null event");
}
}
};
entitlementEventQueue = notificationQueueService.createNotificationQueue(ENTITLEMENT_SERVICE_NAME, NOTIFICATION_QUEUE_NAME, queueHandler);
} catch (final NotificationQueueAlreadyExists e) {
throw new RuntimeException(e);
}
}
Aggregations