Search in sources :

Example 6 with ConceptAttributeType

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");
}
Also used : ConceptAttributeType(org.openmrs.ConceptAttributeType) ConceptService(org.openmrs.api.ConceptService)

Example 7 with ConceptAttributeType

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());
}
Also used : Errors(org.springframework.validation.Errors) ConceptAttributeType(org.openmrs.ConceptAttributeType) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with ConceptAttributeType

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());
}
Also used : ConceptAttributeType(org.openmrs.ConceptAttributeType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 9 with ConceptAttributeType

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));
}
Also used : ConceptAttributeType(org.openmrs.ConceptAttributeType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

ConceptAttributeType (org.openmrs.ConceptAttributeType)9 Test (org.junit.Test)7 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)7 BindException (org.springframework.validation.BindException)2 Before (org.junit.Before)1 ConceptService (org.openmrs.api.ConceptService)1 FreeTextDatatype (org.openmrs.customdatatype.datatype.FreeTextDatatype)1 Errors (org.springframework.validation.Errors)1