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