Search in sources :

Example 1 with CodeListAssociations

use of eu.esdihumboldt.hale.common.codelist.config.CodeListAssociations in project hale by halestudio.

the class CodeListValidator method validateCodeListValue.

private void validateCodeListValue(@Nullable Object value, @Nullable EntityDefinition entity) throws ValidationException {
    CodeListAssociations associations = null;
    if (projectService != null) {
        associations = projectService.getProperty(CodeListAssociations.KEY_ASSOCIATIONS).as(CodeListAssociations.class);
    }
    if (value != null && entity != null && associations != null && codeLists != null) {
        CodeListReference clRef = associations.getCodeList(entity);
        if (clRef != null) {
            CodeList cl = codeLists.findCodeList(clRef);
            if (cl != null) {
                String strValue = value.toString();
                CodeEntry entry = cl.getEntryByIdentifier(strValue);
                if (entry == null) {
                    throw new ValidationException(MessageFormat.format("Value ''{0}'' not found in associated code list", strValue));
                }
            } else {
                log.warn("Code list " + clRef + " not found for validation");
            }
        }
    }
}
Also used : CodeList(eu.esdihumboldt.hale.common.codelist.CodeList) CodeEntry(eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry) ValidationException(eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException) CodeListAssociations(eu.esdihumboldt.hale.common.codelist.config.CodeListAssociations) CodeListReference(eu.esdihumboldt.hale.common.codelist.config.CodeListReference)

Aggregations

CodeList (eu.esdihumboldt.hale.common.codelist.CodeList)1 CodeEntry (eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry)1 CodeListAssociations (eu.esdihumboldt.hale.common.codelist.config.CodeListAssociations)1 CodeListReference (eu.esdihumboldt.hale.common.codelist.config.CodeListReference)1 ValidationException (eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException)1