Search in sources :

Example 1 with CodeListAssociation

use of eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation in project hale by halestudio.

the class CodeListAssocationFactory method restore.

@Override
public CodeListAssociation restore(Value value, Definition<?> definition, TypeResolver typeIndex, ClassResolver resolver) throws Exception {
    // is it a simple value? (single String code list reference)
    String single = value.as(String.class);
    if (single != null) {
        return new CodeListAssociation(Collections.singleton(single));
    }
    // is it a value list? (multiple String code list references)
    ValueList list = value.as(ValueList.class);
    if (list != null) {
        List<String> refList = list.stream().map(val -> val.as(String.class)).filter(val -> val != null).collect(Collectors.toList());
        return new CodeListAssociation(refList);
    }
    // fall-back
    return new CodeListAssociation();
}
Also used : ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) List(java.util.List) ClassResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.ClassResolver) TypeResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeResolver) CodeListAssociation(eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation) StreamSupport(java.util.stream.StreamSupport) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeReferenceBuilder(eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeReferenceBuilder) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Value(eu.esdihumboldt.hale.common.core.io.Value) ValueConstraintFactory(eu.esdihumboldt.hale.common.schema.model.constraint.factory.ValueConstraintFactory) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) CodeListAssociation(eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation)

Aggregations

Value (eu.esdihumboldt.hale.common.core.io.Value)1 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)1 Definition (eu.esdihumboldt.hale.common.schema.model.Definition)1 ClassResolver (eu.esdihumboldt.hale.common.schema.model.constraint.factory.ClassResolver)1 TypeReferenceBuilder (eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeReferenceBuilder)1 TypeResolver (eu.esdihumboldt.hale.common.schema.model.constraint.factory.TypeResolver)1 ValueConstraintFactory (eu.esdihumboldt.hale.common.schema.model.constraint.factory.ValueConstraintFactory)1 CodeListAssociation (eu.esdihumboldt.hale.common.schema.model.constraint.property.CodeListAssociation)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1