/** * Checks that a given concept map type object is valid. * * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail if the concept map type object is null * @should fail if the name is null * @should fail if the name is an empty string * @should fail if the name is a white space character * @should fail if the concept map type name is a duplicate * @should pass if the name is unique amongst all concept map type names * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ public void validate(Object obj, Errors errors) { if (obj == null || !(obj instanceof ConceptMapType)) { throw new IllegalArgumentException( "The parameter obj should not be null and must be of type" + ConceptMapType.class); } ConceptMapType conceptMapType = (ConceptMapType) obj; String name = conceptMapType.getName(); if (!StringUtils.hasText(name)) { errors.rejectValue( "name", "ConceptMapType.error.nameRequired", "The name property is required for a concept map type"); return; } name = name.trim(); ConceptMapType duplicate = Context.getConceptService().getConceptMapTypeByName(name); if (duplicate != null && !OpenmrsUtil.nullSafeEquals(duplicate.getUuid(), conceptMapType.getUuid())) { errors.rejectValue( "name", "ConceptMapType.duplicate.name", "Duplicate concept map type name: " + name); } ValidateUtil.validateFieldLengths( errors, obj.getClass(), "name", "description", "retireReason"); }