Search in sources :

Example 51 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class AbstractAlignmentMappingExport method addCellData.

// get the information of the cell and add them to the map
private void addCellData(Cell cell) {
    Map<CellType, CellInformation> cellInfos = new HashMap<CellType, CellInformation>();
    // create all entries
    List<CellType> cellTypes = getCellTypes();
    for (int i = 0; i < cellTypes.size(); i++) {
        cellInfos.put(cellTypes.get(i), new CellInformation());
    }
    cellInfos.get(CellType.ID).addText(cell.getId(), 0);
    if (cell.getSource() != null) {
        // save the hierarchy of the properties
        // all entries (in the same CellInfo) with the same hierarchy level
        // have to be shown on the same height
        int position = 0;
        for (Entity entity : cell.getSource().values()) {
            // column source type
            cellInfos.get(CellType.SOURCE_TYPE).addText(entity.getDefinition().getType().getName().getLocalPart(), position);
            if (includeNamespaces)
                // column source type namespace
                cellInfos.get(CellType.SOURCE_TYPE_NAMESPACE).addText(entity.getDefinition().getType().getName().getNamespaceURI(), position);
            // column source type conditions
            Filter entityFilter;
            if ((entityFilter = entity.getDefinition().getFilter()) != null) {
                cellInfos.get(CellType.SOURCE_TYPE_CONDITIONS).addText(FilterDefinitionManager.getInstance().asString(entityFilter), position);
                entity.getDefinition().getType().getName().getLocalPart();
            }
            for (ChildContext childContext : entity.getDefinition().getPropertyPath()) {
                PropertyDefinition child = childContext.getChild().asProperty();
                if (child != null) {
                    // column source properties
                    cellInfos.get(CellType.SOURCE_PROPERTIES).addText(child.getName().getLocalPart(), position);
                    if (includeNamespaces)
                        // column source properties namespace
                        cellInfos.get(CellType.SOURCE_PROPERTIES_NAMESPACE).addText(child.getName().getNamespaceURI(), position);
                    Filter contextFilter;
                    if (childContext.getCondition() != null) {
                        contextFilter = childContext.getCondition().getFilter();
                        // column source property conditions
                        cellInfos.get(CellType.SOURCE_PROPERTY_CONDITIONS).addText(FilterDefinitionManager.getInstance().asString(contextFilter), position);
                    }
                    // add dummy to adapt position of source type and source
                    // type conditions
                    cellInfos.get(CellType.SOURCE_TYPE).addText("", position);
                    cellInfos.get(CellType.SOURCE_TYPE_CONDITIONS).addText("", position);
                    position++;
                }
            }
            // next entries must have higher position
            position++;
        }
    }
    if (cell.getTarget() != null) {
        int position = 0;
        for (Entity entity : cell.getTarget().values()) {
            // column target type
            cellInfos.get(CellType.TARGET_TYPE).addText(entity.getDefinition().getType().getDisplayName(), position);
            if (includeNamespaces)
                // column target type namespace
                cellInfos.get(CellType.TARGET_TYPE_NAMESPACE).addText(entity.getDefinition().getType().getName().getNamespaceURI(), position);
            for (ChildContext childContext : entity.getDefinition().getPropertyPath()) {
                PropertyDefinition child = childContext.getChild().asProperty();
                if (child != null) {
                    // column target properties
                    cellInfos.get(CellType.TARGET_PROPERTIES).addText(child.getName().getLocalPart(), position);
                    if (includeNamespaces)
                        // column target properties namespace
                        cellInfos.get(CellType.TARGET_PROPERTIES_NAMESPACE).addText(child.getName().getNamespaceURI(), position);
                    // add dummy to adapt position of target type
                    cellInfos.get(CellType.TARGET_TYPE).addText("", position);
                    position++;
                }
            }
            position++;
        }
    }
    FunctionDefinition<?> function = FunctionUtil.getFunction(cell.getTransformationIdentifier(), getServiceProvider());
    if (function != null) {
        // column relation name
        cellInfos.get(CellType.RELATION_NAME).addText(function.getDisplayName(), 0);
        // column cell explanation
        CellExplanation cellExpl = function.getExplanation();
        if (cellExpl != null) {
            cellInfos.get(CellType.CELL_EXPLANATION).addText(function.getExplanation().getExplanation(cell, null), 0);
        }
    }
    // column cell notes
    List<String> docs = cell.getDocumentation().get(null);
    if (!docs.isEmpty()) {
        String notes = docs.get(0);
        if (notes != null && !notes.isEmpty()) {
            cellInfos.get(CellType.CELL_NOTES).addText(notes, 0);
        }
    }
    // cell priority
    cellInfos.get(CellType.PRIORITY).addText(cell.getPriority().value(), 0);
    // base cell
    if (cell.isBaseCell()) {
        cellInfos.get(CellType.BASE_CELL).addText("yes", 0);
    } else {
        cellInfos.get(CellType.BASE_CELL).addText("no", 0);
    }
    // column transformation/disabled
    if (transformationAndDisabledMode) {
        if (AlignmentUtil.isTypeCell(cell)) {
            currentTypeCell = cell;
            cellInfos.get(CellType.TRANSFORMATION_AND_DISABLED).addText(cell.getTransformationMode().displayName(), 0);
        } else {
            Set<String> disabledCells = cell.getDisabledFor();
            if (disabledCells.contains(currentTypeCell.getId())) {
                for (String disCell : disabledCells) {
                    cellInfos.get(CellType.TRANSFORMATION_AND_DISABLED).addText(disCell, 0);
                }
            }
        }
    }
    // add the row to the map
    allRelations.add(cellInfos);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) HashMap(java.util.HashMap) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) CellExplanation(eu.esdihumboldt.hale.common.align.model.CellExplanation) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 52 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class FormattedStringFunction method addValue.

/**
 * Add a value to the given map of values, with the variable names derived
 * from the associated property definition.
 *
 * @param values the map associating variable names to values
 * @param value the value
 * @param property the associated property
 */
public static void addValue(Map<String, Object> values, Object value, PropertyEntityDefinition property) {
    // determine the variable name
    String name = property.getDefinition().getName().getLocalPart();
    // name is overridden
    if (!values.keySet().contains(name) || property.getPropertyPath().size() == 1) {
        values.put(name, value);
    }
    // add with long name if applicable
    if (property.getPropertyPath().size() > 1) {
        List<String> names = new ArrayList<String>();
        for (ChildContext context : property.getPropertyPath()) {
            names.add(context.getChild().getName().getLocalPart());
        }
        String longName = Joiner.on('.').join(names);
        values.put(longName, value);
    }
}
Also used : ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 53 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class MergeUtil method resolvePropertyPath.

/**
 * Get the property path for a value representing a property configured as
 * Merge function parameter and resolve it to an entity definition.
 *
 * @param value the value representation of the parameter
 * @param parentType the parent type of the property (the type that is
 *            merged)
 * @return the entity definition resolved from the property path
 * @throws IllegalStateException if the property path cannot be resolved
 */
public static EntityDefinition resolvePropertyPath(Value value, TypeDefinition parentType) {
    List<QName> propertyPath = MergeUtil.getPropertyPath(value);
    List<ChildDefinition<?>> path = new ArrayList<>();
    Definition<?> parent = parentType;
    for (QName element : propertyPath) {
        ChildDefinition<?> child = DefinitionUtil.getChild(parent, element);
        if (child != null) {
            path.add(child);
            parent = child;
        } else {
            throw new IllegalStateException("Could not resolve child " + element + " in parent " + parent);
        }
    }
    if (path.isEmpty()) {
        throw new IllegalStateException("No elements in property path");
    }
    List<ChildContext> contexts = path.stream().map(ChildContext::new).collect(Collectors.toList());
    return AlignmentUtil.createEntity(parentType, contexts, SchemaSpaceID.SOURCE, null);
}
Also used : QName(javax.xml.namespace.QName) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 54 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class AbstractCellExplanation method getEntityNameWithoutCondition.

/**
 * Returns an entity name without condition strings (e.g. "part1.part2").
 *
 * @param entity the entity
 * @return the entity name
 */
protected String getEntityNameWithoutCondition(Entity entity) {
    EntityDefinition entityDef = entity.getDefinition();
    if (entityDef.getPropertyPath() != null && !entityDef.getPropertyPath().isEmpty()) {
        List<String> names = new ArrayList<String>();
        for (ChildContext context : entityDef.getPropertyPath()) {
            names.add(context.getChild().getName().getLocalPart());
        }
        String longName = Joiner.on('.').join(names);
        return longName;
    } else
        return entityDef.getDefinition().getDisplayName();
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 55 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext in project hale by halestudio.

the class ChildEntityDefinition method toString.

@Override
public String toString() {
    StringBuffer result = new StringBuffer(getType().toString());
    for (ChildContext childContext : getPropertyPath()) {
        result.append('/');
        result.append(childContext.getChild().getName().getLocalPart());
    }
    return result.toString();
}
Also used : ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Aggregations

ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)63 ArrayList (java.util.ArrayList)32 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)29 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)24 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)12 QName (javax.xml.namespace.QName)11 Property (eu.esdihumboldt.hale.common.align.model.Property)7 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 List (java.util.List)7 Condition (eu.esdihumboldt.hale.common.align.model.Condition)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)6 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)5 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)5 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)4 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)3 Type (eu.esdihumboldt.hale.common.align.model.Type)3 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3