class ConceptNameTagValidator implements Validator {

	@Override
	public void validate(Object obj, Errors errors) {
		ConceptNameTag cnt = (ConceptNameTag) obj;
		if (cnt == null) {
			throw new IllegalArgumentException("The parameter obj should not be null");
		} else {
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "tag", "error.name");
			
			if (cnt.getTag() != null) {
				ConceptNameTag currentTag = Context.getConceptService().getConceptNameTagByName(cnt.getTag());
				if (currentTag != null && !OpenmrsUtil.nullSafeEqualsIgnoreCase(cnt.getUuid(), currentTag.getUuid())
				        && OpenmrsUtil.nullSafeEqualsIgnoreCase(currentTag.getTag(), cnt.getTag())) {
					errors.rejectValue("tag", "Concept.name.tag.duplicate");
				}
			}
			ValidateUtil.validateFieldLengths(errors, obj.getClass(), "tag", "voidReason");
		}
	}

}