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);
}
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];
}
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;
}
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");
}
}
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);
}
Aggregations