Search in sources :

Example 6 with ChildContext

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

the class EntityDefinitionServiceImpl method getChildren.

/**
 * @see EntityDefinitionService#getChildren(EntityDefinition)
 */
@Override
public Collection<? extends EntityDefinition> getChildren(EntityDefinition entity) {
    List<ChildContext> path = entity.getPropertyPath();
    Collection<? extends ChildDefinition<?>> children;
    if (path == null || path.isEmpty()) {
        // entity is a type, children are the type children
        children = entity.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(entity.getType(), createPath(entity.getPropertyPath(), context), entity.getSchemaSpace(), entity.getFilter());
        result.add(defaultEntity);
        // look up additional instance contexts and add them
        synchronized (namedContexts) {
            for (Integer contextName : namedContexts.get(defaultEntity)) {
                ChildContext namedContext = new ChildContext(contextName, null, null, child);
                EntityDefinition namedChild = createEntity(entity.getType(), createPath(entity.getPropertyPath(), namedContext), entity.getSchemaSpace(), entity.getFilter());
                result.add(namedChild);
            }
        }
        synchronized (indexContexts) {
            for (Integer index : indexContexts.get(defaultEntity)) {
                ChildContext indexContext = new ChildContext(null, index, null, child);
                EntityDefinition indexChild = createEntity(entity.getType(), createPath(entity.getPropertyPath(), indexContext), entity.getSchemaSpace(), entity.getFilter());
                result.add(indexChild);
            }
        }
        synchronized (conditionContexts) {
            for (Condition condition : conditionContexts.get(defaultEntity)) {
                ChildContext conditionContext = new ChildContext(null, null, condition, child);
                EntityDefinition conditionChild = createEntity(entity.getType(), createPath(entity.getPropertyPath(), conditionContext), entity.getSchemaSpace(), entity.getFilter());
                result.add(conditionChild);
            }
        }
    }
    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) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 7 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext 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 8 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext 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 9 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext 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 10 with ChildContext

use of eu.esdihumboldt.hale.common.align.model.ChildContext 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

ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)63 ArrayList (java.util.ArrayList)32 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)29 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)24 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)12 QName (javax.xml.namespace.QName)11 Property (eu.esdihumboldt.hale.common.align.model.Property)7 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 List (java.util.List)7 Condition (eu.esdihumboldt.hale.common.align.model.Condition)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)6 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)5 ChildDefinition (eu.esdihumboldt.hale.common.schema.model.ChildDefinition)5 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)4 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)3 Type (eu.esdihumboldt.hale.common.align.model.Type)3 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3