use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class InstanceIndexServiceImpl method addPropertyMappings.
@Override
public boolean addPropertyMappings(Iterable<? extends Cell> cells, ServiceProvider serviceProvider) {
if (serviceProvider == null) {
throw new NullPointerException("Service provider must not be null");
}
boolean result = false;
for (Cell cell : cells) {
List<TypeTransformationFactory> functions = TransformationFunctionUtil.getTypeTransformations(cell.getTransformationIdentifier(), serviceProvider);
if (functions.isEmpty()) {
// Not a type transformation cell
continue;
}
TypeTransformation<?> transformation;
try {
transformation = functions.get(0).createExtensionObject();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
List<List<PropertyEntityDefinition>> indexedProperties = new ArrayList<>();
if (transformation instanceof InstanceIndexContribution) {
InstanceIndexContribution contribution = (InstanceIndexContribution) transformation;
indexedProperties.addAll(contribution.getIndexContribution(cell));
}
if (!indexedProperties.isEmpty()) {
result = true;
for (List<PropertyEntityDefinition> properties : indexedProperties) {
this.addPropertyMapping(properties);
}
}
}
return result;
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class PropertyEntityDefinitionMapping method map.
/**
* @see eu.esdihumboldt.hale.common.instance.index.IndexMapping#map(java.lang.Object)
*/
@Override
public List<IndexedPropertyValue> map(Instance instance) {
List<IndexedPropertyValue> result = new ArrayList<>();
for (PropertyEntityDefinition definition : definitions) {
List<QName> propertyPath = definition.getPropertyPath().stream().map(cctx -> cctx.getChild().getName()).collect(Collectors.toList());
Multiset<?> values = AlignmentUtil.getValues(instance, definition, false);
result.add(new IndexedPropertyValue(propertyPath, values.elementSet().stream().map(v -> processValue(v, definition)).collect(Collectors.toList())));
}
return result;
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class PropertyEntityDialog method getObjectFromSelection.
/**
* @see EntityDialog#getObjectFromSelection(ISelection)
*/
@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
return (EntityDefinition) element;
}
}
if (!selection.isEmpty() && selection instanceof ITreeSelection) {
// create property definition w/ default contexts
TreePath path = ((ITreeSelection) selection).getPaths()[0];
// get parent type
TypeDefinition type = ((PropertyDefinition) path.getFirstSegment()).getParentType();
// determine definition path
List<ChildContext> defPath = new ArrayList<ChildContext>();
for (int i = 0; i < path.getSegmentCount(); i++) {
defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
}
// TODO check if property entity definition is applicable?
return new PropertyEntityDefinition(type, defPath, ssid, parentType.getFilter());
}
return null;
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class PropertyEntitySelector method createFilters.
private static ViewerFilter[] createFilters(PropertyParameterDefinition field) {
// if no condition is present add a filter that allows all properties
ViewerFilter propertyFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return element instanceof PropertyEntityDefinition;
}
};
if (field == null) {
return new ViewerFilter[] { propertyFilter };
}
List<PropertyCondition> conditions = field.getConditions();
if (conditions == null || conditions.isEmpty())
return new ViewerFilter[] { propertyFilter };
ViewerFilter[] filters = new ViewerFilter[conditions.size()];
int i = 0;
for (final PropertyCondition condition : conditions) {
filters[i] = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof PropertyEntityDefinition) {
Property property = new DefaultProperty((PropertyEntityDefinition) element);
return condition.accept(property);
} else
return false;
}
};
}
return filters;
}
use of eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition in project hale by halestudio.
the class EntityDefinitionServiceImpl method replace.
/**
* Creates a new ListMultimap with all occurrences of originalDef replaced
* by newDef. newDef must be a sibling of originalDef.
*
* @param entities the original list
* @param originalDef the entity definition to be replaced
* @param newDef the entity definition to use
* @return a new list
*/
private ListMultimap<String, ? extends Entity> replace(ListMultimap<String, ? extends Entity> entities, EntityDefinition originalDef, EntityDefinition newDef) {
ListMultimap<String, Entity> newList = ArrayListMultimap.create();
for (Entry<String, ? extends Entity> entry : entities.entries()) {
EntityDefinition entryDef = entry.getValue().getDefinition();
Entity newEntry;
if (AlignmentUtil.isParent(originalDef, entryDef)) {
if (entry.getValue() instanceof Type) {
// entry is a Type, so the changed Definition must be a
// Type, too.
newEntry = new DefaultType((TypeEntityDefinition) newDef);
} else if (entry.getValue() instanceof Property) {
// entry is a Property, check changed Definition.
if (originalDef.getPropertyPath().isEmpty()) {
// Type changed.
newEntry = new DefaultProperty(new PropertyEntityDefinition(newDef.getType(), entryDef.getPropertyPath(), entryDef.getSchemaSpace(), newDef.getFilter()));
} else {
// Some element of the property path changed.
List<ChildContext> newPath = new ArrayList<ChildContext>(entryDef.getPropertyPath());
int lastIndexOfChangedDef = newDef.getPropertyPath().size() - 1;
newPath.set(lastIndexOfChangedDef, newDef.getPropertyPath().get(lastIndexOfChangedDef));
newEntry = new DefaultProperty(new PropertyEntityDefinition(entryDef.getType(), newPath, entryDef.getSchemaSpace(), entryDef.getFilter()));
}
} else {
throw new IllegalStateException("Entity is neither a Type nor a Property.");
}
} else {
newEntry = entry.getValue();
}
newList.put(entry.getKey(), newEntry);
}
return newList;
}
Aggregations