Search in sources :

Example 1 with CustomFieldJson

use of org.killbill.billing.jaxrs.json.CustomFieldJson 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 CustomFieldJson

use of org.killbill.billing.jaxrs.json.CustomFieldJson 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.createContext(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("searchKey", searchKey, QUERY_AUDIT, auditMode.getLevel().toString()));
    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 3 with CustomFieldJson

use of org.killbill.billing.jaxrs.json.CustomFieldJson in project killbill by killbill.

the class CustomFieldResource method getCustomFields.

@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List custom fields", response = CustomFieldJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getCustomFields(@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.createContext(request);
    final Pagination<CustomField> customFields = customFieldUserApi.getCustomFields(offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(CustomFieldResource.class, "getCustomFields", customFields.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()));
    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 4 with CustomFieldJson

use of org.killbill.billing.jaxrs.json.CustomFieldJson in project killbill by killbill.

the class JaxRsResourceBase method createCustomFields.

protected Response createCustomFields(final UUID id, final List<CustomFieldJson> customFields, final CallContext context, final UriInfo uriInfo, final HttpServletRequest request) throws CustomFieldApiException {
    final LinkedList<CustomField> input = new LinkedList<CustomField>();
    for (final CustomFieldJson cur : customFields) {
        verifyNonNullOrEmpty(cur.getName(), "CustomFieldJson name needs to be set");
        verifyNonNullOrEmpty(cur.getValue(), "CustomFieldJson value needs to be set");
        input.add(new StringCustomField(cur.getName(), cur.getValue(), getObjectType(), id, context.getCreatedDate()));
    }
    customFieldUserApi.addCustomFields(input, context);
    return uriBuilder.buildResponse(uriInfo, this.getClass(), "getCustomFields", id, request);
}
Also used : StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomFieldJson(org.killbill.billing.jaxrs.json.CustomFieldJson) LinkedList(java.util.LinkedList)

Aggregations

CustomFieldJson (org.killbill.billing.jaxrs.json.CustomFieldJson)4 CustomField (org.killbill.billing.util.customfield.CustomField)4 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 TenantContext (org.killbill.billing.util.callcontext.TenantContext)2 StringCustomField (org.killbill.billing.util.customfield.StringCustomField)2 TimedResource (org.killbill.commons.metrics.TimedResource)2 AuditLog (org.killbill.billing.util.audit.AuditLog)1