Search in sources :

Example 71 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class LookupTableTypeTest method testStringLookup.

/**
 * Test if a simple lookup table containing only string values is the same
 * when converted to DOM and back again.
 */
@Test
public void testStringLookup() {
    Map<Value, Value> values = createStringLookup();
    LookupTable org = new LookupTableImpl(values);
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(org);
    // convert back
    LookupTable conv = HaleIO.getComplexValue(fragment, LookupTable.class, null);
    checkTable(conv, values);
}
Also used : Element(org.w3c.dom.Element) Value(eu.esdihumboldt.hale.common.core.io.Value) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl) Test(org.junit.Test)

Example 72 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class LookupTableTypeTest method testComplexLookup.

/**
 * Test if a lookup table containing only complex values is the same when
 * converted to DOM and back again.
 */
@Test
public void testComplexLookup() {
    Map<Value, Value> values2 = createComplexLookup();
    LookupTable org2 = new LookupTableImpl(values2);
    // convert to DOM
    Element fragment = HaleIO.getComplexElement(org2);
    // convert back
    LookupTable conv = HaleIO.getComplexValue(fragment, LookupTable.class, null);
    checkTable(conv, values2);
}
Also used : Element(org.w3c.dom.Element) Value(eu.esdihumboldt.hale.common.core.io.Value) LookupTable(eu.esdihumboldt.hale.common.lookup.LookupTable) LookupTableImpl(eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl) Test(org.junit.Test)

Example 73 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class AbstractValueConstraintFactoryTest method storeRestoreTest.

/**
 * Test storing a constraint, restoring it and compare both.
 *
 * @param constraint the constraint to store
 * @param typeIndex the type index (as context for storing/restoring),
 *            <code>null</code> for an empty index
 * @param constraintDef the definition the constraint is associated to (as
 *            context for storing/restoring), for <code>null</code> the
 *            method will try to generate a default definition based on the
 *            constraint type
 * @throws Exception if an error occurs during storing, restoring or
 *             comparing the constraint
 */
@SuppressWarnings("unchecked")
protected void storeRestoreTest(T constraint, Map<TypeDefinition, Value> typeIndex, Definition<?> constraintDef) throws Exception {
    // conversion service may be needed for Value conversions
    TestUtil.startConversionService();
    ValueConstraintFactoryDescriptor desc = ValueConstraintExtension.INSTANCE.getForConstraint(constraint);
    // provide defaults for null parameters
    if (typeIndex == null) {
        typeIndex = new HashMap<>();
    }
    if (constraintDef == null) {
        constraintDef = getDefaultConstraintDefinition(constraint.getClass());
    }
    @SuppressWarnings("rawtypes") ValueConstraintFactory factory = desc.getFactory();
    Value val = factory.store(constraint, new MapTypeReferenceBuilder(typeIndex));
    T read;
    if (val != null) {
        // to DOM
        NSDOMBuilder builder = NSDOMBuilder.newBuilder(new HashMap<String, String>());
        Element elem = DOMValueUtil.valueTag(builder, "test", val);
        // from DOM
        Value res = DOMValueUtil.fromTag(elem);
        // bimap for reverse index
        BiMap<TypeDefinition, Value> types = HashBiMap.create(typeIndex);
        read = (T) factory.restore(res, constraintDef, new MapTypeResolver(types.inverse()), new OsgiClassResolver());
    } else {
        // fall back to default constraint
        Class<?> constraintType = ConstraintUtil.getConstraintType(constraint.getClass());
        read = (T) ConstraintUtil.getDefaultConstraint(constraintType, constraintDef);
    }
    compare(constraint, read);
}
Also used : NSDOMBuilder(eu.esdihumboldt.util.groovy.xml.NSDOMBuilder) Element(org.w3c.dom.Element) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) ValueConstraintFactoryDescriptor(eu.esdihumboldt.hale.common.schema.model.constraint.factory.extension.ValueConstraintFactoryDescriptor) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 74 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class ElementTypeFactory method store.

@Override
public Value store(ElementType constraint, TypeReferenceBuilder typeIndex) throws Exception {
    ValueProperties props = new ValueProperties();
    // type definition
    if (constraint.getDefinition() != null) {
        Optional<Value> ref = typeIndex.createReference(constraint.getDefinition());
        if (ref.isPresent()) {
            props.put(P_TYPE, ref.get());
        }
    }
    // binding
    String className = constraint.getBinding().getName();
    props.put(P_BINDING, Value.of(className));
    return props.toValue();
}
Also used : ValueProperties(eu.esdihumboldt.hale.common.core.io.ValueProperties) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 75 with Value

use of eu.esdihumboldt.hale.common.core.io.Value in project hale by halestudio.

the class EnumerationValidatorFactory method restore.

@Override
public Validator restore(Value value) throws Exception {
    ValueList list = value.as(ValueList.class);
    List<String> values = new ArrayList<>();
    for (Value val : list) {
        String str = val.as(String.class);
        if (str != null) {
            values.add(str);
        } else {
            throw new IllegalStateException("Enumeration value for validator could not be read");
        }
    }
    return new EnumerationValidator(values);
}
Also used : EnumerationValidator(eu.esdihumboldt.util.validator.EnumerationValidator) ValueList(eu.esdihumboldt.hale.common.core.io.ValueList) ArrayList(java.util.ArrayList) Value(eu.esdihumboldt.hale.common.core.io.Value)

Aggregations

Value (eu.esdihumboldt.hale.common.core.io.Value)81 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)12 LookupTable (eu.esdihumboldt.hale.common.lookup.LookupTable)12 HashMap (java.util.HashMap)12 ValueProperties (eu.esdihumboldt.hale.common.core.io.ValueProperties)11 LookupTableImpl (eu.esdihumboldt.hale.common.lookup.impl.LookupTableImpl)11 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)10 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)8 Test (org.junit.Test)6 StyledString (org.eclipse.jface.viewers.StyledString)5 Composite (org.eclipse.swt.widgets.Composite)5 DefaultCustomPropertyFunction (eu.esdihumboldt.hale.common.align.custom.DefaultCustomPropertyFunction)4 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)4 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)4 IOException (java.io.IOException)4 Locale (java.util.Locale)4