Search in sources :

Example 1 with TargetNode

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();
}
Also used : CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper) ArrayList(java.util.ArrayList) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)

Example 2 with TargetNode

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);
}
Also used : SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) EntityFigure(eu.esdihumboldt.hale.ui.common.graph.figures.EntityFigure) CustomShapeFigure(eu.esdihumboldt.hale.ui.util.graph.CustomShapeFigure) FingerPost(eu.esdihumboldt.hale.ui.util.graph.shapes.FingerPost) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) ShapePainter(eu.esdihumboldt.hale.ui.util.graph.CustomShapeFigure.ShapePainter) CustomShapeLabel(eu.esdihumboldt.hale.ui.util.graph.CustomShapeLabel) TransformationNodeShape(eu.esdihumboldt.hale.ui.common.graph.figures.TransformationNodeShape)

Example 3 with TargetNode

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);
    }
}
Also used : TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) PropertyTransformationFactory(eu.esdihumboldt.hale.common.align.extension.transformation.PropertyTransformationFactory) TransformationMessageImpl(eu.esdihumboldt.hale.common.align.transformation.report.impl.TransformationMessageImpl)

Example 4 with TargetNode

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;
    }
}
Also used : TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree) GroupNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode) TargetNodeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TargetNodeImpl)

Example 5 with TargetNode

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;
}
Also used : TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) GroupNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode) TargetNodeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TargetNodeImpl)

Aggregations

TargetNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode)13 SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)6 CellNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode)4 TransformationTree (eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)4 TargetNodeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.TargetNodeImpl)4 IdentityWrapper (eu.esdihumboldt.util.IdentityWrapper)3 MultiValue (eu.esdihumboldt.cst.MultiValue)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 GroupNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode)2 CellNodeImpl (eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.CellNodeImpl)2 Group (eu.esdihumboldt.hale.common.instance.model.Group)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 Pair (eu.esdihumboldt.util.Pair)2 ArrayList (java.util.ArrayList)2 Joiner (com.google.common.base.Joiner)1 PropertyTransformationFactory (eu.esdihumboldt.hale.common.align.extension.transformation.PropertyTransformationFactory)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 Entity (eu.esdihumboldt.hale.common.align.model.Entity)1 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)1 AbstractTargetToSourceVisitor (eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.AbstractTargetToSourceVisitor)1