Search in sources :

Example 16 with Binding

use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.

the class Centroid method evaluate.

@Override
protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException, NoResultException {
    // get input geometry
    PropertyValue input = variables.get(null).get(0);
    Object inputValue = input.getValue();
    GeometryProperty<?> result = calculateCentroid(inputValue);
    // try to yield a result compatible to the target
    TypeDefinition targetType = resultProperty.getDefinition().getPropertyType();
    // TODO check element type?
    Class<?> binding = targetType.getConstraint(Binding.class).getBinding();
    if (Geometry.class.isAssignableFrom(binding) && binding.isAssignableFrom(result.getClass())) {
        return result.getGeometry();
    }
    return result;
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) Geometry(org.locationtech.jts.geom.Geometry) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 17 with Binding

use of eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding in project hale by halestudio.

the class FunctionExecutor method convert.

/**
 * Convert a value according to a target property entity definition.
 *
 * @param value the value to convert
 * @param propertyEntityDefinition the target property entity definition
 * @return the converted object
 * @throws ConversionException if an error occurs during conversion
 */
private Object convert(Object value, PropertyEntityDefinition propertyEntityDefinition) throws ConversionException {
    if (value == null) {
        return null;
    }
    PropertyDefinition def = propertyEntityDefinition.getDefinition();
    Binding binding = def.getPropertyType().getConstraint(Binding.class);
    Class<?> target = binding.getBinding();
    // special handling for Value
    if (value instanceof Value) {
        // try value's internal conversion
        Object result = ((Value) value).as(target);
        if (result != null) {
            return result;
        } else {
            // unwrap value
            value = ((Value) value).getValue();
            if (value == null) {
                return null;
            }
        }
    }
    if (target.isAssignableFrom(value.getClass())) {
        return value;
    }
    if (Collection.class.isAssignableFrom(target) && target.isAssignableFrom(List.class)) {
        // collection / list
        ElementType elementType = def.getPropertyType().getConstraint(ElementType.class);
        return ConversionUtil.getAsList(value, elementType.getBinding(), true);
    }
    return ConversionUtil.getAs(value, target);
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) ElementType(eu.esdihumboldt.hale.common.schema.model.constraint.type.ElementType) MultiValue(eu.esdihumboldt.cst.MultiValue) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) Value(eu.esdihumboldt.hale.common.core.io.Value) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Aggregations

Binding (eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding)17 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)12 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 PropertyValue (eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue)4 ElementType (eu.esdihumboldt.hale.common.schema.model.constraint.type.ElementType)4 Geometry (org.locationtech.jts.geom.Geometry)4 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 HasValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag)3 Test (org.junit.Test)3 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)2 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)2 Cardinality (eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality)2 AugmentedValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.AugmentedValueFlag)2 GeometryType (eu.esdihumboldt.hale.common.schema.model.constraint.type.GeometryType)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 MultiValue (eu.esdihumboldt.cst.MultiValue)1 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)1 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1