Search in sources :

Example 36 with EntityDefinition

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

the class PopulationContainer method getChildren.

/**
 * @see eu.esdihumboldt.hale.common.service.helper.population.IPopulationUpdater#getChildren(eu.esdihumboldt.hale.common.align.model.EntityDefinition)
 */
@Override
public Collection<? extends EntityDefinition> getChildren(EntityDefinition entityDef) {
    List<ChildContext> path = entityDef.getPropertyPath();
    Collection<? extends ChildDefinition<?>> children;
    if (path == null || path.isEmpty()) {
        // entity is a type, children are the type children
        children = entityDef.getType().getChildren();
    } else {
        // get parent context
        ChildContext parentContext = path.get(path.size() - 1);
        if (parentContext.getChild().asGroup() != null) {
            children = parentContext.getChild().asGroup().getDeclaredChildren();
        } else if (parentContext.getChild().asProperty() != null) {
            children = parentContext.getChild().asProperty().getPropertyType().getChildren();
        } else {
            throw new IllegalStateException("Illegal child definition type encountered");
        }
    }
    if (children == null || children.isEmpty()) {
        return Collections.emptyList();
    }
    Collection<EntityDefinition> result = new ArrayList<EntityDefinition>(children.size());
    for (ChildDefinition<?> child : children) {
        // add default child entity definition to result
        ChildContext context = new ChildContext(child);
        EntityDefinition defaultEntity = createEntity(entityDef.getType(), createPath(entityDef.getPropertyPath(), context), entityDef.getSchemaSpace(), entityDef.getFilter());
        result.add(defaultEntity);
    }
    return result;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 37 with EntityDefinition

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

the class UnmigratedCell method migrate.

/**
 * Perform the migration of the original cell and return the migrated cell.
 * The <code>UnmigratedCell</code> instance is not changed.
 *
 * @param additionalMappings Additional mappings of original
 *            {@link EntityDefinition}s to the resolved ones that should be
 *            considered in the migration
 * @param log the log
 * @return the migrated cell
 */
public MutableCell migrate(Map<EntityDefinition, EntityDefinition> additionalMappings, SimpleLog log) {
    final Map<EntityDefinition, EntityDefinition> joinedMappings = new HashMap<>(entityMappings);
    joinedMappings.putAll(additionalMappings);
    AlignmentMigration migration = new AlignmentMigrationNameLookupSupport() {

        @Override
        public Optional<EntityDefinition> entityReplacement(EntityDefinition entity, SimpleLog log) {
            return Optional.ofNullable(joinedMappings.get(entity));
        }

        @Override
        public Optional<EntityDefinition> entityReplacement(String name) {
            for (EntityDefinition original : joinedMappings.keySet()) {
                QName entityName = original.getDefinition().getName();
                if (entityName != null && entityName.getLocalPart().equals(name)) {
                    return Optional.of(original);
                }
            }
            return Optional.empty();
        }
    };
    MigrationOptions options = new MigrationOptions() {

        @Override
        public boolean updateTarget() {
            return true;
        }

        @Override
        public boolean updateSource() {
            return true;
        }

        @Override
        public boolean transferBase() {
            return false;
        }
    };
    return migrator.updateCell(this, migration, options, log);
}
Also used : SimpleLog(eu.esdihumboldt.hale.common.core.report.SimpleLog) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) AlignmentMigration(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration) AlignmentMigrationNameLookupSupport(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigrationNameLookupSupport) MigrationOptions(eu.esdihumboldt.hale.common.align.migrate.MigrationOptions)

Example 38 with EntityDefinition

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

the class MergeMigrator method convertProperty.

private ParameterValue convertProperty(ParameterValue value, AlignmentMigration migration, TypeDefinition sourceType, SimpleLog log) {
    EntityDefinition entity = null;
    try {
        entity = MergeUtil.resolvePropertyPath(value, sourceType);
    } catch (IllegalStateException e) {
        // replacement for the parameter value
        if (migration instanceof AlignmentMigrationNameLookupSupport) {
            AlignmentMigrationNameLookupSupport nameLookup = (AlignmentMigrationNameLookupSupport) migration;
            entity = nameLookup.entityReplacement(value.getStringRepresentation()).orElse(null);
        }
    }
    if (entity == null) {
        return value;
    }
    Optional<EntityDefinition> replacement = migration.entityReplacement(entity, log);
    if (replacement.isPresent()) {
        return convertProperty(value, replacement.get(), log);
    } else {
        // use original path
        return value;
    }
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) AlignmentMigrationNameLookupSupport(eu.esdihumboldt.hale.common.align.migrate.AlignmentMigrationNameLookupSupport)

Example 39 with EntityDefinition

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

the class DefaultAlignment method internalAddToMaps.

/**
 * Add a cell to the internal indexes, based on the given associated
 * entities.
 *
 * @param entities the cell entities (usually either source or target)
 * @param cell the cell to add
 */
private void internalAddToMaps(ListMultimap<String, ? extends Entity> entities, Cell cell) {
    if (entities == null) {
        return;
    }
    for (Entity entity : entities.values()) {
        EntityDefinition entityDef = entity.getDefinition();
        cellsPerEntity.put(entityDef, cell);
        switch(entityDef.getSchemaSpace()) {
            case TARGET:
                cellsPerTargetType.put(entityDef.getType(), cell);
                break;
            case SOURCE:
                cellsPerSourceType.put(entityDef.getType(), cell);
                break;
            default:
                throw new IllegalStateException("Entity definition with illegal schema space encountered");
        }
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition)

Example 40 with EntityDefinition

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

the class DefaultAlignment method internalRemoveFromMaps.

/**
 * Removes a cell from the internal indexes, based on the given associated
 * entities.
 *
 * @param entities the cell entities (usually either source or target)
 * @param cell the cell to remove
 */
private void internalRemoveFromMaps(ListMultimap<String, ? extends Entity> entities, Cell cell) {
    if (entities == null) {
        return;
    }
    for (Entity entity : entities.values()) {
        EntityDefinition entityDef = entity.getDefinition();
        cellsPerEntity.remove(entityDef, cell);
        switch(entityDef.getSchemaSpace()) {
            case TARGET:
                cellsPerTargetType.remove(entityDef.getType(), cell);
                break;
            case SOURCE:
                cellsPerSourceType.remove(entityDef.getType(), cell);
                break;
            default:
                throw new IllegalStateException("Entity definition with illegal schema space encountered");
        }
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition)

Aggregations

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)99 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)39 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)37 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)23 ArrayList (java.util.ArrayList)22 Entity (eu.esdihumboldt.hale.common.align.model.Entity)21 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)20 Cell (eu.esdihumboldt.hale.common.align.model.Cell)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)10 HashSet (java.util.HashSet)10 QName (javax.xml.namespace.QName)10 HashMap (java.util.HashMap)9 Condition (eu.esdihumboldt.hale.common.align.model.Condition)8 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ISelection (org.eclipse.jface.viewers.ISelection)7 List (java.util.List)6 TreePath (org.eclipse.jface.viewers.TreePath)6 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)5