use of org.openmrs.ConceptAttributeType in project openmrs-core by openmrs.
the class ConceptAttributeTypeValidator method validate.
@Override
public void validate(Object obj, Errors errors) {
super.validate(obj, errors);
ConceptAttributeType conceptAttributeType = (ConceptAttributeType) obj;
ConceptService conceptService = Context.getConceptService();
if (conceptAttributeType.getName() != null && !conceptAttributeType.getName().isEmpty()) {
ConceptAttributeType attributeType = conceptService.getConceptAttributeTypeByName(conceptAttributeType.getName());
if (attributeType != null && !attributeType.getUuid().equals(conceptAttributeType.getUuid())) {
errors.rejectValue("name", "ConceptAttributeType.error.nameAlreadyInUse");
}
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "ConceptAttributeType.error.nameEmpty");
}
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "datatypeClassname", "preferredHandlerClassname", "retireReason");
}
use of org.openmrs.ConceptAttributeType in project openmrs-core by openmrs.
the class ConceptAttributeTypeValidatorTest method validate_shouldPassEditingConceptAttributeTypeName.
/**
* @see ConceptAttributeTypeValidator#validate(Object, Errors)
*/
@Test
public void validate_shouldPassEditingConceptAttributeTypeName() {
ConceptAttributeType et = Context.getConceptService().getConceptAttributeTypeByName("Audit Date");
Assert.assertNotNull(et);
Errors errors = new BindException(et, "conceptAttributeType");
validator.validate(et, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.ConceptAttributeType in project openmrs-core by openmrs.
the class ConceptServiceTest method unretireConceptAttributeType_shouldUnretireARetiredConceptAttributeType.
/**
* @see ConceptService#unretireConceptAttributeType(ConceptAttributeType)
*/
@Test
public void unretireConceptAttributeType_shouldUnretireARetiredConceptAttributeType() {
executeDataSet(CONCEPT_ATTRIBUTE_TYPE_XML);
ConceptService service = Context.getConceptService();
ConceptAttributeType conceptAttributeType = service.getConceptAttributeType(2);
Assert.assertTrue(conceptAttributeType.getRetired());
Assert.assertNotNull(conceptAttributeType.getDateRetired());
Assert.assertNotNull(conceptAttributeType.getRetiredBy());
Assert.assertNotNull(conceptAttributeType.getRetireReason());
service.unretireConceptAttributeType(conceptAttributeType);
Assert.assertFalse(conceptAttributeType.getRetired());
Assert.assertNull(conceptAttributeType.getDateRetired());
Assert.assertNull(conceptAttributeType.getRetiredBy());
Assert.assertNull(conceptAttributeType.getRetireReason());
}
use of org.openmrs.ConceptAttributeType in project openmrs-core by openmrs.
the class ConceptServiceTest method hasAnyConceptAttribute_shouldReturnFalseIfNoConceptAttributeFoundForGivenConceptAttributeType.
/**
* @see ConceptService#hasAnyConceptAttribute(ConceptAttributeType)
*/
@Test
public void hasAnyConceptAttribute_shouldReturnFalseIfNoConceptAttributeFoundForGivenConceptAttributeType() {
executeDataSet(CONCEPT_ATTRIBUTE_TYPE_XML);
ConceptService conceptService = Context.getConceptService();
ConceptAttributeType conceptAttributeType = conceptService.getConceptAttributeType(2);
Assert.assertFalse(conceptService.hasAnyConceptAttribute(conceptAttributeType));
}
Aggregations