Search in sources :

Example 11 with CodeEntry

use of eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry 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

CodeEntry (eu.esdihumboldt.hale.common.codelist.CodeList.CodeEntry)11 CodeList (eu.esdihumboldt.hale.common.codelist.CodeList)10 Test (org.junit.Test)9 CodeListAssociations (eu.esdihumboldt.hale.common.codelist.config.CodeListAssociations)1 CodeListReference (eu.esdihumboldt.hale.common.codelist.config.CodeListReference)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 ValidationException (eu.esdihumboldt.hale.common.instance.extension.validation.ValidationException)1 NodeList (org.w3c.dom.NodeList)1