use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.
the class EntityPopulationCount method evaluateChildEntityDefinition.
private void evaluateChildEntityDefinition(Group group, EntityDefinition groupDef, List<ChildContext> path) {
if (path.size() == 1) {
evaluateContext(group, groupDef);
} else {
ChildContext context = path.get(0);
List<ChildContext> subPath = path.subList(1, path.size());
Object[] values = group.getProperty(context.getChild().getName());
if (values != null) {
for (Object value : values) {
if (value instanceof Group) {
evaluateChildEntityDefinition((Group) value, groupDef, subPath);
}
}
} else {
evaluateChildEntityDefinition(group, groupDef, subPath);
}
}
}
use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.
the class InstanceVisitor method visit.
/**
* @see AbstractSourceToTargetVisitor#visit(SourceNode)
*/
@Override
public boolean visit(SourceNode source) {
if (source.getDefinition() instanceof TypeDefinition) {
if (instance == null)
return false;
// source root
if (source.getDefinition().equals(instance.getDefinition())) {
// check type filter (if any)
Filter filter = source.getEntityDefinition().getFilter();
if (filter != null && !filter.match(instance)) {
// instance does not match filter, don't descend further
return false;
/*
* XXX What about merged instances? Will this be OK for
* those? A type filter should only apply to the original
* instance if it is merged - but most filters should
* evaluate the same
*/
} else {
// also sets the node to defined
source.setValue(instance);
for (FamilyInstance child : instance.getChildren()) {
// Find fitting SourceNodes.
Collection<SourceNode> candidateNodes = tree.getRootSourceNodes(child.getDefinition());
if (candidateNodes.isEmpty()) {
/*
* No node found - but this may be because no
* property of the type is mapped, but there still
* might be child instances (in a Join) that have
* types with associated relations. To prevent those
* being skipped we add an artificial node
* representing the instance.
*/
candidateNodes = new ArrayList<>();
EntityDefinition entityDef = new TypeEntityDefinition(child.getDefinition(), SchemaSpaceID.SOURCE, null);
candidateNodes.add(new SourceNodeImpl(entityDef, null, false));
}
for (SourceNode candidateNode : candidateNodes) {
filter = candidateNode.getEntityDefinition().getFilter();
if (filter == null || filter.match(child)) {
// XXX add to all candidates!?
if (candidateNode.getValue() == null) {
candidateNode.setAnnotatedParent(source);
source.addAnnotatedChild(candidateNode);
} else {
// Duplicate here, because there is no
// guarantee, that the Duplication
// Visitor will visit candidateNode after
// this node.
SourceNodeImpl duplicateNode = new SourceNodeImpl(candidateNode.getEntityDefinition(), candidateNode.getParent(), false);
duplicateNode.setAnnotatedParent(source);
source.addAnnotatedChild(duplicateNode);
TransformationContext context = candidateNode.getContext();
duplicateNode.setContext(context);
if (context != null) {
context.duplicateContext(candidateNode, duplicateNode, Collections.<Cell>emptySet(), log);
} else {
/*
* Not sure what this really means if we
* get here.
*
* Best guess: Probably that we weren't
* able to determine how the duplication
* of this source can be propagted to
* the target. Thus the duplicated node
* will probably not have any
* connection.
*/
log.warn(log.createMessage("No transformation context for duplicated node of source " + candidateNode.getDefinition().getDisplayName(), null));
}
candidateNode = duplicateNode;
}
// run instance visitor on that annotated child
InstanceVisitor visitor = new InstanceVisitor(child, tree, log);
candidateNode.accept(visitor);
}
}
}
return true;
}
} else
return false;
} else {
Object parentValue = source.getParent().getValue();
if (parentValue == null || !(parentValue instanceof Group)) {
source.setDefined(false);
return false;
} else {
Group parentGroup = (Group) parentValue;
Definition<?> currentDef = source.getDefinition();
Object[] values = parentGroup.getProperty(currentDef.getName());
if (values == null) {
source.setDefined(false);
return false;
}
// check for contexts
EntityDefinition entityDef = source.getEntityDefinition();
// index context
Integer index = AlignmentUtil.getContextIndex(entityDef);
if (index != null) {
// only use the value at the given index, if present
if (index < values.length) {
// annotate with the value at the index
Object value = values[index];
source.setValue(value);
return true;
} else {
source.setDefined(false);
return false;
}
}
// condition context
Condition condition = AlignmentUtil.getContextCondition(entityDef);
if (condition != null) {
if (condition.getFilter() == null) {
// assume exclusion
source.setDefined(false);
return false;
}
// apply condition as filter on values and continue with
// those values
Collection<Object> matchedValues = new ArrayList<Object>();
for (Object value : values) {
// determine parent
Object parent = null;
SourceNode parentNode = source.getParent();
if (parentNode != null && parentNode.isDefined()) {
parent = parentNode.getValue();
}
// test the condition
if (AlignmentUtil.matchCondition(condition, value, parent)) {
matchedValues.add(value);
}
}
values = matchedValues.toArray();
}
// default behavior (default context)
if (values.length >= 1) {
// annotate with the first value
Object value = values[0];
source.setValue(value);
source.setAllValues(values);
} else {
source.setDefined(false);
return false;
}
if (values.length > 1) {
// handle additional values
Object[] leftovers = new Object[values.length - 1];
System.arraycopy(values, 1, leftovers, 0, leftovers.length);
source.setLeftovers(new LeftoversImpl(source, leftovers));
}
return true;
}
}
}
use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.
the class DuplicationVisitor method visit.
/**
* @see AbstractTransformationNodeVisitor#visit(SourceNode)
*/
@Override
public boolean visit(SourceNode source) {
Leftovers leftovers = source.getLeftovers();
if (leftovers != null) {
// identify context match (if possible)
TransformationContext context = source.getContext();
if (context == null) {
// no transformation context match defined
log.warn(log.createMessage("Multiple values for source node w/o transformation context match", null));
} else {
Pair<SourceNode, Set<Cell>> leftover;
// completely consume leftovers
while ((leftover = leftovers.consumeValue()) != null) {
context.duplicateContext(source, leftover.getFirst(), leftover.getSecond(), log);
// XXX is this the place where this should be propagated to
// the duplicated source children?
// XXX trying it out
SourceNode node = leftover.getFirst();
Object value = node.getValue();
if (value instanceof Group) {
InstanceVisitor instanceVisitor = new InstanceVisitor(null, null, log);
for (SourceNode child : node.getChildren(instanceVisitor.includeAnnotatedNodes())) {
// annotate children with leftovers
child.accept(instanceVisitor);
// run the duplication on the children
child.accept(this);
}
}
}
}
}
return true;
}
use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.
the class InstanceValueLabelProvider method update.
/**
* @see CellLabelProvider#update(ViewerCell)
*/
@Override
public void update(ViewerCell cell) {
TreePath treePath = cell.getViewerRow().getTreePath();
Object element = treePath.getLastSegment();
Definition<?> definition = null;
Object value = ((Pair<?, ?>) element).getSecond();
if (((Pair<?, ?>) element).getFirst() instanceof Definition)
definition = (Definition<?>) ((Pair<?, ?>) element).getFirst();
InstanceValidationReport report = null;
if (definition instanceof ChildDefinition<?>) {
report = validator.validate(value, (ChildDefinition<?>) ((Pair<?, ?>) element).getFirst());
} else if (definition instanceof TypeDefinition) {
report = validator.validate((Instance) value);
}
boolean hasValue = false;
if (value instanceof Instance) {
hasValue = ((Instance) value).getValue() != null;
}
StyledString styledString;
if (value == null) {
styledString = new StyledString("no value", StyledString.DECORATIONS_STYLER);
} else if (value instanceof Group && !hasValue) {
styledString = new StyledString("+", StyledString.QUALIFIER_STYLER);
} else {
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
// TODO some kind of conversion?
String stringValue = value.toString();
/*
* Values that are very large, e.g. string representations of very
* complex geometries lead to
* StyledCellLabelProvider.updateTextLayout taking a very long time,
* rendering the application unresponsive when the data views are
* displayed. As such, we reduce the string to a maximum size.
*/
if (stringValue.length() > MAX_STRING_LENGTH) {
stringValue = stringValue.substring(0, MAX_STRING_LENGTH) + "...";
}
styledString = new StyledString(stringValue, null);
}
cell.setText(styledString.toString());
cell.setStyleRanges(styledString.getStyleRanges());
if (report != null && !report.getWarnings().isEmpty()) {
cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
}
super.update(cell);
}
use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.
the class DefinitionInstanceLabelProvider method update.
/**
* @see CellLabelProvider#update(ViewerCell)
*/
@Override
public void update(ViewerCell cell) {
TreePath treePath = cell.getViewerRow().getTreePath();
InstanceEntry entry = findInstanceEntry(treePath);
Object value = entry.value;
InstanceValidationReport report = null;
// If childDef is null we are at the top element.
if (entry.definition && entry.childDef == null) {
report = validator.validate(instance);
}
boolean hasValue = false;
if (entry.definition && value instanceof Instance) {
hasValue = ((Instance) value).getValue() != null;
} else if (!entry.definition && treePath.getSegmentCount() == 1) {
// metadata root
if (instance.getMetaDataNames().isEmpty()) {
hasValue = true;
value = null;
}
}
StyledString styledString;
if (value == null) {
styledString = new StyledString("no value", StyledString.DECORATIONS_STYLER);
} else if (value instanceof Group && !hasValue) {
styledString = new StyledString("+", StyledString.QUALIFIER_STYLER);
} else {
if (value instanceof Instance) {
value = ((Instance) value).getValue();
}
// TODO some kind of conversion?
String stringValue = value.toString();
/*
* Values that are very large, e.g. string representations of very
* complex geometries lead to
* StyledCellLabelProvider.updateTextLayout taking a very long time,
* rendering the application unresponsive when the data views are
* displayed. As such, we reduce the string to a maximum size.
*/
if (stringValue.length() > MAX_STRING_LENGTH) {
stringValue = stringValue.substring(0, MAX_STRING_LENGTH) + "...";
}
styledString = new StyledString(stringValue, null);
}
// mark cell if there are other values
if (entry.valueCount > 1) {
String decoration = " " + MessageFormat.format(MULTIPLE_VALUE_FORMAT, entry.choice + 1, entry.valueCount);
styledString.append(decoration, StyledString.COUNTER_STYLER);
}
cell.setText(styledString.toString());
cell.setStyleRanges(styledString.getStyleRanges());
if (report != null && !report.getWarnings().isEmpty())
cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
super.update(cell);
}
Aggregations