use of eu.esdihumboldt.hale.app.bgis.ade.propagate.internal.TypeEntityIndex in project hale by halestudio.
the class CityGMLPropagateVisitor method propagateCell.
/**
* Propagate a given cell to the given target property and possible source
* types.
*
* @param exampleCell the example cell
* @param ped the target property
*/
private void propagateCell(Cell exampleCell, PropertyEntityDefinition ped) {
/*
* Find the type where the property actually is defined, as if possible
* a super type mapping should be used.
*/
TypeDefinition targetType = findTypeDefining(ped);
if (!targetType.equals(ped.getType())) {
ped = new PropertyEntityDefinition(targetType, ped.getPropertyPath(), ped.getSchemaSpace(), ped.getFilter());
}
// check if the cell was already handled for the type
if (handledTargets.get(exampleCell).contains(targetType)) {
// don't produce any duplicates
return;
}
handledTargets.put(exampleCell, targetType);
TypeEntityIndex<List<ChildContext>> index = new TypeEntityIndex<List<ChildContext>>();
Collection<TypeDefinition> sourceTypes = findSourceTypes(exampleCell, targetType, index);
if (sourceTypes != null) {
for (TypeDefinition sourceType : sourceTypes) {
// copy cell
DefaultCell cell = new DefaultCell(exampleCell);
// reset ID
cell.setId(null);
// assign new target
ListMultimap<String, Entity> target = ArrayListMultimap.create();
target.put(cell.getTarget().keys().iterator().next(), new DefaultProperty(ped));
cell.setTarget(target);
// assign new source(s)
ListMultimap<String, Entity> source = ArrayListMultimap.create();
for (Entry<String, ? extends Entity> entry : cell.getSource().entries()) {
// create new source entity
List<ChildContext> path = index.get(sourceType, entry.getValue());
if (path == null) {
throw new IllegalStateException("No replacement property path computed");
}
Property newSource = new DefaultProperty(new PropertyEntityDefinition(sourceType, path, SchemaSpaceID.SOURCE, null));
source.put(entry.getKey(), newSource);
}
cell.setSource(source);
BGISAppUtil.appendNote(cell, cellNote);
cells.add(cell);
}
}
}
Aggregations