use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class AppSchemaMappingTest method getDefaultTypeCell.
private Cell getDefaultTypeCell(TypeDefinition sourceType, TypeDefinition targetType) {
DefaultCell typeCell = new DefaultCell();
typeCell.setTransformationIdentifier(RetypeFunction.ID);
ListMultimap<String, Type> source = ArrayListMultimap.create();
source.put(null, new DefaultType(new TypeEntityDefinition(sourceType, SchemaSpaceID.SOURCE, null)));
ListMultimap<String, Type> target = ArrayListMultimap.create();
target.put(null, new DefaultType(new TypeEntityDefinition(targetType, SchemaSpaceID.TARGET, null)));
typeCell.setSource(source);
typeCell.setTarget(target);
return typeCell;
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class EntityVisitor method accept.
/**
* Apply the visitor on a type entity definition.
*
* @param ted the type entity definition
*/
public void accept(TypeEntityDefinition ted) {
if (visit(ted)) {
for (ChildDefinition<?> child : ted.getDefinition().getChildren()) {
EntityDefinition ed = AlignmentUtil.getChild(ted, child.getName());
accept(ed);
}
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class CityGMLPropagate method generateMapping.
private void generateMapping() {
System.out.println("Indexing example cells...");
// index all cells based on the target property name
SetMultimap<String, Cell> bgisExamples = HashMultimap.create();
SetMultimap<QName, Cell> cityGMLExamples = HashMultimap.create();
for (Cell cell : examples.getCells()) {
if (cell.getTarget().size() == 1) {
// only supports cells with one target
EntityDefinition entityDef = CellUtil.getFirstEntity(cell.getTarget()).getDefinition();
// XXX check source?!
if (entityDef.getDefinition() instanceof PropertyDefinition) {
QName name = entityDef.getDefinition().getName();
if (ADE_NS.equals(name.getNamespaceURI())) {
bgisExamples.put(name.getLocalPart(), cell);
} else if (name.getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE)) {
// XXX only support level 1 properties?
cityGMLExamples.put(name, cell);
} else
System.out.println("WARNING: ignoring cell with target property neither from CityGML nor from BGIS ADE");
} else
System.out.println("WARNING: ignoring type cell");
} else
System.out.println("WARNING: ignoring cell with multiple or no targets");
}
// collect all ADE feature types
List<TypeDefinition> featureTypes = BGISAppUtil.getADEFeatureTypes(targetSchema);
// collect ADE display names
Set<String> adeTypeNames = new HashSet<String>();
for (TypeDefinition type : featureTypes) {
adeTypeNames.add(type.getDisplayName());
}
// collect possibly relevant target CityGML feature types
for (TypeDefinition type : targetSchema.getTypes()) {
if (type.getName().getNamespaceURI().startsWith(CITYGML_NAMESPACE_CORE) && BGISAppUtil.isFeatureType(type)) {
if (!adeTypeNames.contains(type.getDisplayName())) {
/*
* But ensure to only add those that do not share the
* display name with an ADE type, as in the feature map the
* type identification is only done on based on the display
* name, and ADE types take precedent.
*/
featureTypes.add(type);
}
}
}
// visit ADE properties and create cells
System.out.println("Generating mapping from example cells for");
String cellNote = MessageFormat.format("Generated through propagation of example cells on CityGML and BGIS ADE feature types.\n" + "{0,date,medium}", new Date());
CityGMLPropagateVisitor visitor = new CityGMLPropagateVisitor(cityGMLSource, bgisExamples, cityGMLExamples, config, cellNote);
for (TypeDefinition type : featureTypes) {
System.out.println(type.getDisplayName() + "...");
visitor.accept(new TypeEntityDefinition(type, SchemaSpaceID.TARGET, null));
}
if (visitor.getCells().isEmpty()) {
System.out.println("WARNING: no cells were created");
} else {
System.out.println(visitor.getCells().size() + " cells were created.");
}
// create alignment
MutableAlignment align = new DefaultAlignment();
for (MutableCell cell : visitor.getCells()) {
align.addCell(cell);
}
this.alignment = align;
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class AlignmentUtil method getChildrenWithoutContexts.
/**
* Get children of an {@link Entity} without context conditions
*
* @param entity the entity definition
* @return Collection of entity definitions
*/
public static List<PropertyEntityDefinition> getChildrenWithoutContexts(Entity entity) {
TypeEntityDefinition ted = (TypeEntityDefinition) entity.getDefinition();
List<PropertyEntityDefinition> childProperties = new ArrayList<>();
for (EntityDefinition child : getChildrenWithoutContexts(ted)) {
if (child instanceof PropertyEntityDefinition) {
childProperties.add((PropertyEntityDefinition) child);
}
}
return childProperties;
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class AlignmentUtil method reparentCell.
/**
* Returns a cell like the given property cell with all source and target
* types matching those off the given type cell.<br>
* If the types already match they are unchanged. If the types are sub types
* of the types of the type cell they are changed. If no change is necessary
* the cell itself is returned.
*
* @param propertyCell the property cell to update
* @param typeCell the type cell with the target types
* @param strict If false and the target type cell has no sources or target,
* the property cell is updated to have the sources/target in
* their declaring type. If true, said properties are left
* unchanged. Does not matter for complete type cells, since they
* have sources and a target.
* @return the updated cell or <code>null</code> if an update isn't possible
*/
public static Cell reparentCell(Cell propertyCell, Cell typeCell, boolean strict) {
ListMultimap<String, Entity> sources = ArrayListMultimap.create();
ListMultimap<String, Entity> targets = ArrayListMultimap.create();
boolean updateNecessary = false;
// XXX are updates to the property path needed?
// Currently not, since ChildDefinitions are compared by their names
// only.
// TARGETS
Entity targetEntity = CellUtil.getFirstEntity(typeCell.getTarget());
if (targetEntity != null) {
TypeDefinition typeCellTargetType = ((Type) targetEntity).getDefinition().getDefinition();
for (Entry<String, ? extends Entity> target : propertyCell.getTarget().entries()) {
TypeDefinition propertyCellTargetType = target.getValue().getDefinition().getType();
if (propertyCellTargetType.equals(typeCellTargetType))
targets.put(target.getKey(), target.getValue());
else if (DefinitionUtil.isSuperType(typeCellTargetType, propertyCellTargetType)) {
PropertyEntityDefinition oldDef = (PropertyEntityDefinition) target.getValue().getDefinition();
targets.put(target.getKey(), new DefaultProperty(new PropertyEntityDefinition(typeCellTargetType, oldDef.getPropertyPath(), SchemaSpaceID.TARGET, null)));
updateNecessary = true;
} else {
// a cell with targets in more than one type
return null;
}
}
} else if (!strict)
updateNecessary |= reparentToDeclaring(propertyCell.getTarget(), targets);
else
targets.putAll(propertyCell.getTarget());
if (propertyCell.getSource() != null && !propertyCell.getSource().isEmpty()) {
if (typeCell.getSource() != null && !typeCell.getSource().isEmpty()) {
// collect source entity definitions
Collection<TypeEntityDefinition> typeCellSourceTypes = new ArrayList<TypeEntityDefinition>();
for (Entity entity : typeCell.getSource().values()) typeCellSourceTypes.add((TypeEntityDefinition) entity.getDefinition());
for (Entry<String, ? extends Entity> source : propertyCell.getSource().entries()) {
TypeEntityDefinition propertyCellSourceType = getTypeEntity(source.getValue().getDefinition());
if (typeCellSourceTypes.contains(propertyCellSourceType))
sources.put(source.getKey(), source.getValue());
else {
boolean matchFound = false;
// maybe the whole cell should be duplicated?
for (TypeEntityDefinition typeCellSourceType : typeCellSourceTypes) {
if (DefinitionUtil.isSuperType(typeCellSourceType.getDefinition(), propertyCellSourceType.getDefinition()) && (propertyCellSourceType.getFilter() == null || propertyCellSourceType.getFilter().equals(typeCellSourceType.getFilter()))) {
if (matchFound)
log.warn("Inherited property cell source matches multiple sources of type cell.");
matchFound = true;
PropertyEntityDefinition oldDef = (PropertyEntityDefinition) source.getValue().getDefinition();
sources.put(source.getKey(), new DefaultProperty(new PropertyEntityDefinition(typeCellSourceType.getDefinition(), oldDef.getPropertyPath(), SchemaSpaceID.SOURCE, typeCellSourceType.getFilter())));
updateNecessary = true;
// XXX break; if only one match should be added
}
}
if (!matchFound) {
// cell
return null;
}
}
}
} else if (!strict)
updateNecessary |= reparentToDeclaring(propertyCell.getSource(), sources);
else
targets.putAll(propertyCell.getTarget());
}
if (updateNecessary) {
MutableCell copy = new DefaultCell(propertyCell);
copy.setSource(sources);
copy.setTarget(targets);
propertyCell = copy;
}
return propertyCell;
}
Aggregations