Search in sources :

Example 1 with JoinCondition

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition in project hale by halestudio.

the class JoinParameterPage method getConfiguration.

/**
 * @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#getConfiguration()
 */
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
    ListMultimap<String, ParameterValue> result = ArrayListMultimap.create(1, 1);
    Set<JoinCondition> conditions = new HashSet<>();
    for (ConditionPage page : pages) {
        conditions.addAll(page.conditions);
    }
    JoinParameter param = new JoinParameter(types, conditions);
    result.put(PARAMETER_JOIN, new ParameterValue(new ComplexValue(param)));
    return result;
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) HashSet(java.util.HashSet)

Example 2 with JoinCondition

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition in project hale by halestudio.

the class JoinParameterPage method createJoinParameter.

/**
 * Creates a join parameter for the types up to <code>upToIndex</code>.
 *
 * @param upToIndex the type index up to which the parameter should be
 *            created for
 * @return the current join parameter up to the specified index
 */
private JoinParameter createJoinParameter(int upToIndex) {
    Set<JoinCondition> conditions = new HashSet<>();
    for (int i = 0; i < upToIndex; i++) conditions.addAll(pages.get(i).conditions);
    JoinParameter param = new JoinParameter(types.subList(0, upToIndex + 1), conditions);
    return param;
}
Also used : JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) HashSet(java.util.HashSet)

Example 3 with JoinCondition

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition in project hale by halestudio.

the class JoinParameterPage method onShowPage.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    Cell cell = getWizard().getUnfinishedCell();
    List<? extends Entity> sourceEntities = cell.getSource().get(JOIN_TYPES);
    List<TypeEntityDefinition> types = new ArrayList<TypeEntityDefinition>();
    Iterator<? extends Entity> iter = sourceEntities.iterator();
    while (iter.hasNext()) {
        types.add(AlignmentUtil.getTypeEntity(iter.next().getDefinition()));
    }
    if (sameTypes(this.types, types)) {
        return;
    }
    if (containsDuplicateType(types)) {
        setPageComplete(false);
        setErrorMessage("The selected source types contain duplicates.");
        this.types.clear();
        table.setInput(null);
        return;
    } else {
        setErrorMessage(null);
    }
    JoinParameter initialValue = null;
    if (firstShow && !getInitialValues().get(PARAMETER_JOIN).isEmpty()) {
        initialValue = getInitialValues().get(PARAMETER_JOIN).get(0).as(JoinParameter.class);
        if (initialValue != null) {
            // use ordering of the initial value (needs to be modifiable)
            List<TypeEntityDefinition> tmp = new ArrayList<>(initialValue.getTypes());
            // append any type that were added, or remove types that were
            // removed
            tmp.retainAll(types);
            List<TypeEntityDefinition> more = new ArrayList<>(types);
            more.removeAll(tmp);
            tmp.addAll(more);
            types = tmp;
            // apply potentially changed type list
            initialValue = new JoinParameter(types, initialValue.getConditions());
            if (initialValue.validate(true) != null) {
                // try to fix config
                // not recoverable
                initialValue = null;
            }
        }
    }
    this.types = types;
    for (ConditionPage page : pages) {
        page.dispose();
    }
    pages.clear();
    if (table != null) {
        table.setInput(types);
    }
    for (int i = 1; i < types.size(); i++) {
        ConditionPage conditionPage = new ConditionPage(i);
        conditionPage.setWizard(getWizard());
        pages.add(conditionPage);
    }
    if (initialValue != null) {
        // add initial conditions
        for (JoinCondition condition : initialValue.getConditions()) {
            TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(condition.joinProperty);
            int typeIndex = types.indexOf(joinType);
            int pageIndex = typeIndex - 1;
            pages.get(pageIndex).conditions.add(condition);
            pages.get(pageIndex).updateCompletionStatus();
        }
    }
    // order is always valid, will trigger updateButtons
    setPageComplete(true);
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ArrayList(java.util.ArrayList) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)

Example 4 with JoinCondition

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition in project hale by halestudio.

the class IndexJoinIterator method join.

/**
 * Joins all direct children of the given type to currentInstances.
 */
@SuppressWarnings("javadoc")
private void join(FamilyInstance[] currentInstances, int currentType) {
    // Join all types that are direct children of the last type.
    for (int i = currentType + 1; i < joinDefinition.directParent.length; i++) {
        if (joinDefinition.directParent[i] == currentType) {
            // Get join condition for the direct child type.
            Multimap<Integer, JoinCondition> joinConditions = joinDefinition.joinTable.get(i);
            // Collect intersection of conditions. null marks beginning
            // in contrast to an empty set.
            Set<ResolvableInstanceReference> possibleInstances = null;
            // ParentType -> JoinConditions
            for (Map.Entry<Integer, JoinCondition> joinCondition : joinConditions.entries()) {
                PropertyEntityDefinition baseProp = joinCondition.getValue().baseProperty;
                QName baseTypeName = baseProp.getType().getName();
                List<QName> basePropertyPath = baseProp.getPropertyPath().stream().map(pp -> pp.getChild().getName()).collect(Collectors.toList());
                PropertyEntityDefinition joinProp = joinCondition.getValue().joinProperty;
                QName joinTypeName = joinProp.getType().getName();
                List<QName> joinPropertyPath = joinProp.getPropertyPath().stream().map(pp -> pp.getChild().getName()).collect(Collectors.toList());
                List<IndexedPropertyValue> currentValues = index.getInstancePropertyValues(baseTypeName, basePropertyPath, currentInstances[joinCondition.getKey()].getId());
                if (currentValues == null || currentValues.isEmpty()) {
                    possibleInstances = Collections.emptySet();
                    break;
                }
                HashSet<ResolvableInstanceReference> matches = new HashSet<ResolvableInstanceReference>();
                for (IndexedPropertyValue currentValue : currentValues) {
                    if (currentValue.getValues() == null || currentValue.getValues().isEmpty()) {
                        continue;
                    }
                    // Find instances that have the current property value
                    Collection<ResolvableInstanceReference> instancesWithValues = index.getInstancesByValue(joinTypeName, joinPropertyPath, currentValue.getValues());
                    matches.addAll(instancesWithValues);
                }
                if (possibleInstances == null) {
                    possibleInstances = matches;
                } else {
                    // Remove candidates that don't have the current
                    // property value
                    Iterator<ResolvableInstanceReference> it = possibleInstances.iterator();
                    while (it.hasNext()) {
                        ResolvableInstanceReference cand = it.next();
                        if (!matches.contains(cand)) {
                            it.remove();
                        }
                    }
                }
                if (possibleInstances.isEmpty()) {
                    break;
                }
            }
            if (possibleInstances != null && !possibleInstances.isEmpty()) {
                FamilyInstance parent = currentInstances[currentType];
                for (ResolvableInstanceReference ref : possibleInstances) {
                    FamilyInstance child;
                    child = new FamilyInstanceImpl(ref.resolve());
                    parent.addChild(child);
                    currentInstances[i] = child;
                    join(currentInstances, i);
                }
                currentInstances[i] = null;
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference) Collection(java.util.Collection) JoinDefinition(eu.esdihumboldt.cst.functions.core.join.JoinUtil.JoinDefinition) Set(java.util.Set) InstanceIndexService(eu.esdihumboldt.hale.common.instance.index.InstanceIndexService) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) HashSet(java.util.HashSet) FamilyInstanceImpl(eu.esdihumboldt.hale.common.align.transformation.function.impl.FamilyInstanceImpl) GenericResourceIteratorAdapter(eu.esdihumboldt.hale.common.instance.model.impl.GenericResourceIteratorAdapter) List(java.util.List) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) Map(java.util.Map) QName(javax.xml.namespace.QName) IndexedPropertyValue(eu.esdihumboldt.hale.common.instance.index.IndexedPropertyValue) Collections(java.util.Collections) QName(javax.xml.namespace.QName) IndexedPropertyValue(eu.esdihumboldt.hale.common.instance.index.IndexedPropertyValue) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) FamilyInstanceImpl(eu.esdihumboldt.hale.common.align.transformation.function.impl.FamilyInstanceImpl) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference) Map(java.util.Map) HashSet(java.util.HashSet)

Example 5 with JoinCondition

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition in project hale by halestudio.

the class JoinIterator method join.

// Joins all direct children of the given type to currentInstances.
private void join(FamilyInstance[] currentInstances, int currentType) {
    // Join all types that are direct children of the last type.
    for (int i = currentType + 1; i < parent.length; i++) {
        if (parent[i] == currentType) {
            // Get join condition for the direct child type.
            Multimap<Integer, JoinCondition> joinConditions = joinTable.get(i);
            // Collect intersection of conditions. null marks beginning
            // in contrast to an empty set.
            Set<InstanceReference> possibleInstances = null;
            // ParentType -> JoinConditions
            for (Map.Entry<Integer, JoinCondition> joinCondition : joinConditions.entries()) {
                Collection<Object> currentValues = AlignmentUtil.getValues(currentInstances[joinCondition.getKey()], joinCondition.getValue().baseProperty, true);
                if (currentValues == null) {
                    possibleInstances = Collections.emptySet();
                    break;
                }
                // Allow targets with any of the property values.
                HashSet<InstanceReference> matches = new HashSet<InstanceReference>();
                for (Object currentValue : currentValues) {
                    Object keyValue = currentValue;
                    if (valueProcessor != null) {
                        keyValue = valueProcessor.processValue(currentValue, joinCondition.getValue().baseProperty);
                    }
                    matches.addAll(index.get(joinCondition.getValue().joinProperty).get(keyValue));
                }
                if (possibleInstances == null)
                    possibleInstances = matches;
                else {
                    // Intersect!
                    Iterator<InstanceReference> iter = possibleInstances.iterator();
                    while (iter.hasNext()) {
                        InstanceReference ref = iter.next();
                        if (!matches.contains(ref))
                            iter.remove();
                    }
                }
                // Break if set is empty.
                if (possibleInstances.isEmpty())
                    break;
            }
            if (possibleInstances != null && !possibleInstances.isEmpty()) {
                FamilyInstance parent = currentInstances[currentType];
                for (InstanceReference ref : possibleInstances) {
                    FamilyInstance child;
                    if (ref instanceof ResolvableInstanceReference) {
                        child = new FamilyInstanceImpl(((ResolvableInstanceReference) ref).resolve());
                    } else {
                        child = new FamilyInstanceImpl(instances.getInstance(ref));
                    }
                    parent.addChild(child);
                    currentInstances[i] = child;
                    join(currentInstances, i);
                }
                currentInstances[i] = null;
            }
        }
    }
}
Also used : JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) FamilyInstanceImpl(eu.esdihumboldt.hale.common.align.transformation.function.impl.FamilyInstanceImpl) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) Map(java.util.Map) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference) HashSet(java.util.HashSet)

Aggregations

JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)15 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)11 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Cell (eu.esdihumboldt.hale.common.align.model.Cell)5 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)5 List (java.util.List)5 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)4 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 ListMultimap (com.google.common.collect.ListMultimap)2 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)2 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)2 JoinFunction (eu.esdihumboldt.hale.common.align.model.functions.JoinFunction)2 FamilyInstanceImpl (eu.esdihumboldt.hale.common.align.transformation.function.impl.FamilyInstanceImpl)2 Value (eu.esdihumboldt.hale.common.core.io.Value)2