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