use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class PropertiesLabelProvider method getImage.
/**
* @see LabelProvider#getImage(Object)
*/
@Override
public Image getImage(Object element) {
if (element instanceof IStructuredSelection) {
element = ((IStructuredSelection) element).getFirstElement();
}
element = TransformationTreeUtil.extractObject(element);
if (element instanceof Entity) {
element = ((Entity) element).getDefinition();
}
if (element instanceof EntityDefinition || element instanceof Definition<?>) {
return definitionLabels.getImage(element);
}
if (element instanceof Cell) {
Cell cell = (Cell) element;
FunctionDefinition<?> function = FunctionUtil.getFunction(cell.getTransformationIdentifier(), HaleUI.getServiceProvider());
if (function != null) {
element = function;
}
}
if (element instanceof FunctionDefinition) {
return functionLabels.getImage(element);
}
return super.getImage(element);
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class FormattedStringHandler method getSourceExpressionAsCQL.
/**
* @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
*/
@Override
protected String getSourceExpressionAsCQL() {
ListMultimap<String, ParameterValue> parameters = propertyCell.getTransformationParameters();
String pattern = parameters.get(PARAMETER_PATTERN).get(0).as(String.class);
List<int[]> startEndList = new ArrayList<int[]>();
List<String> varList = new ArrayList<String>();
Matcher m = VARIABLE_PATTERN.matcher(pattern);
while (m.find()) {
int[] startEnd = new int[2];
// index of '{' character
startEnd[0] = m.start();
// index of '}' character
startEnd[1] = m.end();
startEndList.add(startEnd);
// the variable name, without curly braces
varList.add(m.group(1));
}
// list of string to be concatenated, either string constants or
// variable names
String[] partsToConcat = new String[varList.size() * 2 + 1];
int lastPos = 0;
for (int i = 0; i < varList.size(); i++) {
int[] startEnd = startEndList.get(i);
String var = varList.get(i);
String textBeforeVar = pattern.substring(lastPos, startEnd[0]);
if (textBeforeVar != null && textBeforeVar.length() == 0) {
textBeforeVar = null;
}
partsToConcat[i * 2] = (textBeforeVar != null) ? "'" + textBeforeVar + "'" : null;
partsToConcat[i * 2 + 1] = var;
lastPos = startEnd[1];
}
// add text after last variable
String textAfterLastVar = pattern.substring(lastPos, pattern.length());
if (textAfterLastVar != null && textAfterLastVar.length() == 0) {
textAfterLastVar = null;
}
partsToConcat[partsToConcat.length - 1] = (textAfterLastVar != null) ? "'" + textAfterLastVar + "'" : null;
String strConcatExpr = "";
int lastPartIdx = 0;
while (lastPartIdx < partsToConcat.length) {
if (lastPartIdx == 0) {
// initialize strConcatExpr
for (int notNullIdx = lastPartIdx; notNullIdx < partsToConcat.length; notNullIdx++) {
if (partsToConcat[notNullIdx] != null) {
strConcatExpr = partsToConcat[notNullIdx];
lastPartIdx = notNullIdx;
break;
}
}
}
String secondArgument = null;
for (int notNullIdx = lastPartIdx + 1; notNullIdx < partsToConcat.length; notNullIdx++) {
if (partsToConcat[notNullIdx] != null) {
secondArgument = partsToConcat[notNullIdx];
lastPartIdx = notNullIdx;
break;
}
}
if (secondArgument != null) {
strConcatExpr = "strConcat(" + strConcatExpr + ", " + secondArgument + ")";
} else {
// no second argument could be found: should stop here
break;
}
}
// expression should be evaluated only if all conditions are met
if (propertyCell.getSource() != null) {
List<? extends Entity> sourceEntities = propertyCell.getSource().get(FormattedStringFunction.ENTITY_VARIABLE);
if (sourceEntities != null) {
for (Entity source : sourceEntities) {
PropertyEntityDefinition propEntityDef = (PropertyEntityDefinition) source.getDefinition();
strConcatExpr = getConditionalExpression(propEntityDef, strConcatExpr);
}
}
}
return strConcatExpr;
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class MathematicalExpressionHandler method getSourceExpressionAsCQL.
/**
* @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
*/
@Override
protected String getSourceExpressionAsCQL() {
// TODO: verify math expressions work as-is in CQL
String mathExpression = propertyCell.getTransformationParameters().get(PARAMETER_EXPRESSION).get(0).getStringRepresentation();
// expression should be evaluated only if all conditions are met
if (propertyCell.getSource() != null) {
List<? extends Entity> sourceEntities = propertyCell.getSource().get(MathematicalExpression.ENTITY_VARIABLE);
if (sourceEntities != null) {
for (Entity source : sourceEntities) {
PropertyEntityDefinition propEntityDef = (PropertyEntityDefinition) source.getDefinition();
mathExpression = getConditionalExpression(propEntityDef, mathExpression);
}
}
}
return mathExpression;
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class DefaultsVisitor method addDefaultCell.
/**
* Add a cell assigning a default value to the given entity.
*
* @param ped the property entity definition
* @param value the value to assign or <code>null</code> if it should be
* auto-detected
*/
private void addDefaultCell(PropertyEntityDefinition ped, String value) {
String note;
// determine value to assign
if (value == null) {
value = determineDefaultValue(ped.getDefinition().getPropertyType());
note = "Generated default value based on property type.";
} else {
note = "Generated cell with specified default value.";
}
if (value == null) {
return;
}
// create cell template
MutableCell cell = new DefaultCell();
cell.setPriority(Priority.LOWEST);
ListMultimap<String, Entity> target = ArrayListMultimap.create();
cell.setTarget(target);
ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
cell.setTransformationParameters(parameters);
// set transformation identifier (Assign)
cell.setTransformationIdentifier(AssignFunction.ID);
// set cell target (Property)
target.put(null, new DefaultProperty(ped));
// set cell parameters (Value)
parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(value));
BGISAppUtil.appendNote(cell, note);
cells.add(cell);
}
use of eu.esdihumboldt.hale.common.align.model.Entity in project hale by halestudio.
the class CityGMLPropagateVisitor method findSourceTypes.
/**
* Find source types to use to propagate the given example cell. If
* possible, common super types will be returned.
*
* @param exampleCell the example cell
* @param targetType the target type
* @param index the index to store the replacement property paths in
* @return the source types to propagate the cell to
*/
private Collection<TypeDefinition> findSourceTypes(Cell exampleCell, TypeDefinition targetType, TypeEntityIndex<List<ChildContext>> index) {
Set<TypeDefinition> possibleSources = findAllPossibleSources(targetType);
/*
* Add all super types, because if possible, we want to do the mapping
* on super types.
*/
Set<TypeDefinition> superTypes = new HashSet<TypeDefinition>();
for (TypeDefinition type : possibleSources) {
TypeDefinition superType = type.getSuperType();
while (superType != null) {
if (superTypes.add(superType) || !possibleSources.contains(superType)) {
superType = superType.getSuperType();
} else {
superType = null;
}
}
}
possibleSources.addAll(superTypes);
/*
* Check source entities and filter all source types that don't match
* the entity.
*/
TypeDefinition originalSource = null;
for (Entity source : exampleCell.getSource().values()) {
EntityDefinition ed = source.getDefinition();
// check source type
if (originalSource == null) {
originalSource = ed.getType();
} else {
if (!originalSource.equals(ed.getType())) {
System.err.println("WARNING: ignoring cell with sources in different types");
return null;
}
}
if (ed.getPropertyPath().isEmpty()) {
// don't handle type cells
return null;
}
// remove all types w/o compatible property
Iterator<TypeDefinition> it = possibleSources.iterator();
while (it.hasNext()) {
TypeDefinition type = it.next();
List<ChildContext> newPath = hasCompatibleProperty(type, ed.getPropertyPath());
if (newPath == null) {
it.remove();
} else {
// remember child path per root type and entity
index.put(type, source, newPath);
}
}
}
/*
* Remove all types that have super types contained in the set.
*/
Set<TypeDefinition> toTest = new HashSet<TypeDefinition>(possibleSources);
for (TypeDefinition type : toTest) {
TypeDefinition superType = type.getSuperType();
while (superType != null) {
if (possibleSources.contains(superType)) {
possibleSources.remove(type);
// other super types are tested on their own
break;
}
superType = superType.getSuperType();
}
}
return possibleSources;
}
Aggregations