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