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();
}
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);
}
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);
}
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);
}
Aggregations