use of org.openmrs.ProviderAttributeType in project openmrs-core by openmrs.
the class ProviderServiceTest method saveProviderAttributeType_shouldSaveTheProviderAttributeType.
/**
* @see ProviderService#saveProviderAttributeType(ProviderAttributeType)
*/
@Test
public void saveProviderAttributeType_shouldSaveTheProviderAttributeType() {
int size = service.getAllProviderAttributeTypes().size();
ProviderAttributeType providerAttributeType = new ProviderAttributeType();
providerAttributeType.setName("new");
providerAttributeType.setDatatypeClassname(FreeTextDatatype.class.getName());
providerAttributeType = service.saveProviderAttributeType(providerAttributeType);
assertEquals(size + 1, service.getAllProviderAttributeTypes().size());
assertNotNull(providerAttributeType.getId());
}
use of org.openmrs.ProviderAttributeType in project openmrs-core by openmrs.
the class ProviderAttributeTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see ProviderAttributeTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ProviderAttributeType type = new ProviderAttributeType();
type.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
type.setDatatypeClassname("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
type.setDescription(new String(new char[655555]));
type.setPreferredHandlerClassname("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
type.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(type, "type");
new ProviderAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("datatypeClassname"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("preferredHandlerClassname"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.openmrs.ProviderAttributeType in project openmrs-core by openmrs.
the class ProviderAttributeTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see ProviderAttributeTypeValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
ProviderAttributeType type = new ProviderAttributeType();
type.setName("name");
type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
type.setDescription("description");
type.setRetireReason("retireReason");
Errors errors = new BindException(type, "type");
new ProviderAttributeTypeValidator().validate(type, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.ProviderAttributeType in project openmrs-core by openmrs.
the class HibernateProviderDAO method getProviders.
/**
* @see org.openmrs.api.db.ProviderDAO#getProviders(String, Map, Integer, Integer, boolean)
*/
@Override
public List<Provider> getProviders(String name, Map<ProviderAttributeType, String> serializedAttributeValues, Integer start, Integer length, boolean includeRetired) {
Criteria criteria = prepareProviderCriteria(name, includeRetired);
if (start != null) {
criteria.setFirstResult(start);
}
if (length != null) {
criteria.setMaxResults(length);
}
if (includeRetired) {
// push retired Provider to the end of the returned list
criteria.addOrder(Order.asc("retired"));
}
List<Provider> providers = criteria.list();
if (serializedAttributeValues != null) {
CollectionUtils.filter(providers, new AttributeMatcherPredicate<Provider, ProviderAttributeType>(serializedAttributeValues));
}
return providers;
}
Aggregations