use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode in project hale by halestudio.
the class TransformationTreeContentProvider method getChilddren.
/**
* Get the children of a node
*
* @param node the node
* @return the node's children
*/
private Collection<? extends Object> getChilddren(Object node) {
if (node instanceof IdentityWrapper<?>) {
node = ((IdentityWrapper<?>) node).getValue();
}
if (node instanceof TransformationTree) {
return wrapNodes(((TransformationTree) node).getChildren(true));
}
if (node instanceof TargetNode) {
List<Object> children = new ArrayList<Object>();
children.addAll(((TargetNode) node).getChildren(true));
children.addAll(((TargetNode) node).getAssignments());
return wrapNodes(children);
}
if (node instanceof CellNode) {
return wrapNodes(((CellNode) node).getSources());
}
if (node instanceof SourceNode) {
SourceNode parent = ((SourceNode) node).getParent();
if (parent != null) {
return Collections.singleton(new IdentityWrapper<Object>(parent));
}
}
return Collections.emptyList();
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode in project hale by halestudio.
the class TransformationTreeLabelProvider method getFigure.
/**
* @see GraphLabelProvider#getFigure(Object)
*/
@Override
public IFigure getFigure(Object element) {
if (element instanceof IdentityWrapper<?>) {
element = ((IdentityWrapper<?>) element).getValue();
}
ShapePainter shape = null;
String contextText = null;
String cardText = null;
if (element instanceof TransformationTree) {
shape = new TransformationNodeShape(10, SWT.NONE);
} else if (element instanceof TargetNode) {
TargetNode node = (TargetNode) element;
contextText = AlignmentUtil.getContextText(node.getEntityDefinition());
if (!hasTransformationAnnotations(element)) {
cardText = getCardinalityText(node.getEntityDefinition().getDefinition());
}
if (node.getAssignments().isEmpty()) {
shape = new TransformationNodeShape(10, SWT.NONE);
} else {
// shape = new TransformationNodeShape(10, SWT.LEFT);
shape = new FingerPost(10, SWT.LEFT);
}
} else if (element instanceof SourceNode) {
SourceNode node = (SourceNode) element;
contextText = AlignmentUtil.getContextText(node.getEntityDefinition());
if (!hasTransformationAnnotations(element)) {
cardText = getCardinalityText(node.getEntityDefinition().getDefinition());
}
if (node.getParent() == null) {
shape = new TransformationNodeShape(10, SWT.NONE);
} else {
shape = new FingerPost(10, SWT.RIGHT);
}
}
if (shape != null) {
CustomShapeFigure figure;
if (contextText != null || cardText != null) {
figure = new EntityFigure(shape, contextText, cardText, getCustomFigureFont());
} else {
figure = new CustomShapeLabel(shape, getCustomFigureFont());
}
figure.setMaximumWidth(MAX_FIGURE_WIDTH);
return figure;
}
element = TransformationTreeUtil.extractObject(element);
return super.getFigure(element);
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode in project hale by halestudio.
the class FunctionExecutor method processValid.
/**
* @see CellNodeValidator#processValid(Cell, ListMultimap, ListMultimap)
*/
@Override
protected void processValid(Cell cell, ListMultimap<String, Pair<SourceNode, Entity>> sources, ListMultimap<String, Pair<TargetNode, Entity>> targets) {
if (cell.getPriority() != functionPriority) {
// ignore the priorities that do not match
return;
}
/*
* if the result node is only one and its value had already been set, it
* is not necessary to execute this function of a lower priority. (if
* there are more than one target node we will need to execute them all
* and check at the end of the transformation.
*/
if (targets.size() == 1) {
TargetNode targetNode = targets.values().iterator().next().getFirst();
if (targetNode.isDefined()) {
// pass
return;
}
}
String functionId = cell.getTransformationIdentifier();
List<PropertyTransformationFactory> transformations = this.transformations.getPropertyTransformations(functionId);
if (transformations == null || transformations.isEmpty()) {
reporter.error(new TransformationMessageImpl(cell, MessageFormat.format("No transformation for function {0} found. Skipping property transformation.", functionId), null));
} else {
// TODO select based on e.g. preferred transformation engine?
PropertyTransformationFactory transformation = transformations.iterator().next();
executeTransformation(transformation, cell, sources, targets);
}
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode in project hale by halestudio.
the class TargetContext method duplicateTree.
/**
* Duplicates the transformation tree for the given target node to the given
* duplicate target node.
*
* @param target the original target node
* @param info the duplication info object
* @param log the transformation log
* @return a collection of newly created target nodes
*/
private static TargetNodeImpl duplicateTree(TargetNode target, DuplicationInformation info, TransformationLog log) {
GroupNode parent = null;
// Check if the parent node exists in the given context already.
if (target.getParent() instanceof TargetNode) {
Iterator<TargetNode> possibleParents = info.getAllTargetNodes(((TargetNode) target.getParent()).getEntityDefinition()).iterator();
while (possibleParents.hasNext()) {
TargetNode possibleParent = possibleParents.next();
if (info.getContextTargets().contains(target) || !possibleParent.getChildren(false).contains(target)) {
parent = possibleParent;
break;
}
}
} else if (target.getParent() instanceof TransformationTree && info.getContextTargets().contains(target)) {
// Reached root, but this is a possible target.
parent = target.getParent();
} else {
// Reached root, but this is no possible target or the parent is
// null!
// XXX instead log and return null or not connected TargetNode? See
// T O D O below
log.warn(log.createMessage("DuplicationContext present, but no matching target found.", null));
return null;
// throw new IllegalStateException(
// "DuplicationContext present, but no matching target found.");
}
if (parent == null) {
// Does not exist: recursion.
TargetNodeImpl duplicatedTarget = duplicateTree((TargetNode) target.getParent(), info, log);
if (duplicatedTarget == null) {
return null;
}
TargetNodeImpl newTarget = new TargetNodeImpl(target.getEntityDefinition(), duplicatedTarget);
info.addNewTargetNode(newTarget.getEntityDefinition(), newTarget);
duplicatedTarget.addChild(newTarget);
return newTarget;
} else {
// Exists: add as child.
TargetNodeImpl newTarget = new TargetNodeImpl(target.getEntityDefinition(), parent);
info.addNewTargetNode(newTarget.getEntityDefinition(), newTarget);
// as annotated child.
if (parent instanceof TargetNodeImpl && !parent.getChildren(false).contains(newTarget))
((TargetNodeImpl) parent).addChild(newTarget);
else
parent.addAnnotatedChild(newTarget);
return newTarget;
}
}
use of eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode in project hale by halestudio.
the class TargetContext method duplicateTarget.
/**
* Duplicate a target node.
*
* @param target the original target node
* @param relation the relation to associated to the target node
* @param duplicationContext the duplication context
* @return the duplicated target node or <code>null</code> if duplication
* was prohibited
*/
private TargetNode duplicateTarget(TargetNode target, CellNode relation, DuplicationContext duplicationContext) {
TargetNodeImpl duplicatedTarget = duplicationContext.getNode(target.getEntityDefinition());
if (duplicatedTarget == null) {
// target node not created yet
boolean duplicateParent = true;
if (contextTargets.contains(target)) {
// this is an endpoint, as such this is the last node to be
// duplicated
duplicateParent = false;
}
GroupNode duplicatedParent;
if (duplicateParent) {
GroupNode parent = target.getParent();
if (parent instanceof TargetNode) {
// create a duplicated parent
duplicatedParent = duplicateTarget((TargetNode) parent, null, duplicationContext);
if (duplicatedParent == null) {
return null;
}
} else {
// thus this is not a valid path for duplication
return null;
}
} else {
duplicatedParent = target.getParent();
}
// create duplicate
duplicatedTarget = new TargetNodeImpl(target.getEntityDefinition(), duplicatedParent);
// add as annotated child to parent
duplicatedParent.addAnnotatedChild(duplicatedTarget);
// add to duplication context
duplicationContext.addNode(duplicatedTarget, target);
}
if (relation != null) {
// assign relation
duplicatedTarget.addAssignment(target.getAssignmentNames(relation), relation);
}
return duplicatedTarget;
}
Aggregations