Search in sources :

Example 11 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class InstanceContextTester method testAllowAddIndex.

/**
 * Tests if for the given entity definition a new index context may be
 * created.
 *
 * @param entityDef the entity definition
 * @return if adding an index context is allowed
 */
private boolean testAllowAddIndex(EntityDefinition entityDef) {
    if (entityDef.getSchemaSpace().equals(SchemaSpaceID.TARGET)) {
        // only allowed on source properties
        return false;
    }
    // XXX for now only a simple test based on type and cardinality
    List<ChildContext> path = entityDef.getPropertyPath();
    if (path != null && !path.isEmpty()) {
        ChildContext lastContext = path.get(path.size() - 1);
        ChildDefinition<?> lastDef = lastContext.getChild();
        // test type & cardinality
        Cardinality cardinality;
        try {
            cardinality = DefinitionUtil.getCardinality(lastDef);
        } catch (Exception e) {
            return false;
        }
        if (cardinality.getMaxOccurs() == Cardinality.UNBOUNDED) {
            return true;
        }
        return cardinality.getMaxOccurs() > 1;
    }
    return false;
}
Also used : Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 12 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class InstanceContextTester method testAllowAddNamed.

/**
 * Tests if for the given entity definition a new instance context may be
 * created.
 *
 * @param entityDef the entity definition
 * @return if adding an instance context is allowed
 */
private boolean testAllowAddNamed(EntityDefinition entityDef) {
    if (entityDef.getSchemaSpace().equals(SchemaSpaceID.SOURCE)) {
        // only allowed on target properties
        return false;
    }
    // XXX for now only a simple test based on type and cardinality
    List<ChildContext> path = entityDef.getPropertyPath();
    if (path != null && !path.isEmpty()) {
        ChildContext lastContext = path.get(path.size() - 1);
        ChildDefinition<?> lastDef = lastContext.getChild();
        // test type & cardinality
        Cardinality cardinality;
        try {
            cardinality = DefinitionUtil.getCardinality(lastDef);
        } catch (Exception e) {
            return false;
        }
        if (cardinality.getMaxOccurs() == Cardinality.UNBOUNDED) {
            return true;
        }
        return cardinality.getMaxOccurs() > 1;
    }
    return false;
}
Also used : Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 13 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class InstanceTestValues method extractValue.

/**
 * Extract the value represented by the given property from the given
 * instance.
 *
 * @param instance the instance
 * @param property the property
 * @return the first property value in the instance, or <code>null</code>
 */
protected Object extractValue(Instance instance, PropertyEntityDefinition property) {
    List<ChildContext> path = property.getPropertyPath();
    Object current = instance;
    // step down for each path element
    for (ChildContext element : path) {
        if (current instanceof Group) {
            Group group = (Group) current;
            Object[] vals = group.getProperty(element.getChild().getName());
            if (vals != null && vals.length > 0) {
                // TODO match filter?
                // child
                current = vals[0];
            } else {
                // property not present
                return null;
            }
        } else {
            // property not present
            return null;
        }
    }
    return current;
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 14 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class FilterEditor method getValue.

/**
 * @see Editor#getValue()
 */
@Override
public Filter getValue() {
    if (filterEnabled.getSelection()) {
        try {
            FilterIdentifier id = (FilterIdentifier) ((IStructuredSelection) filterSelect.getSelection()).getFirstElement();
            String propertyName = "";
            // get the selected entity from the property selector (filter
            // fields)
            // and pass it to the filter
            EntityDefinition entity = propertySelect.getSelectedObject();
            if (entity != null) {
                Iterator<ChildContext> childIt = entity.getPropertyPath().iterator();
                if (childIt.hasNext()) {
                    propertyName = propertyName.concat(childIt.next().getChild().getName().toString());
                }
                while (childIt.hasNext()) {
                    propertyName = propertyName.concat("." + childIt.next().getChild().getName().toString());
                }
            } else {
                propertyName = "<select>";
            }
            String valueText = literal.getDocument().get();
            Expression property = filterFactory.property(propertyName);
            Expression value = filterFactory.literal(valueText);
            switch(id) {
                case EQUAL:
                    return filterFactory.equals(property, value);
                case LESS_THAN:
                    return filterFactory.less(property, value);
                case LESS_OR_EQUAL:
                    return filterFactory.lessOrEqual(property, value);
                case GREATER_THAN:
                    return filterFactory.greater(property, value);
                case GREATER_OR_EQUAL:
                    return filterFactory.greaterOrEqual(property, value);
                case LIKE:
                    return filterFactory.like(property, valueText);
                default:
                    return null;
            }
        } catch (Exception e) {
            // $NON-NLS-1$
            log.warn("Error getting filter", e);
            return null;
        }
    } else {
        // no filter
        return null;
    }
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Expression(org.opengis.filter.expression.Expression) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 15 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class MathematicalExpression method evaluateExpression.

/**
 * Evaluate a mathematical expression.
 *
 * @param expression the mathematical expression. It may contain references
 *            to variables
 * @param vars the list of available property values that may be bound to
 *            variables
 * @return the evaluated expression, which can be Double, Integer or String
 * @throws XExpression if the expression could not be evaluated
 */
public static Object evaluateExpression(String expression, List<PropertyValue> vars) throws XExpression {
    Environment env = new Environment();
    for (PropertyValue var : vars) {
        // add the variable to the environment
        // determine the variable value
        Object value = var.getValue();
        Number number;
        if (value instanceof Number) {
            number = (Number) value;
        } else {
            // try conversion to Double as default
            number = var.getValueAs(Double.class);
        }
        // Floats
        if (!(number instanceof Integer) && !(number instanceof Double)) {
            number = number.doubleValue();
        }
        // determine the variable name
        String name = var.getProperty().getDefinition().getName().getLocalPart();
        Constant varValue = new Constant(number);
        // name is overridden
        if (env.getVariable(name) == null || var.getProperty().getPropertyPath().size() == 1) {
            env.addVariable(name, varValue);
        }
        // add with long name if applicable
        if (var.getProperty().getPropertyPath().size() > 1) {
            List<String> names = new ArrayList<String>();
            for (ChildContext context : var.getProperty().getPropertyPath()) {
                names.add(context.getChild().getName().getLocalPart());
            }
            String longName = Joiner.on('.').join(names);
            env.addVariable(longName, varValue);
        }
    }
    Expression ex = new Expression(expression, env);
    return ex.evaluate();
}
Also used : Expression(com.iabcinc.jmep.Expression) XExpression(com.iabcinc.jmep.XExpression) Constant(com.iabcinc.jmep.hooks.Constant) ArrayList(java.util.ArrayList) Environment(com.iabcinc.jmep.Environment) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Aggregations

ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)63 ArrayList (java.util.ArrayList)32 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)29 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)24 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)12 QName (javax.xml.namespace.QName)11 Property (eu.esdihumboldt.hale.common.align.model.Property)7 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 List (java.util.List)7 Condition (eu.esdihumboldt.hale.common.align.model.Condition)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)6 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)5 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)5 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)4 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)3 Type (eu.esdihumboldt.hale.common.align.model.Type)3 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3