use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class SubscriptionResource method uncancelEntitlementPlan.
@TimedResource
@PUT
@Path("/{subscriptionId:" + UUID_PATTERN + "}/uncancel")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Un-cancel an entitlement")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid subscription id supplied"), @ApiResponse(code = 404, message = "Entitlement not found") })
public Response uncancelEntitlementPlan(@PathParam("subscriptionId") final String subscriptionId, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @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) throws EntitlementApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final UUID uuid = UUID.fromString(subscriptionId);
final Entitlement current = entitlementApi.getEntitlementForId(uuid, context.createContext(createdBy, reason, comment, request));
current.uncancelEntitlement(pluginProperties, context.createContext(createdBy, reason, comment, request));
return Response.status(Status.OK).build();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class TagDefinitionResource method getTagDefinitions.
@TimedResource
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List tag definitions", response = TagDefinitionJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getTagDefinitions(@javax.ws.rs.core.Context final HttpServletRequest request, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode) {
final TenantContext tenantContext = context.createContext(request);
final List<TagDefinition> tagDefinitions = tagUserApi.getTagDefinitions(tenantContext);
final Collection<TagDefinitionJson> result = new LinkedList<TagDefinitionJson>();
for (final TagDefinition tagDefinition : tagDefinitions) {
final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tagDefinition.getId(), ObjectType.TAG_DEFINITION, auditMode.getLevel(), tenantContext);
result.add(new TagDefinitionJson(tagDefinition, auditLogs));
}
return Response.status(Status.OK).entity(result).build();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class TagDefinitionResource method getTagDefinition.
@TimedResource
@GET
@Path("/{tagDefinitionId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a tag definition", response = TagDefinitionJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid tagDefinitionId supplied") })
public Response getTagDefinition(@PathParam("tagDefinitionId") final String tagDefId, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws TagDefinitionApiException {
final TenantContext tenantContext = context.createContext(request);
final TagDefinition tagDefinition = tagUserApi.getTagDefinition(UUID.fromString(tagDefId), tenantContext);
final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(tagDefinition.getId(), ObjectType.TAG_DEFINITION, auditMode.getLevel(), tenantContext);
final TagDefinitionJson json = new TagDefinitionJson(tagDefinition, auditLogs);
return Response.status(Status.OK).entity(json).build();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class InvoiceResource method createExternalCharges.
@TimedResource
@POST
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/" + CHARGES + "/{accountId:" + UUID_PATTERN + "}")
@ApiOperation(value = "Create external charge(s)", response = InvoiceItemJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response createExternalCharges(final Iterable<InvoiceItemJson> externalChargesJson, @PathParam("accountId") final String accountId, @QueryParam(QUERY_REQUESTED_DT) final String requestedDateTimeString, @QueryParam(QUERY_PAY_INVOICE) @DefaultValue("false") final Boolean payInvoice, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUTO_COMMIT) @DefaultValue("false") final Boolean autoCommit, @QueryParam(QUERY_PAYMENT_EXTERNAL_KEY) final String paymentExternalKey, @QueryParam(QUERY_TRANSACTION_EXTERNAL_KEY) final String transactionExternalKey, @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 AccountApiException, InvoiceApiException, PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), callContext);
final Iterable<InvoiceItem> sanitizedExternalChargesJson = validateSanitizeAndTranformInputItems(account.getCurrency(), externalChargesJson);
// Get the effective date of the external charge, in the account timezone
final LocalDate requestedDate = toLocalDateDefaultToday(account, requestedDateTimeString, callContext);
final List<InvoiceItem> createdExternalCharges = invoiceApi.insertExternalCharges(account.getId(), requestedDate, sanitizedExternalChargesJson, autoCommit, callContext);
// if all createdExternalCharges point to the same invoiceId, use the provided paymentExternalKey and / or transactionExternalKey
final boolean haveSameInvoiceId = Iterables.all(createdExternalCharges, new Predicate<InvoiceItem>() {
@Override
public boolean apply(final InvoiceItem input) {
return input.getInvoiceId().equals(createdExternalCharges.get(0).getInvoiceId());
}
});
if (payInvoice) {
final Collection<UUID> paidInvoices = new HashSet<UUID>();
for (final InvoiceItem externalCharge : createdExternalCharges) {
if (!paidInvoices.contains(externalCharge.getInvoiceId())) {
paidInvoices.add(externalCharge.getInvoiceId());
final Invoice invoice = invoiceApi.getInvoice(externalCharge.getInvoiceId(), callContext);
createPurchaseForInvoice(account, invoice.getId(), invoice.getBalance(), account.getPaymentMethodId(), false, (haveSameInvoiceId && paymentExternalKey != null) ? paymentExternalKey : null, (haveSameInvoiceId && transactionExternalKey != null) ? transactionExternalKey : null, pluginProperties, callContext);
}
}
}
final List<InvoiceItemJson> createdExternalChargesJson = Lists.<InvoiceItem, InvoiceItemJson>transform(createdExternalCharges, new Function<InvoiceItem, InvoiceItemJson>() {
@Override
public InvoiceItemJson apply(final InvoiceItem input) {
return new InvoiceItemJson(input);
}
});
return Response.status(Status.OK).entity(createdExternalChargesJson).build();
}
use of org.killbill.commons.metrics.TimedResource in project killbill by killbill.
the class InvoiceResource method getInvoice.
@TimedResource
@GET
@Path("/{invoiceId:" + UUID_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an invoice by id", response = InvoiceJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid invoice id supplied"), @ApiResponse(code = 404, message = "Invoice not found") })
public Response getInvoice(@PathParam("invoiceId") final String invoiceId, @QueryParam(QUERY_INVOICE_WITH_ITEMS) @DefaultValue("false") final boolean withItems, @QueryParam(QUERY_INVOICE_WITH_CHILDREN_ITEMS) @DefaultValue("false") final boolean withChildrenItems, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException {
final TenantContext tenantContext = context.createContext(request);
final Invoice invoice = invoiceApi.getInvoice(UUID.fromString(invoiceId), tenantContext);
final List<InvoiceItem> childInvoiceItems = withChildrenItems ? invoiceApi.getInvoiceItemsByParentInvoice(invoice.getId(), tenantContext) : null;
final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext);
if (invoice == null) {
throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceId);
} else {
final InvoiceJson json = new InvoiceJson(invoice, withItems, childInvoiceItems, accountAuditLogs);
return Response.status(Status.OK).entity(json).build();
}
}
Aggregations