Search in sources :

Example 71 with EntityDefinition

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

the class XPathParameterPage method determineDefaultVariableNames.

@Override
protected Map<EntityDefinition, String> determineDefaultVariableNames(List<EntityDefinition> variables) {
    Map<EntityDefinition, String> result = new LinkedHashMap<EntityDefinition, String>();
    // variable names depend on order for GenericXPath
    int number = 1;
    for (EntityDefinition var : variables) {
        result.put(var, "$" + GenericXPath.PREFIX_VAR + number++);
    }
    return result;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) LinkedHashMap(java.util.LinkedHashMap)

Example 72 with EntityDefinition

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

the class XPathFilterField method selectVariable.

/**
 * @see eu.esdihumboldt.hale.ui.filter.TypeFilterField#selectVariable()
 */
@Override
protected String selectVariable() {
    XPathPropertyDefinitionDialog dialog = new XPathPropertyDefinitionDialog(Display.getCurrent().getActiveShell(), entity, "Insert attribute name", null);
    if (dialog.open() == XPathPropertyDefinitionDialog.OK && dialog.getObject() != null) {
        EntityDefinition entityDef = dialog.getObject();
        StringBuilder var = new StringBuilder();
        for (int i = 0; i < dialog.getParentCount(); i++) var.append("../");
        // skip the first path element if we didn't start at top level
        int start = dialog.atTopLevel() ? 0 : 1;
        // if the element itself was selected simply use a single dot
        if (dialog.getParentCount() == 0 && entityDef.getPropertyPath().size() == start)
            var.append(".");
        boolean first = true;
        for (int i = start; i < entityDef.getPropertyPath().size(); i++) {
            PropertyDefinition propDef = entityDef.getPropertyPath().get(i).getChild().asProperty();
            if (propDef != null) {
                if (first)
                    first = false;
                else
                    var.append("/");
                if (propDef.getConstraint(XmlAttributeFlag.class).isEnabled())
                    var.append('@');
                QName name = entityDef.getPropertyPath().get(i).getChild().getName();
                if (!XMLConstants.NULL_NS_URI.equals(name.getNamespaceURI()))
                    var.append("\"").append(name.getNamespaceURI()).append("\":");
                var.append(name.getLocalPart());
            }
        }
        return var.toString();
    } else
        return null;
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) QName(javax.xml.namespace.QName) XmlAttributeFlag(eu.esdihumboldt.hale.io.xsd.constraint.XmlAttributeFlag) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)

Example 73 with EntityDefinition

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

the class GroovyTransformation method createGroovyBinding.

/**
 * Create a Groovy binding from the list of variables.
 *
 * @param vars the variable values
 * @param varDefs definition of the assigned variables, in case some
 *            variable values are not set, may be <code>null</code>
 * @param cell the cell the binding is created for
 * @param typeCell the type cell the binding is created for, may be
 *            <code>null</code>
 * @param builder the instance builder for creating target instances, or
 *            <code>null</code> if not applicable
 * @param useInstanceVariables if instances should be used as variables for
 *            the binding instead of extracting the instance values
 * @param log the transformation log
 * @param context the execution context
 * @param targetInstanceType the type of the target instance
 * @return the binding for use with {@link GroovyShell}
 */
public static Binding createGroovyBinding(List<PropertyValue> vars, List<? extends Entity> varDefs, Cell cell, Cell typeCell, InstanceBuilder builder, boolean useInstanceVariables, TransformationLog log, ExecutionContext context, TypeDefinition targetInstanceType) {
    Binding binding = GroovyUtil.createBinding(builder, cell, typeCell, log, context, targetInstanceType);
    // collect definitions to check if all were provided
    Set<EntityDefinition> notDefined = new HashSet<>();
    if (varDefs != null) {
        for (Entity entity : varDefs) {
            notDefined.add(entity.getDefinition());
        }
    }
    // keep only defs where no value is provided
    if (!notDefined.isEmpty()) {
        for (PropertyValue var : vars) {
            notDefined.remove(var.getProperty());
        }
    }
    // add null value for missing variables
    if (!notDefined.isEmpty()) {
        vars = new ArrayList<>(vars);
        for (EntityDefinition entityDef : notDefined) {
            if (entityDef instanceof PropertyEntityDefinition) {
                vars.add(new PropertyValueImpl(null, (PropertyEntityDefinition) entityDef));
            }
        }
    }
    for (PropertyValue var : vars) {
        // add the variable to the environment
        addToBinding(binding, var.getProperty(), getUseValue(var.getValue(), useInstanceVariables));
    }
    return binding;
}
Also used : Binding(groovy.lang.Binding) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Entity(eu.esdihumboldt.hale.common.align.model.Entity) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) PropertyValue(eu.esdihumboldt.hale.common.align.transformation.function.PropertyValue) HashSet(java.util.HashSet) PropertyValueImpl(eu.esdihumboldt.hale.common.align.transformation.function.impl.PropertyValueImpl)

Example 74 with EntityDefinition

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

the class DefaultCellMigrator method updateCell.

@Override
public MutableCell updateCell(final Cell originalCell, final AlignmentMigration migration, final MigrationOptions options, SimpleLog log) {
    MutableCell result = new DefaultCell(originalCell);
    SimpleLog cellLog = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));
    final AtomicBoolean replacedEntities = new AtomicBoolean(false);
    EntryTransformer<String, Entity, Entity> entityTransformer = new EntryTransformer<String, Entity, Entity>() {

        @Override
        public Entity transformEntry(String key, Entity value) {
            EntityDefinition org = value.getDefinition();
            Optional<EntityDefinition> replace = migration.entityReplacement(org, cellLog);
            EntityDefinition entity = replace.orElse(org);
            if (!Objects.equal(entity, org)) {
                replacedEntities.set(true);
            }
            if (entity instanceof PropertyEntityDefinition) {
                return new DefaultProperty((PropertyEntityDefinition) entity);
            } else if (entity instanceof TypeEntityDefinition) {
                return new DefaultType((TypeEntityDefinition) entity);
            } else {
                throw new IllegalStateException("Invalid entity definition for creating entity");
            }
        }
    };
    // update source entities
    if (options.updateSource() && result.getSource() != null && !result.getSource().isEmpty()) {
        result.setSource(ArrayListMultimap.create(Multimaps.transformEntries(result.getSource(), entityTransformer)));
    }
    // update target entities
    if (options.updateTarget() && result.getTarget() != null && !result.getTarget().isEmpty()) {
        result.setTarget(ArrayListMultimap.create(Multimaps.transformEntries(result.getTarget(), entityTransformer)));
    }
    // TODO anything else?
    postUpdateCell(result, options, replacedEntities.get(), cellLog);
    return result;
}
Also used : SimpleLog(eu.esdihumboldt.hale.common.core.report.SimpleLog) Entity(eu.esdihumboldt.hale.common.align.model.Entity) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) EntryTransformer(com.google.common.collect.Maps.EntryTransformer) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) CellLog(eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)

Example 75 with EntityDefinition

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

the class PropertyOrChildrenTypeCondition method accept.

private boolean accept(EntityDefinition entityDef, Set<TypeDefinition> tested) {
    Definition<?> def = entityDef.getDefinition();
    if (def instanceof PropertyDefinition) {
        // test the property definition and its property type
        TypeDefinition type = ((PropertyDefinition) def).getPropertyType();
        if (tested.contains(type)) {
            // we already tested that type
            return false;
        }
        if (accept(type, entityDef.getSchemaSpace())) {
            return true;
        }
        tested.add(type);
    }
    // test the children
    for (ChildDefinition<?> child : DefinitionUtil.getAllChildren(DefinitionUtil.getDefinitionGroup(def))) {
        EntityDefinition childDef = AlignmentUtil.getChild(entityDef, child.getName());
        if (accept(childDef, tested)) {
            return true;
        }
    }
    return false;
}
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) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)99 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)39 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)37 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)23 ArrayList (java.util.ArrayList)22 Entity (eu.esdihumboldt.hale.common.align.model.Entity)21 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)20 Cell (eu.esdihumboldt.hale.common.align.model.Cell)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)11 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)10 HashSet (java.util.HashSet)10 QName (javax.xml.namespace.QName)10 HashMap (java.util.HashMap)9 Condition (eu.esdihumboldt.hale.common.align.model.Condition)8 SimpleLog (eu.esdihumboldt.hale.common.core.report.SimpleLog)7 ISelection (org.eclipse.jface.viewers.ISelection)7 List (java.util.List)6 TreePath (org.eclipse.jface.viewers.TreePath)6 AlignmentMigration (eu.esdihumboldt.hale.common.align.migrate.AlignmentMigration)5