Search in sources :

Example 1 with CustomFieldModelDao

use of org.killbill.billing.util.customfield.dao.CustomFieldModelDao 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 2 with CustomFieldModelDao

use of org.killbill.billing.util.customfield.dao.CustomFieldModelDao 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 3 with CustomFieldModelDao

use of org.killbill.billing.util.customfield.dao.CustomFieldModelDao in project killbill by killbill.

the class TestFieldStore method testCreateCustomField.

@Test(groups = "slow")
public void testCreateCustomField() throws CustomFieldApiException {
    final UUID id = UUID.randomUUID();
    final ObjectType objectType = ObjectType.ACCOUNT;
    String fieldName = "TestField1";
    String fieldValue = "Kitty Hawk";
    eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
    customFieldDao.create(new CustomFieldModelDao(internalCallContext.getCreatedDate(), fieldName, fieldValue, id, objectType), internalCallContext);
    assertListenerStatus();
    fieldName = "TestField2";
    fieldValue = "Cape Canaveral";
    eventsListener.pushExpectedEvent(NextEvent.CUSTOM_FIELD);
    customFieldDao.create(new CustomFieldModelDao(internalCallContext.getCreatedDate(), fieldName, fieldValue, id, objectType), internalCallContext);
    assertListenerStatus();
}
Also used : ObjectType(org.killbill.billing.ObjectType) CustomFieldModelDao(org.killbill.billing.util.customfield.dao.CustomFieldModelDao) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 4 with CustomFieldModelDao

use of org.killbill.billing.util.customfield.dao.CustomFieldModelDao in project killbill by killbill.

the class TestAccountDao method testCustomFields.

@Test(groups = "slow", description = "Test Account DAO: custom fields")
public void testCustomFields() throws CustomFieldApiException {
    final UUID accountId = UUID.randomUUID();
    final String fieldName = UUID.randomUUID().toString().substring(0, 4);
    final String fieldValue = UUID.randomUUID().toString();
    customFieldDao.create(new CustomFieldModelDao(internalCallContext.getCreatedDate(), fieldName, fieldValue, accountId, ObjectType.ACCOUNT), internalCallContext);
    final List<CustomFieldModelDao> customFieldMap = customFieldDao.getCustomFieldsForObject(accountId, ObjectType.ACCOUNT, internalCallContext);
    Assert.assertEquals(customFieldMap.size(), 1);
    final CustomFieldModelDao customField = customFieldMap.get(0);
    Assert.assertEquals(customField.getFieldName(), fieldName);
    Assert.assertEquals(customField.getFieldValue(), fieldValue);
}
Also used : CustomFieldModelDao(org.killbill.billing.util.customfield.dao.CustomFieldModelDao) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

CustomFieldModelDao (org.killbill.billing.util.customfield.dao.CustomFieldModelDao)4 UUID (java.util.UUID)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 CustomField (org.killbill.billing.util.customfield.CustomField)2 StringCustomField (org.killbill.billing.util.customfield.StringCustomField)2 Test (org.testng.annotations.Test)2 ObjectType (org.killbill.billing.ObjectType)1 DefaultCustomFieldDao (org.killbill.billing.util.customfield.dao.DefaultCustomFieldDao)1