use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class UserMigration method entityReplacement.
@Override
public Optional<EntityDefinition> entityReplacement(EntityDefinition entity, SimpleLog log) {
// use functionality from entity resolver
if (entity instanceof TypeEntityDefinition) {
EntityDefinition candidate = entity;
Type type = UserFallbackEntityResolver.resolveType((TypeEntityDefinition) entity, candidate, schemaSpace);
return Optional.ofNullable(type).map(e -> e.getDefinition());
} else if (entity instanceof PropertyEntityDefinition) {
EntityDefinition candidate = entity;
candidate = EntityCandidates.find((PropertyEntityDefinition) entity);
Property property = UserFallbackEntityResolver.resolveProperty((PropertyEntityDefinition) entity, candidate, schemaSpace);
return Optional.ofNullable(property).map(e -> e.getDefinition());
} else {
log.error("Unrecognised entity type: " + entity.getClass());
return Optional.empty();
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class EntityTypeIndexHierarchy method getChildren.
/**
* @see ITreeContentProvider#getChildren(Object)
*/
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof EntityDefinition) {
EntityDefinition parent = (EntityDefinition) parentElement;
List<EntityDefinition> children = new ArrayList<EntityDefinition>();
// add valid sub types and alternative type entities
if (parent.getPropertyPath().isEmpty() && parent.getFilter() == null) {
// add valid sub types w/o filter
for (TypeDefinition subtype : parent.getType().getSubTypes()) {
if (validTypes.contains(subtype)) {
children.add(new TypeEntityDefinition(subtype, parent.getSchemaSpace(), null));
}
}
// add type contexts
for (TypeEntityDefinition typeEntity : entityDefinitionService.getTypeEntities(parent.getType(), parent.getSchemaSpace())) {
if (typeEntity.getFilter() != null) {
// only use type entities with filter defined
children.add(typeEntity);
}
}
}
if (!onlyTypes) {
// add regular children
children.addAll(entityDefinitionService.getChildren(parent));
}
return children.toArray();
} else {
throw new IllegalArgumentException("Given element not supported in schema tree structure.");
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class EntityTypeIndexHierarchy method getElements.
/**
* @see ITreeContentProvider#getElements(Object)
*/
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof TypeIndex) {
validTypes = new HashSet<TypeDefinition>();
List<TypeEntityDefinition> roots = new ArrayList<TypeEntityDefinition>();
Queue<TypeDefinition> types = new LinkedList<TypeDefinition>();
if (onlyMappingRelevant)
types.addAll(((TypeIndex) inputElement).getMappingRelevantTypes());
else {
for (TypeDefinition type : ((TypeIndex) inputElement).getTypes()) if (type.getConstraint(MappableFlag.class).isEnabled())
types.add(type);
}
// collect types and super types in valid types set
while (!types.isEmpty()) {
TypeDefinition type = types.poll();
if (!validTypes.contains(type)) {
validTypes.add(type);
TypeDefinition superType = type.getSuperType();
if (superType != null && !validTypes.contains(superType)) {
types.add(superType);
}
if (superType == null) {
// add default type as root
roots.add(new TypeEntityDefinition(type, schemaSpace, null));
}
}
}
// }
return roots.toArray();
} else {
throw new IllegalArgumentException("Content provider only applicable for type indexes.");
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class PopulationServiceImpl method addToPopulation.
/**
* @see PopulationService#addToPopulation(Instance, DataSet)
*/
@Override
public void addToPopulation(Instance instance, DataSet dataSet) {
SchemaSpaceID schemaSpace;
if (dataSet != null) {
switch(dataSet) {
case TRANSFORMED:
schemaSpace = SchemaSpaceID.TARGET;
break;
case SOURCE:
default:
schemaSpace = SchemaSpaceID.SOURCE;
}
} else {
throw new IllegalArgumentException("Invalid data set specified.");
}
// count for each Type definitions of instance type
Collection<? extends TypeEntityDefinition> typeDefinitions = entityDefinitionService.getTypeEntities(instance.getDefinition(), schemaSpace);
for (TypeEntityDefinition def : typeDefinitions) {
if (def.getFilter() == null || def.getFilter().match(instance)) {
increase(def, 1);
populationCount.addToPopulation(instance, def);
}
}
}
use of eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition in project hale by halestudio.
the class PropertyEntitiesPage method createHeader.
/**
* @see EntitiesPage#createHeader(Composite)
*/
@Override
protected Control createHeader(Composite parent) {
Group typeSelectionGroup = new Group(parent, SWT.NONE);
typeSelectionGroup.setText("Type");
typeSelectionGroup.setLayout(new GridLayout());
sourceTargetSelector = new SourceTargetTypeSelector(typeSelectionGroup);
sourceTargetSelector.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// set initial selection
sourceTargetSelector.setSelection(getInitialTypeSelection(SchemaSpaceID.SOURCE), SchemaSpaceID.SOURCE);
sourceTargetSelector.setSelection(getInitialTypeSelection(SchemaSpaceID.TARGET), SchemaSpaceID.TARGET);
// add selection listener
sourceTargetSelector.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
TypeEntityDefinition selectedType = sourceTargetSelector.getSelection(SchemaSpaceID.SOURCE);
for (PropertyField field : getFunctionFields()) {
if (field.getSchemaSpace() == SchemaSpaceID.SOURCE) {
field.setParentType(selectedType);
}
}
}
}, SchemaSpaceID.SOURCE);
sourceTargetSelector.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
TypeEntityDefinition selectedType = sourceTargetSelector.getSelection(SchemaSpaceID.TARGET);
for (PropertyField field : getFunctionFields()) if (field.getSchemaSpace() == SchemaSpaceID.TARGET)
field.setParentType(selectedType);
}
}, SchemaSpaceID.TARGET);
return typeSelectionGroup;
}
Aggregations