Search in sources :

Example 61 with TypeEntityDefinition

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

the class UserFallbackEntityResolver method resolveType.

/**
 * Ask the user to select a replacement for a type.
 *
 * @param original the original entity
 * @param candidate a candidate for the replacement
 * @param schemaSpace the schema space
 * @return the resolved type (may be the original)
 */
public static Type resolveType(TypeEntityDefinition original, @Nullable EntityDefinition candidate, SchemaSpaceID schemaSpace) {
    ResolveCache cache = getCache();
    TypeEntityDefinition replacement = cache.getReplacement(original);
    if (replacement != null) {
        // use cached replacement
        return new DefaultType(replacement);
    }
    ProjectService ps = HaleUI.getServiceProvider().getService(ProjectService.class);
    final AtomicBoolean canceled;
    final AtomicBoolean skipped = new AtomicBoolean(false);
    if (ps.getTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(false)).as(Boolean.class)) {
        canceled = new AtomicBoolean(true);
    } else {
        canceled = new AtomicBoolean(false);
    }
    final AtomicReference<EntityDefinition> result = new AtomicReference<>();
    if (!canceled.get()) {
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

            @Override
            public void run() {
                TypeEntityResolverDialog dlg = new TypeEntityResolverDialog(Display.getCurrent().getActiveShell(), schemaSpace, "Cell entity could not be resolved", candidate, false) {

                    @Override
                    public void create() {
                        super.create();
                        openTray(new ViewerEntityTray(original));
                    }
                };
                switch(dlg.open()) {
                    case Window.OK:
                        result.set(dlg.getObject());
                        break;
                    case Window.CANCEL:
                        // Don't try to resolve further entities
                        ps.setTemporaryProperty(RESOLVE_SKIP_PROPERTY, Value.of(true));
                        canceled.set(true);
                        break;
                    case TypeEntityResolverDialog.SKIP:
                        // skip this entity
                        skipped.set(true);
                        break;
                    default:
                        canceled.set(true);
                }
            }
        });
    }
    EntityDefinition def = result.get();
    if (canceled.get() || skipped.get()) {
        // return the original so the cell is not lost
        return new DefaultType(original);
    } else if (def == null) {
        // caller must take care about this
        return null;
    } else {
        TypeEntityDefinition ted = (TypeEntityDefinition) def;
        // make sure that the type is classified as mapping relevant
        if (!ted.getType().getConstraint(MappingRelevantFlag.class).isEnabled()) {
            SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
            ss.toggleMappable(schemaSpace, Collections.singleton(ted.getType()));
        }
        cache.put(original, ted);
        return new DefaultType(ted);
    }
}
Also used : DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityResolverDialog(eu.esdihumboldt.hale.ui.service.align.resolver.internal.TypeEntityResolverDialog) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) ViewerEntityTray(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ViewerEntityTray) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) ResolveCache(eu.esdihumboldt.hale.ui.service.align.resolver.internal.ResolveCache) MappingRelevantFlag(eu.esdihumboldt.hale.common.schema.model.constraint.type.MappingRelevantFlag)

Example 62 with TypeEntityDefinition

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

the class EntityDefinitionServiceImpl method getTypeEntities.

/**
 * @see EntityDefinitionService#getTypeEntities(TypeDefinition,
 *      SchemaSpaceID)
 */
@Override
public Collection<? extends TypeEntityDefinition> getTypeEntities(TypeDefinition type, SchemaSpaceID schemaSpace) {
    TypeEntityDefinition ted = new TypeEntityDefinition(type, schemaSpace, null);
    Set<Condition> conditions;
    synchronized (conditionContexts) {
        conditions = conditionContexts.get(ted);
    }
    List<TypeEntityDefinition> result = new ArrayList<TypeEntityDefinition>();
    // add default type entity
    result.add(ted);
    // type entity definitions with filters
    for (Condition condition : conditions) {
        result.add(new TypeEntityDefinition(type, schemaSpace, condition.getFilter()));
    }
    return result;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ArrayList(java.util.ArrayList)

Example 63 with TypeEntityDefinition

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

the class EntityDefinitionServiceImpl method replace.

/**
 * Creates a new ListMultimap with all occurrences of originalDef replaced
 * by newDef. newDef must be a sibling of originalDef.
 *
 * @param entities the original list
 * @param originalDef the entity definition to be replaced
 * @param newDef the entity definition to use
 * @return a new list
 */
private ListMultimap<String, ? extends Entity> replace(ListMultimap<String, ? extends Entity> entities, EntityDefinition originalDef, EntityDefinition newDef) {
    ListMultimap<String, Entity> newList = ArrayListMultimap.create();
    for (Entry<String, ? extends Entity> entry : entities.entries()) {
        EntityDefinition entryDef = entry.getValue().getDefinition();
        Entity newEntry;
        if (AlignmentUtil.isParent(originalDef, entryDef)) {
            if (entry.getValue() instanceof Type) {
                // entry is a Type, so the changed Definition must be a
                // Type, too.
                newEntry = new DefaultType((TypeEntityDefinition) newDef);
            } else if (entry.getValue() instanceof Property) {
                // entry is a Property, check changed Definition.
                if (originalDef.getPropertyPath().isEmpty()) {
                    // Type changed.
                    newEntry = new DefaultProperty(new PropertyEntityDefinition(newDef.getType(), entryDef.getPropertyPath(), entryDef.getSchemaSpace(), newDef.getFilter()));
                } else {
                    // Some element of the property path changed.
                    List<ChildContext> newPath = new ArrayList<ChildContext>(entryDef.getPropertyPath());
                    int lastIndexOfChangedDef = newDef.getPropertyPath().size() - 1;
                    newPath.set(lastIndexOfChangedDef, newDef.getPropertyPath().get(lastIndexOfChangedDef));
                    newEntry = new DefaultProperty(new PropertyEntityDefinition(entryDef.getType(), newPath, entryDef.getSchemaSpace(), entryDef.getFilter()));
                }
            } else {
                throw new IllegalStateException("Entity is neither a Type nor a Property.");
            }
        } else {
            newEntry = entry.getValue();
        }
        newList.put(entry.getKey(), newEntry);
    }
    return newList;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) 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) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 64 with TypeEntityDefinition

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

the class UnpopulatedPropertiesFilter method select.

/**
 * @see ViewerFilter#select(Viewer, Object, Object)
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (ps != null) {
        if (element instanceof TreePath) {
            element = ((TreePath) element).getLastSegment();
        }
        if (element instanceof EntityDefinition) {
            EntityDefinition entityDef = (EntityDefinition) element;
            if (filterOnlyPopulatedTypes) {
                TypeEntityDefinition type = AlignmentUtil.getTypeEntity(entityDef);
                int typeCount = ps.getPopulation(type).getOverallCount();
                if (typeCount == 0 || typeCount == Population.UNKNOWN) {
                    // all
                    return true;
                }
            }
            if (!entityDef.getPropertyPath().isEmpty() && // only filter properties
            ps.hasPopulation(entityDef.getSchemaSpace())) {
                // only filter if there is a population
                Population pop = ps.getPopulation(entityDef);
                return pop != null && pop.getOverallCount() != 0;
            }
        }
    }
    return true;
}
Also used : 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) TreePath(org.eclipse.jface.viewers.TreePath) Population(eu.esdihumboldt.hale.ui.common.service.population.Population)

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