Search in sources :

Example 16 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class EntityDefinitionServiceImpl method createWithCondition.

/**
 * Creates a new entity definition.
 *
 * @param sibling the entity definition to use as base
 * @param condition the new condition, not <code>null</code>
 * @return a new entity definition
 */
private EntityDefinition createWithCondition(EntityDefinition sibling, Condition condition) {
    EntityDefinition result;
    List<ChildContext> path = sibling.getPropertyPath();
    if (path.isEmpty()) {
        // create type entity definition with filter
        result = createEntity(sibling.getType(), path, sibling.getSchemaSpace(), condition.getFilter());
    } else {
        List<ChildContext> newPath = new ArrayList<ChildContext>(path);
        ChildContext last = newPath.remove(path.size() - 1);
        // new condition context, w/o name or index context
        newPath.add(new ChildContext(null, null, condition, last.getChild()));
        result = createEntity(sibling.getType(), newPath, sibling.getSchemaSpace(), sibling.getFilter());
    }
    return result;
}
Also used : 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) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 17 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class EntityDefinitionServiceImpl method addNamedContext.

/**
 * @see EntityDefinitionService#addNamedContext(EntityDefinition)
 */
@Override
public EntityDefinition addNamedContext(EntityDefinition sibling) {
    List<ChildContext> path = sibling.getPropertyPath();
    if (sibling.getSchemaSpace() == SchemaSpaceID.SOURCE || path.isEmpty()) {
        // XXX throw exception instead?
        return null;
    }
    // XXX any checks? see InstanceContextTester
    EntityDefinition def = AlignmentUtil.getDefaultEntity(sibling);
    Integer newName;
    synchronized (namedContexts) {
        // get registered context names
        Collection<Integer> names = namedContexts.get(def);
        if (names == null || names.isEmpty()) {
            newName = Integer.valueOf(0);
        } else {
            // get the maximum value available as a name
            SortedSet<Integer> sortedNames = new TreeSet<Integer>(names);
            int max = sortedNames.last();
            // and use its value increased by one
            newName = Integer.valueOf(max + 1);
        }
        namedContexts.put(def, newName);
    }
    List<ChildContext> newPath = new ArrayList<ChildContext>(path);
    ChildDefinition<?> lastChild = newPath.get(newPath.size() - 1).getChild();
    newPath.remove(path.size() - 1);
    // new named context, w/o index or condition context
    newPath.add(new ChildContext(newName, null, null, lastChild));
    EntityDefinition result = createEntity(def.getType(), newPath, sibling.getSchemaSpace(), sibling.getFilter());
    notifyContextAdded(result);
    return result;
}
Also used : 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) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 18 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class EntityDefinitionServiceImpl method addIndexContext.

/**
 * @see EntityDefinitionService#addIndexContext(EntityDefinition, Integer)
 */
@Override
public EntityDefinition addIndexContext(EntityDefinition sibling, Integer index) {
    List<ChildContext> path = sibling.getPropertyPath();
    if (sibling.getSchemaSpace() == SchemaSpaceID.TARGET || path.isEmpty()) {
        // XXX throw exception instead?
        return null;
    }
    // XXX any checks? see InstanceContextTester
    EntityDefinition def = AlignmentUtil.getDefaultEntity(sibling);
    boolean doAdd = true;
    synchronized (indexContexts) {
        // get registered context indexes
        Set<Integer> existingIndexes = indexContexts.get(def);
        if (index == null) {
            // determine index automatically
            if (existingIndexes == null || existingIndexes.isEmpty()) {
                index = Integer.valueOf(0);
            } else {
                // get the sorted existing indexes
                SortedSet<Integer> sortedIndexes = new TreeSet<Integer>(existingIndexes);
                // find the smallest value not present
                int expected = 0;
                Iterator<Integer> it = sortedIndexes.iterator();
                while (index == null && it.hasNext()) {
                    int existingIndex = it.next();
                    if (existingIndex != expected) {
                        index = expected;
                    }
                    expected++;
                }
                if (index == null) {
                    index = expected;
                }
            }
        } else if (existingIndexes.contains(index)) {
            // this index context is not new, but already there
            doAdd = false;
        }
        if (doAdd) {
            indexContexts.put(def, index);
        }
    }
    List<ChildContext> newPath = new ArrayList<ChildContext>(path);
    ChildDefinition<?> lastChild = newPath.get(newPath.size() - 1).getChild();
    newPath.remove(path.size() - 1);
    // new index context, w/o name or condition context
    newPath.add(new ChildContext(null, index, null, lastChild));
    EntityDefinition result = createEntity(def.getType(), newPath, sibling.getSchemaSpace(), sibling.getFilter());
    if (doAdd) {
        notifyContextAdded(result);
    }
    return result;
}
Also used : 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) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 19 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class EntityDefinitionServiceImpl method addContexts.

/**
 * Add the missing contexts for the given entity definition.
 *
 * @param entityDef the entity definition to add contexts for
 * @param addedContexts a collection where newly created contexts must be
 *            added
 */
private void addContexts(EntityDefinition entityDef, Collection<EntityDefinition> addedContexts) {
    // collect the entity definition and all of its parents
    LinkedList<EntityDefinition> hierarchy = new LinkedList<EntityDefinition>();
    EntityDefinition parent = entityDef;
    while (parent != null) {
        hierarchy.addFirst(parent);
        parent = getParent(parent);
    }
    // topmost parent
    for (EntityDefinition candidate : hierarchy) {
        Integer contextName = AlignmentUtil.getContextName(candidate);
        Integer contextIndex = AlignmentUtil.getContextIndex(candidate);
        Condition contextCondition = AlignmentUtil.getContextCondition(candidate);
        if (contextName != null || contextIndex != null || contextCondition != null) {
            if (contextName != null && contextIndex == null && contextCondition == null) {
                // add named context
                boolean added = namedContexts.put(AlignmentUtil.getDefaultEntity(candidate), contextName);
                if (added) {
                    addedContexts.add(candidate);
                }
            } else if (contextIndex != null && contextName == null && contextCondition == null) {
                // add index context
                boolean added = indexContexts.put(AlignmentUtil.getDefaultEntity(candidate), contextIndex);
                if (added) {
                    addedContexts.add(candidate);
                }
            } else if (contextCondition != null && contextName == null && contextIndex == null) {
                // add condition context
                boolean added = conditionContexts.put(AlignmentUtil.getDefaultEntity(candidate), contextCondition);
                if (added) {
                    addedContexts.add(candidate);
                }
            } else {
                throw new IllegalArgumentException("Illegal combination of instance contexts");
            }
        }
    }
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) 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) LinkedList(java.util.LinkedList)

Example 20 with EntityDefinition

use of eu.esdihumboldt.hale.common.align.model.EntityDefinition in project hale by halestudio.

the class EntityDefinitionServiceImpl method addConditionContext.

/**
 * @see EntityDefinitionService#addConditionContext(EntityDefinition,
 *      Filter)
 */
@Override
public EntityDefinition addConditionContext(EntityDefinition sibling, Filter filter) {
    if (filter == null) {
        throw new NullPointerException("Filter must not be null");
    }
    List<ChildContext> path = sibling.getPropertyPath();
    if (sibling.getSchemaSpace() == SchemaSpaceID.TARGET && path.isEmpty()) {
        // XXX throw exception instead?
        return null;
    }
    Condition condition = new Condition(filter);
    EntityDefinition def = AlignmentUtil.getDefaultEntity(sibling);
    boolean doAdd = true;
    synchronized (conditionContexts) {
        // get registered context indexes
        Set<Condition> existingConditions = conditionContexts.get(def);
        if (existingConditions.contains(condition)) {
            // this condition context is not new, but already there
            doAdd = false;
        }
        if (doAdd) {
            conditionContexts.put(def, condition);
        }
    }
    EntityDefinition result = createWithCondition(sibling, condition);
    if (doAdd) {
        notifyContextAdded(result);
    }
    return result;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) 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) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Aggregations

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)99 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)39 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)37 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)23 ArrayList (java.util.ArrayList)22 Entity (eu.esdihumboldt.hale.common.align.model.Entity)21 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)20 Cell (eu.esdihumboldt.hale.common.align.model.Cell)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)10 HashSet (java.util.HashSet)10 QName (javax.xml.namespace.QName)10 HashMap (java.util.HashMap)9 Condition (eu.esdihumboldt.hale.common.align.model.Condition)8 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ISelection (org.eclipse.jface.viewers.ISelection)7 List (java.util.List)6 TreePath (org.eclipse.jface.viewers.TreePath)6 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)5