Search in sources :

Example 1 with CustomField

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();
}
Also used : StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) CustomFieldJson(org.killbill.billing.jaxrs.json.CustomFieldJson) LinkedList(java.util.LinkedList) AuditLog(org.killbill.billing.util.audit.AuditLog)

Example 2 with CustomField

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);
}
Also used : Invoice(org.killbill.billing.invoice.api.Invoice) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) Test(org.testng.annotations.Test)

Example 3 with CustomField

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();
}
Also used : StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) StringCustomField(org.killbill.billing.util.customfield.StringCustomField) ArrayList(java.util.ArrayList)

Example 4 with CustomField

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);
}
Also used : CustomField(org.killbill.billing.util.customfield.CustomField) TenantContext(org.killbill.billing.util.callcontext.TenantContext) List(java.util.List) CustomFieldJson(org.killbill.billing.jaxrs.json.CustomFieldJson) URI(java.net.URI) 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 5 with CustomField

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

Aggregations

CustomField (org.killbill.billing.util.customfield.CustomField)17 StringCustomField (org.killbill.billing.util.customfield.StringCustomField)13 CustomFieldJson (org.killbill.billing.jaxrs.json.CustomFieldJson)7 Test (org.testng.annotations.Test)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 TenantContext (org.killbill.billing.util.callcontext.TenantContext)4 TimedResource (org.killbill.commons.metrics.TimedResource)4 URI (java.net.URI)3 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)3 CustomFieldApiException (org.killbill.billing.util.api.CustomFieldApiException)3 AuditLog (org.killbill.billing.util.audit.AuditLog)2 CustomFieldModelDao (org.killbill.billing.util.customfield.dao.CustomFieldModelDao)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1