Search in sources :

Example 16 with TypeEntityDefinition

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;
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType)

Example 17 with TypeEntityDefinition

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);
        }
    }
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.ChildEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition)

Example 18 with TypeEntityDefinition

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;
}
Also used : MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) QName(javax.xml.namespace.QName) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Date(java.util.Date) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashSet(java.util.HashSet)

Example 19 with TypeEntityDefinition

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;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.ChildEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList)

Example 20 with TypeEntityDefinition

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;
}
Also used : ArrayList(java.util.ArrayList) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Aggregations

TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)64 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)23 ArrayList (java.util.ArrayList)19 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)16 Type (eu.esdihumboldt.hale.common.align.model.Type)16 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)16 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)11 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)10 QName (javax.xml.namespace.QName)9 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)8 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)8 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)6 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 LinkedList (java.util.LinkedList)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)5 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)5