Search in sources :

Example 11 with TypeEntityDefinition

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

the class MarkTypeUnmappableHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
        SchemaService schemaService = PlatformUI.getWorkbench().getService(SchemaService.class);
        Iterator<?> it = ((IStructuredSelection) selection).iterator();
        List<TypeDefinition> sourceTypes = new ArrayList<>();
        List<TypeDefinition> targetTypes = new ArrayList<>();
        while (it.hasNext()) {
            Object selected = it.next();
            TypeDefinition type = null;
            if (selected instanceof TypeEntityDefinition) {
                type = ((TypeEntityDefinition) selected).getDefinition();
            } else if (selected instanceof TypeDefinition) {
                type = (TypeDefinition) selected;
            }
            if (type != null) {
                if (schemaService.getSchemas(SchemaSpaceID.SOURCE).getMappingRelevantTypes().contains(type)) {
                    sourceTypes.add(type);
                } else {
                    targetTypes.add(type);
                }
            }
        }
        if (!sourceTypes.isEmpty()) {
            schemaService.toggleMappable(SchemaSpaceID.SOURCE, sourceTypes);
        }
        if (!targetTypes.isEmpty()) {
            schemaService.toggleMappable(SchemaSpaceID.TARGET, targetTypes);
        }
    }
    return null;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 12 with TypeEntityDefinition

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

the class TypeEntityDefinitionTester method test.

/**
 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object,
 *      java.lang.String, java.lang.Object[], java.lang.Object)
 */
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (receiver == null)
        return false;
    if (property.equals(PROPERTY_TYPE_ALLOW_MARK_UNMAPPABLE) && receiver instanceof TypeEntityDefinition) {
        AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
        TypeEntityDefinition entityDef = (TypeEntityDefinition) receiver;
        return as.getAlignment().getCells(entityDef.getType(), entityDef.getSchemaSpace()).isEmpty();
    }
    return false;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService)

Example 13 with TypeEntityDefinition

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

the class PropertyEntitySelector method setParentType.

/**
 * Set the parent type
 *
 * @param parentType the parentType to set
 */
public void setParentType(TypeEntityDefinition parentType) {
    // reset candidates?? refresh viewer?
    if (!Objects.equal(this.parentType, parentType)) {
        this.parentType = parentType;
        // reset selection if necessary
        EntityDefinition selection = getSelectedObject();
        if (selection != null && parentType != null) {
            // parentType, which also got the selected property?
            if (!AlignmentUtil.getTypeEntity(selection).equals(parentType)) {
                setSelection(StructuredSelection.EMPTY);
            }
        }
    }
}
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)

Example 14 with TypeEntityDefinition

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

the class SpatialJoinHandler method partitionInstances.

/**
 * @see eu.esdihumboldt.hale.common.align.transformation.function.InstanceHandler#partitionInstances(eu.esdihumboldt.hale.common.instance.model.InstanceCollection,
 *      java.lang.String,
 *      eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine,
 *      com.google.common.collect.ListMultimap, java.util.Map,
 *      eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog)
 */
@Override
public ResourceIterator<FamilyInstance> partitionInstances(InstanceCollection instances, String transformationIdentifier, TransformationEngine engine, ListMultimap<String, ParameterValue> transformationParameters, Map<String, String> executionParameters, TransformationLog log) throws TransformationException {
    if (transformationParameters == null || !transformationParameters.containsKey(PARAMETER_SPATIAL_JOIN) || transformationParameters.get(PARAMETER_SPATIAL_JOIN).isEmpty()) {
        throw new TransformationException("No join parameter defined");
    }
    if (services == null) {
        throw new IllegalStateException("ServiceProvider must be set before calling partitionInstances");
    }
    SpatialJoinParameter joinParameter = transformationParameters.get(PARAMETER_SPATIAL_JOIN).get(0).as(SpatialJoinParameter.class);
    String validation = joinParameter.validate();
    if (validation != null) {
        throw new TransformationException("Spatial Join parameter invalid: " + validation);
    }
    List<TypeEntityDefinition> types = joinParameter.types;
    // ChildType -> DirectParentType
    int[] directParent = new int[joinParameter.types.size()];
    // ChildType -> (ParentType -> Collection<JoinCondition>)
    Map<Integer, Multimap<Integer, SpatialJoinCondition>> joinTable = new HashMap<>();
    for (SpatialJoinCondition condition : joinParameter.conditions) {
        int baseTypeIndex = types.indexOf(AlignmentUtil.getTypeEntity(condition.baseProperty));
        int joinTypeIndex = types.indexOf(AlignmentUtil.getTypeEntity(condition.joinProperty));
        Multimap<Integer, SpatialJoinCondition> typeTable = joinTable.get(joinTypeIndex);
        if (typeTable == null) {
            typeTable = ArrayListMultimap.create(2, 2);
            joinTable.put(joinTypeIndex, typeTable);
        }
        typeTable.put(baseTypeIndex, condition);
        // update highest type if necessary
        if (directParent[joinTypeIndex] < baseTypeIndex) {
            directParent[joinTypeIndex] = baseTypeIndex;
        }
    }
    // remember instances of first type to start join afterwards
    Collection<InstanceReference> startInstances = new LinkedList<InstanceReference>();
    // iterate once over all instances
    ResourceIterator<Instance> iterator = instances.iterator();
    try {
        while (iterator.hasNext()) {
            Instance next = iterator.next();
            // remember instances of first type
            if (next.getDefinition().equals(types.get(0).getDefinition())) {
                startInstances.add(instances.getReference(next));
            }
        }
    } finally {
        iterator.close();
    }
    return new SpatialJoinIterator(instances, startInstances, directParent, services, joinTable);
}
Also used : TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) HashMap(java.util.HashMap) SpatialJoinCondition(eu.esdihumboldt.cst.functions.geometric.join.SpatialJoinParameter.SpatialJoinCondition) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) LinkedList(java.util.LinkedList) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Multimap(com.google.common.collect.Multimap) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ResolvableInstanceReference(eu.esdihumboldt.hale.common.instance.model.ResolvableInstanceReference) InstanceReference(eu.esdihumboldt.hale.common.instance.model.InstanceReference)

Example 15 with TypeEntityDefinition

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

the class SpatialJoinParameter method validate.

/**
 * Checks whether this join parameter is valid.<br>
 * <br>
 * Valid means, that there has to be at least two types, with each type
 * after the first having at least one join condition on previous types.
 *
 * @return a error description or <code>null</code> if the parameter is
 *         valid.
 */
public String validate() {
    // enough types?
    if (types.size() < 2)
        return "Less than two types.";
    // Check that each type is only in here once.
    Set<TypeDefinition> typeSet = new HashSet<>();
    for (TypeEntityDefinition type : types) {
        if (typeSet.contains(type.getDefinition())) {
            return "Same base type is used twice.";
        } else {
            typeSet.add(type.getDefinition());
        }
    }
    // direct parent map
    int[] parent = new int[types.size()];
    // marker for found conditions for each type
    boolean[] conditionFound = new boolean[types.size()];
    // use sorted conditions (by join type)
    List<SpatialJoinCondition> sortedConditions = new ArrayList<>(conditions);
    Collections.sort(sortedConditions, new Comparator<SpatialJoinCondition>() {

        @Override
        public int compare(SpatialJoinCondition o1, SpatialJoinCondition o2) {
            TypeEntityDefinition o1Type = AlignmentUtil.getTypeEntity(o1.baseProperty);
            TypeEntityDefinition o2Type = AlignmentUtil.getTypeEntity(o2.baseProperty);
            return types.indexOf(o1Type) - types.indexOf(o2Type);
        }
    });
    // check types of each condition
    for (SpatialJoinCondition condition : sortedConditions) {
        TypeEntityDefinition baseType = AlignmentUtil.getTypeEntity(condition.baseProperty);
        TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(condition.joinProperty);
        int baseIndex = types.indexOf(baseType);
        int joinIndex = types.indexOf(joinType);
        // types have to exist, and join has to be after base
        if (baseIndex == -1 || joinIndex == -1) {
            return "Property references no specified type.";
        }
        if (joinIndex <= baseIndex) {
            return "Invalid condition for type order.";
        }
        conditionFound[joinIndex] = true;
        // sorted conditions allow this dependsOn-check
        if (parent[joinIndex] < baseIndex) {
            if (!dependsOn(baseIndex, parent[joinIndex], parent)) {
                return "A join type depends on two types which do not depend on each other.";
            }
            parent[joinIndex] = baseIndex;
        }
    }
    // check whether each type (except the first) has a join condition
    for (int i = 1; i < conditionFound.length; i++) {
        if (!conditionFound[i]) {
            return "A joined type does not have any join conditions.";
        }
    }
    return null;
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ArrayList(java.util.ArrayList) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) HashSet(java.util.HashSet)

Aggregations

TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)64 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)23 ArrayList (java.util.ArrayList)19 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)16 Type (eu.esdihumboldt.hale.common.align.model.Type)16 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)16 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)15 Cell (eu.esdihumboldt.hale.common.align.model.Cell)14 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)11 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)10 QName (javax.xml.namespace.QName)9 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)8 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)8 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)6 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)6 LinkedList (java.util.LinkedList)6 Entity (eu.esdihumboldt.hale.common.align.model.Entity)5 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)5