Search in sources :

Example 1 with AlignmentMigrationNameLookupSupport

use of eu.esdihumboldt.hale.common.align.migrate.AlignmentMigrationNameLookupSupport 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 2 with AlignmentMigrationNameLookupSupport

use of eu.esdihumboldt.hale.common.align.migrate.AlignmentMigrationNameLookupSupport 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)

Aggregations

AlignmentMigrationNameLookupSupport (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigrationNameLookupSupport)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)1 MigrationOptions (eu.esdihumboldt.hale.common.align.migrate.MigrationOptions)1 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1