Search in sources :

Example 1 with TypeEntityDefinition

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

the class AppSchemaMappingTest method getDefaultTypeCell.

private Cell getDefaultTypeCell(TypeDefinition sourceType, TypeDefinition targetType) {
    DefaultCell typeCell = new DefaultCell();
    typeCell.setTransformationIdentifier(RetypeFunction.ID);
    ListMultimap<String, Type> source = ArrayListMultimap.create();
    source.put(null, new DefaultType(new TypeEntityDefinition(sourceType, SchemaSpaceID.SOURCE, null)));
    ListMultimap<String, Type> target = ArrayListMultimap.create();
    target.put(null, new DefaultType(new TypeEntityDefinition(targetType, SchemaSpaceID.TARGET, null)));
    typeCell.setSource(source);
    typeCell.setTarget(target);
    return typeCell;
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) AppSchemaDataAccessType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AppSchemaDataAccessType) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType)

Example 2 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 3 with TypeEntityDefinition

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

the class PopulationServiceImpl method addToPopulation.

/**
 * @see PopulationService#addToPopulation(Instance, DataSet)
 */
@Override
public void addToPopulation(Instance instance, DataSet dataSet) {
    SchemaSpaceID schemaSpace;
    if (dataSet != null) {
        switch(dataSet) {
            case TRANSFORMED:
                schemaSpace = SchemaSpaceID.TARGET;
                break;
            case SOURCE:
            default:
                schemaSpace = SchemaSpaceID.SOURCE;
        }
    } else {
        throw new IllegalArgumentException("Invalid data set specified.");
    }
    // count for each Type definitions of instance type
    Collection<? extends TypeEntityDefinition> typeDefinitions = entityDefinitionService.getTypeEntities(instance.getDefinition(), schemaSpace);
    for (TypeEntityDefinition def : typeDefinitions) {
        if (def.getFilter() == null || def.getFilter().match(instance)) {
            increase(def, 1);
            populationCount.addToPopulation(instance, def);
        }
    }
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID)

Example 4 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 5 with TypeEntityDefinition

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

the class InstanceVisitor method visit.

/**
 * @see AbstractSourceToTargetVisitor#visit(SourceNode)
 */
@Override
public boolean visit(SourceNode source) {
    if (source.getDefinition() instanceof TypeDefinition) {
        if (instance == null)
            return false;
        // source root
        if (source.getDefinition().equals(instance.getDefinition())) {
            // check type filter (if any)
            Filter filter = source.getEntityDefinition().getFilter();
            if (filter != null && !filter.match(instance)) {
                // instance does not match filter, don't descend further
                return false;
            /*
					 * XXX What about merged instances? Will this be OK for
					 * those? A type filter should only apply to the original
					 * instance if it is merged - but most filters should
					 * evaluate the same
					 */
            } else {
                // also sets the node to defined
                source.setValue(instance);
                for (FamilyInstance child : instance.getChildren()) {
                    // Find fitting SourceNodes.
                    Collection<SourceNode> candidateNodes = tree.getRootSourceNodes(child.getDefinition());
                    if (candidateNodes.isEmpty()) {
                        /*
							 * No node found - but this may be because no
							 * property of the type is mapped, but there still
							 * might be child instances (in a Join) that have
							 * types with associated relations. To prevent those
							 * being skipped we add an artificial node
							 * representing the instance.
							 */
                        candidateNodes = new ArrayList<>();
                        EntityDefinition entityDef = new TypeEntityDefinition(child.getDefinition(), SchemaSpaceID.SOURCE, null);
                        candidateNodes.add(new SourceNodeImpl(entityDef, null, false));
                    }
                    for (SourceNode candidateNode : candidateNodes) {
                        filter = candidateNode.getEntityDefinition().getFilter();
                        if (filter == null || filter.match(child)) {
                            // XXX add to all candidates!?
                            if (candidateNode.getValue() == null) {
                                candidateNode.setAnnotatedParent(source);
                                source.addAnnotatedChild(candidateNode);
                            } else {
                                // Duplicate here, because there is no
                                // guarantee, that the Duplication
                                // Visitor will visit candidateNode after
                                // this node.
                                SourceNodeImpl duplicateNode = new SourceNodeImpl(candidateNode.getEntityDefinition(), candidateNode.getParent(), false);
                                duplicateNode.setAnnotatedParent(source);
                                source.addAnnotatedChild(duplicateNode);
                                TransformationContext context = candidateNode.getContext();
                                duplicateNode.setContext(context);
                                if (context != null) {
                                    context.duplicateContext(candidateNode, duplicateNode, Collections.<Cell>emptySet(), log);
                                } else {
                                    /*
										 * Not sure what this really means if we
										 * get here.
										 * 
										 * Best guess: Probably that we weren't
										 * able to determine how the duplication
										 * of this source can be propagted to
										 * the target. Thus the duplicated node
										 * will probably not have any
										 * connection.
										 */
                                    log.warn(log.createMessage("No transformation context for duplicated node of source " + candidateNode.getDefinition().getDisplayName(), null));
                                }
                                candidateNode = duplicateNode;
                            }
                            // run instance visitor on that annotated child
                            InstanceVisitor visitor = new InstanceVisitor(child, tree, log);
                            candidateNode.accept(visitor);
                        }
                    }
                }
                return true;
            }
        } else
            return false;
    } else {
        Object parentValue = source.getParent().getValue();
        if (parentValue == null || !(parentValue instanceof Group)) {
            source.setDefined(false);
            return false;
        } else {
            Group parentGroup = (Group) parentValue;
            Definition<?> currentDef = source.getDefinition();
            Object[] values = parentGroup.getProperty(currentDef.getName());
            if (values == null) {
                source.setDefined(false);
                return false;
            }
            // check for contexts
            EntityDefinition entityDef = source.getEntityDefinition();
            // index context
            Integer index = AlignmentUtil.getContextIndex(entityDef);
            if (index != null) {
                // only use the value at the given index, if present
                if (index < values.length) {
                    // annotate with the value at the index
                    Object value = values[index];
                    source.setValue(value);
                    return true;
                } else {
                    source.setDefined(false);
                    return false;
                }
            }
            // condition context
            Condition condition = AlignmentUtil.getContextCondition(entityDef);
            if (condition != null) {
                if (condition.getFilter() == null) {
                    // assume exclusion
                    source.setDefined(false);
                    return false;
                }
                // apply condition as filter on values and continue with
                // those values
                Collection<Object> matchedValues = new ArrayList<Object>();
                for (Object value : values) {
                    // determine parent
                    Object parent = null;
                    SourceNode parentNode = source.getParent();
                    if (parentNode != null && parentNode.isDefined()) {
                        parent = parentNode.getValue();
                    }
                    // test the condition
                    if (AlignmentUtil.matchCondition(condition, value, parent)) {
                        matchedValues.add(value);
                    }
                }
                values = matchedValues.toArray();
            }
            // default behavior (default context)
            if (values.length >= 1) {
                // annotate with the first value
                Object value = values[0];
                source.setValue(value);
                source.setAllValues(values);
            } else {
                source.setDefined(false);
                return false;
            }
            if (values.length > 1) {
                // handle additional values
                Object[] leftovers = new Object[values.length - 1];
                System.arraycopy(values, 1, leftovers, 0, leftovers.length);
                source.setLeftovers(new LeftoversImpl(source, leftovers));
            }
            return true;
        }
    }
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) Group(eu.esdihumboldt.hale.common.instance.model.Group) ArrayList(java.util.ArrayList) TransformationContext(eu.esdihumboldt.hale.common.align.model.transformation.tree.context.TransformationContext) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) SourceNodeImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.SourceNodeImpl) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) LeftoversImpl(eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.LeftoversImpl) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance)

Aggregations

TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)68 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)25 ArrayList (java.util.ArrayList)21 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)20 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)18 Cell (eu.esdihumboldt.hale.common.align.model.Cell)16 Type (eu.esdihumboldt.hale.common.align.model.Type)16 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)15 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)13 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)13 JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)12 QName (javax.xml.namespace.QName)10 Entity (eu.esdihumboldt.hale.common.align.model.Entity)8 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)8 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)8 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)8 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)8 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)7 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)6