Search in sources :

Example 56 with Entity

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

the class JoinMergeMigrator method mergeRetypeSource.

@SuppressWarnings("unused")
private void mergeRetypeSource(MutableCell cell, EntityDefinition source, Cell match, Cell originalCell, SimpleLog log, JoinContext context, boolean groovy) {
    /*
		 * Sources: Add all from match (should be one)
		 */
    addSources(cell, source, match, log, true);
    /*
		 * Join order: Replace type with matched source
		 */
    Entity matchEntity = CellUtil.getFirstEntity(match.getSource());
    TypeEntityDefinition matchSource = null;
    if (matchEntity != null) {
        EntityDefinition def = matchEntity.getDefinition();
        if (def instanceof TypeEntityDefinition) {
            matchSource = (TypeEntityDefinition) def;
        }
    }
    if (matchSource != null) {
        context.addOrderReplacement((TypeEntityDefinition) source, matchSource);
    } else {
        log.error("Match for source {0} is invalid and does not have a type source", source.getDefinition());
        return;
    }
    if (groovy) {
        addScript(match, context);
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)

Example 57 with Entity

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

the class JaxbToAlignment method convertEntities.

private static ListMultimap<String, Pair<Entity, Entity>> convertEntities(List<NamedEntityType> namedEntities, TypeIndex types, SchemaSpaceID schemaSpace, EntityResolver resolver) {
    if (namedEntities == null || namedEntities.isEmpty()) {
        return null;
    }
    ListMultimap<String, Pair<Entity, Entity>> result = ArrayListMultimap.create();
    for (NamedEntityType namedEntity : namedEntities) {
        /**
         * Resolve entity.
         *
         * Possible results:
         * <ul>
         * <li>non-null entity - entity could be resolved</li>
         * <li>null entity - entity could not be resolved, continue</li>
         * <li>IllegalStateException - entity could not be resolved, reject
         * cell</li>
         * </ul>
         */
        // Create a dummy entity from the original XML definition
        DummyEntityResolver dummyResolver = new DummyEntityResolver();
        Entity dummyEntity = dummyResolver.resolve(namedEntity.getAbstractEntity().getValue(), types, schemaSpace);
        // Resolve the real entity
        Entity resolvedEntity = resolver.resolve(namedEntity.getAbstractEntity().getValue(), types, schemaSpace);
        if (resolvedEntity != null) {
            result.put(namedEntity.getName(), new Pair<Entity, Entity>(dummyEntity, resolvedEntity));
        }
    }
    return result;
}
Also used : NamedEntityType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.NamedEntityType) Entity(eu.esdihumboldt.hale.common.align.model.Entity) DummyEntityResolver(eu.esdihumboldt.hale.common.align.io.impl.dummy.DummyEntityResolver) Pair(eu.esdihumboldt.util.Pair)

Example 58 with Entity

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

the class JaxbToAlignment method createUnmigratedCell.

private static UnmigratedCell createUnmigratedCell(CellType cell, LoadAlignmentContext context, IOReporter reporter, EntityResolver resolver, ServiceProvider serviceProvider) {
    // The sourceCell represents the cell as it was imported from the
    // XML alignment. The conversion to the resolved cell must be performed
    // later by migrating the UnmigratedCell returned from this function.
    final DefaultCell sourceCell = new DefaultCell();
    sourceCell.setTransformationIdentifier(cell.getRelation());
    final FunctionDefinition<?> cellFunction = FunctionUtil.getFunction(sourceCell.getTransformationIdentifier(), serviceProvider);
    final CellMigrator migrator;
    if (cellFunction != null) {
        migrator = cellFunction.getCustomMigrator().orElse(new DefaultCellMigrator());
    } else {
        migrator = new DefaultCellMigrator();
    }
    Map<EntityDefinition, EntityDefinition> mappings = new HashMap<>();
    try {
        // The returned Entity pair consists of
        // (1st) a dummy entity representing the entity read from JAXB
        // (2nd) the resolved entity
        ListMultimap<String, Pair<Entity, Entity>> convertedSourceEntities = convertEntities(cell.getSource(), context.getSourceTypes(), SchemaSpaceID.SOURCE, resolver);
        if (convertedSourceEntities == null) {
            sourceCell.setSource(null);
        } else {
            sourceCell.setSource(Multimaps.transformValues(convertedSourceEntities, pair -> pair.getFirst()));
            for (Pair<Entity, Entity> pair : convertedSourceEntities.values()) {
                mappings.put(pair.getFirst().getDefinition(), pair.getSecond().getDefinition());
            }
        }
        ListMultimap<String, Pair<Entity, Entity>> convertedTargetEntities = convertEntities(cell.getTarget(), context.getTargetTypes(), SchemaSpaceID.TARGET, resolver);
        if (convertedTargetEntities == null) {
            sourceCell.setTarget(null);
        } else {
            sourceCell.setTarget(Multimaps.transformValues(convertedTargetEntities, pair -> pair.getFirst()));
            for (Pair<Entity, Entity> pair : convertedTargetEntities.values()) {
                mappings.put(pair.getFirst().getDefinition(), pair.getSecond().getDefinition());
            }
        }
        if (sourceCell.getTarget() == null || sourceCell.getTarget().isEmpty()) {
            // target is mandatory for cells!
            throw new IllegalStateException("Cannot create cell without target");
        }
    } catch (Exception e) {
        if (reporter != null) {
            reporter.error(new IOMessageImpl("Could not create cell", e));
        }
        return null;
    }
    if (!cell.getAbstractParameter().isEmpty()) {
        ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
        for (JAXBElement<? extends AbstractParameterType> param : cell.getAbstractParameter()) {
            AbstractParameterType apt = param.getValue();
            if (apt instanceof ParameterType) {
                // treat string parameters or null parameters
                ParameterType pt = (ParameterType) apt;
                ParameterValue pv = new ParameterValue(pt.getType(), Value.of(pt.getValue()));
                parameters.put(pt.getName(), pv);
            } else if (apt instanceof ComplexParameterType) {
                // complex parameters
                ComplexParameterType cpt = (ComplexParameterType) apt;
                parameters.put(cpt.getName(), new ParameterValue(new ElementValue(cpt.getAny(), context)));
            } else
                throw new IllegalStateException("Illegal parameter type");
        }
        sourceCell.setTransformationParameters(parameters);
    }
    // annotations & documentation
    for (Object element : cell.getDocumentationOrAnnotation()) {
        if (element instanceof AnnotationType) {
            // add annotation to the cell
            AnnotationType annot = (AnnotationType) element;
            // but first load it from the DOM
            AnnotationDescriptor<?> desc = AnnotationExtension.getInstance().get(annot.getType());
            if (desc != null) {
                try {
                    Object value = desc.fromDOM(annot.getAny(), null);
                    sourceCell.addAnnotation(annot.getType(), value);
                } catch (Exception e) {
                    if (reporter != null) {
                        reporter.error(new IOMessageImpl("Error loading cell annotation", e));
                    } else
                        throw new IllegalStateException("Error loading cell annotation", e);
                }
            } else
                reporter.error(new IOMessageImpl("Cell annotation of type {0} unknown, cannot load the annotation object", null, -1, -1, annot.getType()));
        } else if (element instanceof DocumentationType) {
            // add documentation to the cell
            DocumentationType doc = (DocumentationType) element;
            sourceCell.getDocumentation().put(doc.getType(), doc.getValue());
        }
    }
    sourceCell.setId(cell.getId());
    // a default value is assured for priority
    String priorityStr = cell.getPriority().value();
    Priority priority = Priority.fromValue(priorityStr);
    if (priority != null) {
        sourceCell.setPriority(priority);
    } else {
        // used.
        throw new IllegalArgumentException();
    }
    return new UnmigratedCell(sourceCell, migrator, mappings);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) CellMigrator(eu.esdihumboldt.hale.common.align.migrate.CellMigrator) Collections2(com.google.common.collect.Collections2) ModifierType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ModifierType) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) ElementValue(eu.esdihumboldt.hale.common.core.io.impl.ElementValue) HaleIO(eu.esdihumboldt.hale.common.core.io.HaleIO) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Map(java.util.Map) ParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ParameterType) Pair(eu.esdihumboldt.util.Pair) AnnotationDescriptor(eu.esdihumboldt.hale.common.align.model.AnnotationDescriptor) URI(java.net.URI) AnnotationExtension(eu.esdihumboldt.hale.common.align.extension.annotation.AnnotationExtension) Value(eu.esdihumboldt.hale.common.core.io.Value) Function(com.google.common.base.Function) Collection(java.util.Collection) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) JAXBException(javax.xml.bind.JAXBException) LoadAlignmentContext(eu.esdihumboldt.hale.common.align.io.LoadAlignmentContext) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) CustomFunctionType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CustomFunctionType) DummyEntityResolver(eu.esdihumboldt.hale.common.align.io.impl.dummy.DummyEntityResolver) List(java.util.List) Base(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType.Base) ComplexParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ComplexParameterType) TypeIndex(eu.esdihumboldt.hale.common.schema.model.TypeIndex) CellType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType) Priority(eu.esdihumboldt.hale.common.align.model.Priority) StreamSource(javax.xml.transform.stream.StreamSource) AnnotationType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AnnotationType) HashMap(java.util.HashMap) DefaultCellMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultCellMigrator) ArrayList(java.util.ArrayList) Multimaps(com.google.common.collect.Multimaps) JaxbAlignmentIO(eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentIO) EntityResolver(eu.esdihumboldt.hale.common.align.io.EntityResolver) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) DisableFor(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ModifierType.DisableFor) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) CustomPropertyFunction(eu.esdihumboldt.hale.common.align.extension.function.custom.CustomPropertyFunction) DocumentationType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.DocumentationType) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) ServiceProvider(eu.esdihumboldt.hale.common.core.service.ServiceProvider) DefaultEntityResolver(eu.esdihumboldt.hale.common.align.io.impl.DefaultEntityResolver) Entity(eu.esdihumboldt.hale.common.align.model.Entity) FunctionUtil(eu.esdihumboldt.hale.common.align.extension.function.FunctionUtil) AbstractParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AbstractParameterType) TransformationMode(eu.esdihumboldt.hale.common.align.model.TransformationMode) FunctionDefinition(eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition) Element(org.w3c.dom.Element) NamedEntityType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.NamedEntityType) AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) InputStream(java.io.InputStream) Entity(eu.esdihumboldt.hale.common.align.model.Entity) HashMap(java.util.HashMap) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) CellMigrator(eu.esdihumboldt.hale.common.align.migrate.CellMigrator) DefaultCellMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultCellMigrator) DefaultCellMigrator(eu.esdihumboldt.hale.common.align.migrate.impl.DefaultCellMigrator) AnnotationType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AnnotationType) UnmigratedCell(eu.esdihumboldt.hale.common.align.migrate.impl.UnmigratedCell) AbstractParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AbstractParameterType) Pair(eu.esdihumboldt.util.Pair) ParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ParameterType) ComplexParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ComplexParameterType) AbstractParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AbstractParameterType) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Priority(eu.esdihumboldt.hale.common.align.model.Priority) ElementValue(eu.esdihumboldt.hale.common.core.io.impl.ElementValue) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) ComplexParameterType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ComplexParameterType) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DocumentationType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.DocumentationType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 59 with Entity

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

the class SchemaExplorerLabelProvider method getEntityBackground.

private Color getEntityBackground(EntityDefinition entityDef, Alignment alignment, boolean isType) {
    // check for directly associated cells
    Collection<? extends Cell> cells = alignment.getCells(entityDef);
    if (!cells.isEmpty()) {
        if (isType) {
            return typeCellColor;
        }
        for (Cell cell : cells) {
            if (!AlignmentUtil.isAugmentation(cell)) {
                return propertyCellColor;
            }
        }
        return augmentedColor;
    }
    // check for cells associated to children of the entity definition
    cells = alignment.getCells(entityDef.getType(), entityDef.getSchemaSpace());
    for (Cell cell : cells) {
        ListMultimap<String, ? extends Entity> entities;
        switch(entityDef.getSchemaSpace()) {
            case SOURCE:
                entities = cell.getSource();
                break;
            case TARGET:
                entities = cell.getTarget();
                break;
            default:
                throw new IllegalStateException("Entity definition with illegal schema space encountered");
        }
        if (entities != null) {
            for (Entity entity : entities.values()) {
                if (AlignmentUtil.isParent(entityDef, entity.getDefinition())) {
                    return indirectMappingColor;
                }
            }
        }
    }
    if (!isType) {
        // check for direct inherited property cells
        cells = alignment.getCells(entityDef, true);
        if (!cells.isEmpty()) {
            for (Cell cell : cells) {
                if (!AlignmentUtil.isAugmentation(cell)) {
                    return inheritedPropertyCellColor;
                }
            }
            return inheritedAugmentedColor;
        }
    }
    // check for inherited child property cells
    // walk over all cells, alternatively could query for matching property
    // cells, don't know which would be faster
    cells = alignment.getCells();
    for (Cell cell : cells) if (!AlignmentUtil.isTypeCell(cell) && AlignmentUtil.associatedWith(entityDef, cell, true, true))
        return inheritedIndirectMappingColor;
    // default color
    return null;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 60 with Entity

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

the class TypeHierarchyView method update.

/**
 * Update the hierarchy view with the given selection
 *
 * @param selection the selection
 */
protected void update(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof ParentPath) {
            element = ((ParentPath) element).getHead();
        }
        if (element instanceof Entity) {
            element = ((Entity) element).getDefinition();
        }
        if (element instanceof EntityDefinition) {
            element = ((EntityDefinition) element).getDefinition();
        }
        viewer.setInput(element);
        ParentPath path = TypeHierarchyContentProvider.createPath(element);
        viewer.expandAll();
        if (path != null) {
            viewer.setSelection(new StructuredSelection(path.getMainPath()));
        }
    } else {
        viewer.setInput(null);
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ParentPath(eu.esdihumboldt.hale.ui.views.typehierarchy.TypeHierarchyContentProvider.ParentPath) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

Entity (eu.esdihumboldt.hale.common.align.model.Entity)64 Cell (eu.esdihumboldt.hale.common.align.model.Cell)25 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)21 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)14 ArrayList (java.util.ArrayList)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)9 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)9 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)9 List (java.util.List)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)8 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)6 HashSet (java.util.HashSet)6 Locale (java.util.Locale)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)4 CellUtil (eu.esdihumboldt.hale.common.align.model.CellUtil)4 CellLog (eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)4 AbstractCellExplanation (eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation)4