Search in sources :

Example 6 with CustomField

use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.

the class JaxRsResourceBase method modifyCustomFields.

protected Response modifyCustomFields(final UUID id, final List<CustomFieldJson> customFields, final CallContext context) throws CustomFieldApiException {
    final LinkedList<CustomField> input = new LinkedList<CustomField>();
    for (final CustomFieldJson cur : customFields) {
        verifyNonNullOrEmpty(cur.getCustomFieldId(), "CustomFieldJson id needs to be set");
        verifyNonNullOrEmpty(cur.getValue(), "CustomFieldJson value needs to be set");
        input.add(new StringCustomField(cur.getCustomFieldId(), cur.getName(), cur.getValue(), getObjectType(), id, context.getCreatedDate()));
    }
    customFieldUserApi.updateCustomFields(input, context);
    return Response.status(Status.NO_CONTENT).build();
}
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)

Example 7 with CustomField

use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.

the class DefaultCustomFieldUserApi method addCustomFields.

@Override
public void addCustomFields(final List<CustomField> customFields, final CallContext context) throws CustomFieldApiException {
    if (!customFields.isEmpty()) {
        final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(customFields.get(0).getObjectId(), customFields.get(0).getObjectType(), context);
        final Iterable<CustomFieldModelDao> transformed = Iterables.transform(customFields, new Function<CustomField, CustomFieldModelDao>() {

            @Override
            public CustomFieldModelDao apply(final CustomField input) {
                // TODO See https://github.com/killbill/killbill/issues/35
                if (input.getId() != null) {
                    return new CustomFieldModelDao(input.getId(), context.getCreatedDate(), context.getCreatedDate(), input.getFieldName(), input.getFieldValue(), input.getObjectId(), input.getObjectType());
                } else {
                    return new CustomFieldModelDao(context.getCreatedDate(), input.getFieldName(), input.getFieldValue(), input.getObjectId(), input.getObjectType());
                }
            }
        });
        ((DefaultCustomFieldDao) customFieldDao).create(transformed, internalCallContext);
    }
}
Also used : CustomFieldModelDao(org.killbill.billing.util.customfield.dao.CustomFieldModelDao) DefaultCustomFieldDao(org.killbill.billing.util.customfield.dao.DefaultCustomFieldDao) StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 8 with CustomField

use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.

the class DefaultCustomFieldUserApi method updateCustomFields.

@Override
public void updateCustomFields(final List<CustomField> customFields, final CallContext context) throws CustomFieldApiException {
    if (!customFields.isEmpty()) {
        final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(customFields.get(0).getObjectId(), customFields.get(0).getObjectType(), context);
        final Iterable<CustomFieldModelDao> customFieldIds = Iterables.transform(customFields, new Function<CustomField, CustomFieldModelDao>() {

            @Override
            public CustomFieldModelDao apply(final CustomField input) {
                return new CustomFieldModelDao(input.getId(), internalCallContext.getCreatedDate(), internalCallContext.getUpdatedDate(), input.getFieldName(), input.getFieldValue(), input.getObjectId(), input.getObjectType());
            }
        });
        customFieldDao.updateCustomFields(customFieldIds, internalCallContext);
    }
}
Also used : CustomFieldModelDao(org.killbill.billing.util.customfield.dao.CustomFieldModelDao) StringCustomField(org.killbill.billing.util.customfield.StringCustomField) CustomField(org.killbill.billing.util.customfield.CustomField) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext)

Example 9 with CustomField

use of org.killbill.billing.util.customfield.CustomField in project killbill by killbill.

the class CustomFieldResource method searchCustomFieldsByTypeName.

@TimedResource
@GET
@Path("/" + SEARCH)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search custom fields by type, name and optional value", response = CustomFieldJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchCustomFieldsByTypeName(@QueryParam("objectType") final String objectType, @QueryParam("fieldName") final String fieldName, @Nullable @QueryParam("fieldValue") final String fieldValue, @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) {
    Preconditions.checkNotNull(objectType);
    Preconditions.checkNotNull(fieldName);
    final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
    final Pagination<CustomField> customFields = fieldValue != null ? customFieldUserApi.searchCustomFields(fieldName, fieldValue, ObjectType.valueOf(objectType), offset, limit, tenantContext) : customFieldUserApi.searchCustomFields(fieldName, ObjectType.valueOf(objectType), offset, limit, tenantContext);
    final URI nextPageUri = uriBuilder.nextPage(CustomFieldResource.class, "searchCustomFields", customFields.getNextOffset(), limit, ImmutableMap.<String, String>of("objectType", objectType, "fieldName", fieldName, "fieldValue", MoreObjects.firstNonNull(fieldValue, ""), QUERY_AUDIT, auditMode.getLevel().toString()), ImmutableMap.<String, String>of());
    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 10 with CustomField

use of org.killbill.billing.util.customfield.CustomField 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.createTenantContextNoAccountId(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()), ImmutableMap.<String, String>of());
    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)

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