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);
}
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;
}
}
Aggregations