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