Search in sources :

Example 1 with CodeListReference

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

the class CodeListServiceImpl method findCodeListByEntity.

@Override
public CodeList findCodeListByEntity(EntityDefinition entity) {
    CodeList result = null;
    CodeListReference ref = associations.getCodeList(entity);
    if (ref != null) {
        result = findCodeListByIdentifier(ref.getNamespace(), ref.getIdentifier());
    }
    if (result == null) {
        // fall-back to legacy mechanism
        String ident = entity.getDefinition().getIdentifier();
        result = findCodeListByAttribute(ident);
    }
    return result;
}
Also used : CodeList(eu.esdihumboldt.hale.common.codelist.CodeList) CodeListReference(eu.esdihumboldt.hale.common.codelist.config.CodeListReference)

Example 2 with CodeListReference

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

the class CodeListServiceImpl method addCodeList.

@Override
public void addCodeList(String resourceId, CodeList code) {
    CodeListReference key = new CodeListReference(code.getNamespace(), code.getIdentifier());
    resourceAssociations.put(resourceId, key);
    // TODO deal with possible replacements?!
    codelists.put(key, code);
}
Also used : CodeListReference(eu.esdihumboldt.hale.common.codelist.config.CodeListReference)

Example 3 with CodeListReference

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

the class CodeListServiceImpl method findCodeListByAttribute.

/**
 * Find a code list by attribute identifier.
 *
 * @param attributeIdentifier the attribute identifier
 * @return the code list or <code>null</code>
 */
public CodeList findCodeListByAttribute(String attributeIdentifier) {
    String key = configurationService.get(attributeIdentifier);
    if (key != null) {
        int index = key.lastIndexOf('/');
        if (index >= 0) {
            String namespace = key.substring(0, index);
            String identifier = key.substring(index + 1);
            CodeListReference ref = new CodeListReference(namespace, identifier);
            return codelists.get(ref);
        }
    }
    return null;
}
Also used : CodeListReference(eu.esdihumboldt.hale.common.codelist.config.CodeListReference)

Example 4 with CodeListReference

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

the class CodeListAdvisor method handleResults.

@Override
public void handleResults(CodeListReader provider) {
    CodeList codeList = provider.getCodeList();
    if (codeList != null) {
        CodeListReference key = new CodeListReference(codeList.getNamespace(), codeList.getIdentifier());
        codeLists.put(key, codeList);
    }
}
Also used : CodeList(eu.esdihumboldt.hale.common.codelist.CodeList) CodeListReference(eu.esdihumboldt.hale.common.codelist.config.CodeListReference)

Example 5 with CodeListReference

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

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