Search in sources :

Example 51 with PropertyEntityDefinition

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;
}
Also used : ArrayList(java.util.ArrayList) TypeTransformationFactory(eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) List(java.util.List) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 52 with PropertyEntityDefinition

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;
}
Also used : HashSet(java.util.HashSet) List(java.util.List) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Multiset(com.google.common.collect.Multiset) Set(java.util.Set) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) QName(javax.xml.namespace.QName) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList)

Example 53 with PropertyEntityDefinition

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;
}
Also used : ArrayList(java.util.ArrayList) ChildDefinition(eu.esdihumboldt.hale.common.schema.model.ChildDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreePath(org.eclipse.jface.viewers.TreePath) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 54 with PropertyEntityDefinition

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;
}
Also used : PropertyCondition(eu.esdihumboldt.hale.common.align.model.condition.PropertyCondition) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) Viewer(org.eclipse.jface.viewers.Viewer) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 55 with PropertyEntityDefinition

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;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Aggregations

PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)55 ArrayList (java.util.ArrayList)26 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)19 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)19 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)16 List (java.util.List)15 Entity (eu.esdihumboldt.hale.common.align.model.Entity)12 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)12 QName (javax.xml.namespace.QName)11 Cell (eu.esdihumboldt.hale.common.align.model.Cell)10 HashSet (java.util.HashSet)10 Property (eu.esdihumboldt.hale.common.align.model.Property)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)7 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)6 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 Collectors (java.util.stream.Collectors)6 Type (eu.esdihumboldt.hale.common.align.model.Type)5 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)5