Search in sources :

Example 26 with Group

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

the class AbstractTableInstanceWriter method getPropertyMap.

/**
 * Iterates over properties of the instance and creates a map of the given
 * properties
 *
 * @param instance the Instance to check
 * @param headerRow the current header row of the table
 * @param solveNestedProperties <code>true</code> if nested properties
 *            should be solved, otherwise <code>false</code>
 * @return a map of properties with string of localpart of the QName of the
 *         property as key
 */
protected Map<String, Object> getPropertyMap(Instance instance, List<String> headerRow, boolean solveNestedProperties) {
    // properties of current instance
    Iterable<QName> allProperties = instance.getPropertyNames();
    // write properties to map; currently only the first property of nested
    // properties is selected
    Map<String, Object> row = new HashMap<String, Object>();
    for (QName qname : allProperties) {
        // get properties of the current instance
        Object[] properties = instance.getProperty(qname);
        if (properties != null && properties.length != 0) {
            String cellValue = "";
            // only the first property is evaluated
            Object property = properties[0];
            if (shouldBeDisplayed(property)) {
                cellValue = qname.getLocalPart();
            }
            // if property is an OInstance or OGroup, it's a nested property
            if (solveNestedProperties && property instanceof Group) {
                Group nextInstance = (Group) property;
                iterateBuild(nextInstance, qname, headerRow, row, cellValue);
            // Group inst = (Group) property;
            // // check if property has a value and add it
            // checkValue(inst, headerRow, row, cellValue);
            // // go through nested properties to get other properties
            // Iterator<QName> propertyIt = inst.getPropertyNames().iterator();
            // if (propertyIt.hasNext()) {
            // QName value = propertyIt.next();
            // Object nextProp = inst.getProperty(value)[0];
            // // check if current property should be displayed in map
            // if (shouldBeDisplayed(nextProp)) {
            // cellValue += ".";
            // cellValue += value.getLocalPart();
            // }
            // 
            // // iterate over all nested properties
            // while (nextProp instanceof Group) {
            // Group oinst = (Group) nextProp;
            // checkValue(oinst, headerRow, row, cellValue);
            // 
            // // get localparts of all nested properties
            // Iterator<QName> qnames = oinst.getPropertyNames().iterator();
            // if (qnames.hasNext()) {
            // value = qnames.next();
            // nextProp = oinst.getProperty(value)[0];
            // if (shouldBeDisplayed(nextProp)) {
            // cellValue += ".";
            // cellValue += value.getLocalPart();
            // }
            // else
            // continue;
            // }
            // else
            // break;
            // }
            // // add property with corresponding cellValue (localpart)
            // // to map
            // // no resolving of nested properties
            // addProperty(headerRow, row, nextProp, cellValue);
            // }
            } else {
                // map
                if (property instanceof Group && shouldBeDisplayed(property)) {
                    checkValue((Group) property, headerRow, row, cellValue);
                } else {
                    addProperty(headerRow, row, property, cellValue);
                }
            }
        }
    }
    return row;
}
Also used : Group(eu.esdihumboldt.hale.common.instance.model.Group) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName)

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