use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.
the class JaxRsResourceBase method getCustomFields.
protected Response getCustomFields(final UUID id, final AuditMode auditMode, final TenantContext context) {
final List<CustomField> fields = customFieldUserApi.getCustomFieldsForObject(id, getObjectType(), context);
final List<CustomFieldJson> result = new LinkedList<CustomFieldJson>();
for (final CustomField cur : fields) {
// TODO PIERRE - Bulk API
final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(cur.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), context);
result.add(new CustomFieldJson(cur, auditLogs));
}
return Response.status(Response.Status.OK).entity(result).build();
}
use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.
the class TestCustomFieldApi method testCustomFieldForInvoice.
@Test(groups = "slow")
public void testCustomFieldForInvoice() throws CustomFieldApiException, SubscriptionBaseApiException {
//
// Create necessary logic to end up with an Invoice object on that account.
//
final String productName = "Shotgun";
final BillingPeriod term = BillingPeriod.ANNUAL;
final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME;
final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
assertNotNull(bpEntitlement);
final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, false, callContext);
Assert.assertEquals(invoices.size(), 1);
final Invoice invoice = invoices.get(0);
Assert.assertEquals(invoice.getAccountId(), account.getId());
addCustomField("name1", "value1", invoice.getId(), ObjectType.INVOICE, clock.getUTCNow());
addCustomField("name2", "value2", invoice.getId(), ObjectType.INVOICE, clock.getUTCNow());
List<CustomField> fields = customFieldApi.getCustomFieldsForAccount(invoice.getId(), callContext);
Assert.assertEquals(fields.size(), 2);
fields = customFieldApi.getCustomFieldsForAccountType(invoice.getId(), ObjectType.INVOICE, callContext);
Assert.assertEquals(fields.size(), 2);
fields = customFieldApi.getCustomFieldsForObject(invoice.getId(), ObjectType.INVOICE, callContext);
Assert.assertEquals(fields.size(), 2);
//
// Add custom field on account and retry
//
addCustomField("foo", "bar", account.getId(), ObjectType.ACCOUNT, clock.getUTCNow());
fields = customFieldApi.getCustomFieldsForAccount(invoice.getId(), callContext);
Assert.assertEquals(fields.size(), 3);
fields = customFieldApi.getCustomFieldsForAccountType(invoice.getId(), ObjectType.INVOICE, callContext);
Assert.assertEquals(fields.size(), 2);
fields = customFieldApi.getCustomFieldsForObject(invoice.getId(), ObjectType.INVOICE, callContext);
Assert.assertEquals(fields.size(), 2);
}
use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.
the class TestCustomFieldApi method addCustomField.
private void addCustomField(String name, String value, UUID objectId, ObjectType type, DateTime createdDate) throws CustomFieldApiException {
CustomField f = new StringCustomField(name, value, type, objectId, clock.getUTCNow());
busHandler.pushExpectedEvents(NextEvent.CUSTOM_FIELD);
List<CustomField> fields = new ArrayList<CustomField>();
fields.add(f);
customFieldApi.addCustomFields(fields, callContext);
assertListenerStatus();
}
use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.
the class CustomFieldResource method searchCustomFields.
@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search custom fields", response = CustomFieldJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchCustomFields(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws CustomFieldApiException {
final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
final Pagination<CustomField> customFields = customFieldUserApi.searchCustomFields(searchKey, offset, limit, tenantContext);
final URI nextPageUri = uriBuilder.nextPage(CustomFieldResource.class, "searchCustomFields", customFields.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()), ImmutableMap.<String, String>of("searchKey", searchKey));
return buildStreamingPaginationResponse(customFields, new Function<CustomField, CustomFieldJson>() {
@Override
public CustomFieldJson apply(final CustomField customField) {
// TODO Really slow - we should instead try to figure out the account id
final List<AuditLog> auditLogs = auditUserApi.getAuditLogs(customField.getId(), ObjectType.CUSTOM_FIELD, auditMode.getLevel(), tenantContext);
return new CustomFieldJson(customField, auditLogs);
}
}, nextPageUri);
}
use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.
the class AccountResource method getAllCustomFields.
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + ALL_CUSTOM_FIELDS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve account customFields", response = CustomFieldJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response getAllCustomFields(@PathParam(ID_PARAM_NAME) final UUID accountId, @QueryParam(QUERY_OBJECT_TYPE) final ObjectType objectType, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) {
final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request);
final List<CustomField> customFields = objectType != null ? customFieldUserApi.getCustomFieldsForAccountType(accountId, objectType, tenantContext) : customFieldUserApi.getCustomFieldsForAccount(accountId, tenantContext);
return createCustomFieldResponse(customFields, auditMode, tenantContext);
}
Aggregations