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;
}
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);
}
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;
}
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);
}
}
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");
}
}
}
}
Aggregations