Search in sources :

Example 11 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class JacksonMapper method skipChoice.

/**
 * Handles skipping choice groups.
 *
 * @param propertyName the start property name
 * @param obj the object to inspect
 * @param reporter the reporter
 * @return a pair of property name and value to use
 */
private Pair<String, Object> skipChoice(String propertyName, Object obj, IOReporter reporter) {
    if (obj instanceof Group) {
        Group group = (Group) obj;
        // For choices search for the (only!) child and skip the choice.
        if (group.getDefinition() instanceof GroupPropertyDefinition) {
            if (((GroupPropertyDefinition) group.getDefinition()).getConstraint(ChoiceFlag.class).isEnabled()) {
                Iterator<QName> childPropertyNames = group.getPropertyNames().iterator();
                if (!childPropertyNames.hasNext()) {
                    reporter.warn(new IOMessageImpl("Found an empty choice.", null));
                    return null;
                }
                QName childPropertyName = childPropertyNames.next();
                Object[] values = group.getProperty(childPropertyName);
                Object value = values[0];
                if (childPropertyNames.hasNext() || values.length > 1)
                    reporter.warn(new IOMessageImpl("Found a choice with multiple children. Using first.", null));
                // delegate to only value
                return skipChoice(childPropertyName.getLocalPart(), value, reporter);
            }
        }
    }
    return new Pair<>(propertyName, obj);
}
Also used : GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) Group(eu.esdihumboldt.hale.common.instance.model.Group) QName(javax.xml.namespace.QName) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) ChoiceFlag(eu.esdihumboldt.hale.common.schema.model.constraint.property.ChoiceFlag) Pair(eu.esdihumboldt.util.Pair)

Example 12 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class InstanceContentProvider method getChildren.

/**
 * @see ITreeContentProvider#getChildren(Object)
 */
@Override
public Object[] getChildren(Object parentElement) {
    boolean isMetaData = false;
    if (parentElement instanceof Pair<?, ?>) {
        Pair<?, ?> pair = (Pair<?, ?>) parentElement;
        parentElement = pair.getSecond();
        if (pair.getFirst() == Metadata.METADATA && pair.getSecond() instanceof Instance) {
            isMetaData = true;
        }
    }
    if (parentElement instanceof Group && isMetaData == false) {
        Group group = (Group) parentElement;
        List<Object> children = new ArrayList<Object>();
        for (QName name : group.getPropertyNames()) {
            Definition<?> childDef = group.getDefinition().getChild(name);
            for (Object value : group.getProperty(name)) {
                children.add(new Pair<Object, Object>(childDef, value));
            }
        }
        return children.toArray();
    }
    if (parentElement instanceof Group && isMetaData == true) {
        Instance inst = (Instance) parentElement;
        List<Object> metachildren = new ArrayList<Object>();
        for (String key : inst.getMetaDataNames()) {
            List<Object> values = inst.getMetaData(key);
            for (Object value : values) {
                metachildren.add(new Pair<String, Object>(key, value));
            }
        }
        return metachildren.toArray();
    }
    return new Object[0];
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Pair(eu.esdihumboldt.util.Pair)

Example 13 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class InstanceContentProvider method hasChildren.

/**
 * @see ITreeContentProvider#hasChildren(Object)
 */
@Override
public boolean hasChildren(Object element) {
    if (element instanceof Pair<?, ?>) {
        Pair<?, ?> pair = (Pair<?, ?>) element;
        if (pair.getFirst() == Metadata.METADATA && pair.getSecond() instanceof Instance) {
            return true;
        }
        element = pair.getSecond();
    }
    if (element instanceof Group) {
        Group group = (Group) element;
        return !Iterables.isEmpty(group.getPropertyNames());
    }
    return false;
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) Pair(eu.esdihumboldt.util.Pair)

Example 14 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class TreeGraphMLProvider method setVertexProperty.

/**
 * sets the property of a [@link]Vertex from a [@link]TransformationNode
 *
 * @param node the node-object to get the name from
 * @param vertex the vertex to set the property
 */
private void setVertexProperty(TransformationNode node, Vertex vertex) {
    if (node instanceof TransformationTree) {
        vertex.setProperty("name", ((TransformationTree) node).getType().getDisplayName());
        vertex.setProperty("type", "root");
    }
    if (node instanceof TargetNode) {
        vertex.setProperty("name", ((TargetNode) node).getDefinition().getDisplayName());
        vertex.setProperty("type", "target");
    }
    if (node instanceof SourceNode) {
        SourceNode snode = (SourceNode) node;
        Object value = snode.getValue();
        String name = ((SourceNode) node).getDefinition().getDisplayName();
        if (value instanceof Group) {
            vertex.setProperty("name", name);
            vertex.setProperty("group", getChildrencountString(value));
            vertex.setProperty("type", "source");
        }
        if (value instanceof Instance) {
            if (((Instance) value).getValue() != null) {
                vertex.setProperty("group", getChildrencountString(value));
                vertex.setProperty("value", ((Instance) value).getValue().toString());
                vertex.setProperty("type", "source");
            }
        } else {
            vertex.setProperty("name", name);
            vertex.setProperty("type", "source");
            if (value instanceof String) {
                vertex.setProperty("value", value);
            }
        }
    }
    if (node instanceof CellNode) {
        vertex.setProperty("name", FunctionUtil.getFunction(((CellNode) node).getCell().getTransformationIdentifier(), null).getDisplayName());
        vertex.setProperty("type", "cell");
    }
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) TargetNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) TransformationTree(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationTree)

Example 15 with Group

use of eu.esdihumboldt.hale.common.instance.model.Group in project hale by halestudio.

the class TransformationTreeLabelProvider method getText.

/**
 * @see GraphLabelProvider#getText(Object)
 */
@Override
public String getText(Object element) {
    if (element instanceof IdentityWrapper<?>) {
        element = ((IdentityWrapper<?>) element).getValue();
    }
    if (element instanceof EntityConnectionData) {
        // text for connections
        EntityConnectionData connection = (EntityConnectionData) element;
        Set<String> names = null;
        Object source = connection.source;
        if (source instanceof IdentityWrapper<?>) {
            source = ((IdentityWrapper<?>) source).getValue();
        }
        Object dest = connection.dest;
        if (dest instanceof IdentityWrapper<?>) {
            dest = ((IdentityWrapper<?>) dest).getValue();
        }
        if (source instanceof TargetNode && dest instanceof CellNode) {
            names = ((TargetNode) source).getAssignmentNames((CellNode) dest);
        }
        if (source instanceof CellNode && dest instanceof SourceNode) {
            names = ((CellNode) source).getSourceNames((SourceNode) dest);
        }
        if (names != null && !names.isEmpty()) {
            if (names.contains(null)) {
                names = new HashSet<String>(names);
                names.remove(null);
                if (!names.isEmpty()) {
                    names.add("(unnamed)");
                }
            }
            // build name string
            Joiner joiner = Joiner.on(',');
            return joiner.join(names);
        }
        return "";
    }
    if (hasTransformationAnnotations(element)) {
        if (element instanceof SourceNode) {
            SourceNode node = (SourceNode) element;
            if (node.isDefined()) {
                Object value = node.getValue();
                if (value == null) {
                    // no value
                    return "(not set)";
                } else if (value instanceof Instance) {
                    // use the instance value if present
                    value = ((Instance) value).getValue();
                }
                if (value != null && !(value instanceof Group)) {
                    // TODO shorten if needed?
                    return value.toString();
                }
            // otherwise, just display the definition name
            }
        }
    }
    element = TransformationTreeUtil.extractObject(element);
    return super.getText(element);
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) 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) Joiner(com.google.common.base.Joiner) EntityConnectionData(org.eclipse.zest.core.viewers.EntityConnectionData) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) IdentityWrapper(eu.esdihumboldt.util.IdentityWrapper)

Aggregations

Group (eu.esdihumboldt.hale.common.instance.model.Group)26 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)15 QName (javax.xml.namespace.QName)10 ArrayList (java.util.ArrayList)6 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)5 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)5 SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)4 Pair (eu.esdihumboldt.util.Pair)4 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)3 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 CellNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode)2 TargetNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.TargetNode)2 TransformationContext (eu.esdihumboldt.hale.common.align.model.transformation.tree.context.TransformationContext)2 InstanceValidationReport (eu.esdihumboldt.hale.common.instance.extension.validation.report.InstanceValidationReport)2 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)2 DefinitionGroup (eu.esdihumboldt.hale.common.schema.model.DefinitionGroup)2 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)2 HasValueFlag (eu.esdihumboldt.hale.common.schema.model.constraint.type.HasValueFlag)2 LinkedList (java.util.LinkedList)2