Search in sources :

Example 6 with Condition

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

the class PurgeConditionContextHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof EntityDefinition) {
            EntityDefinition entityDef = (EntityDefinition) element;
            Condition condition = AlignmentUtil.getContextCondition(entityDef);
            if (condition != null && condition.getFilter() != null) {
                EntityDefinitionService eds = PlatformUI.getWorkbench().getService(EntityDefinitionService.class);
                eds.editConditionContext((EntityDefinition) element, null);
            }
        }
    }
    return null;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntityDefinitionService(eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)

Example 7 with Condition

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

the class AbstractPropertyTransformationHandler method getConditionalExpression.

/**
 * Wraps the provided CQL expression in a conditional expression, based on
 * the filter defined on the property.
 *
 * <p>
 * TODO: current implementation is broken, don't use it (first argument of
 * if_then_else must be an expression, cannot be a filter (i.e. cannot
 * contain '=' sign))!
 * </p>
 *
 * @param propertyEntityDef the property definition defining the condition
 * @param cql the CQL expression to wrap
 * @return a conditional expression wrapping the provided CQL expression
 */
protected static String getConditionalExpression(PropertyEntityDefinition propertyEntityDef, String cql) {
    if (propertyEntityDef != null) {
        String propertyName = propertyEntityDef.getDefinition().getName().getLocalPart();
        List<ChildContext> propertyPath = propertyEntityDef.getPropertyPath();
        // properties
        if (propertyPath.size() == 1) {
            Condition condition = propertyPath.get(0).getCondition();
            if (condition != null) {
                String fitlerText = AlignmentUtil.getFilterText(condition.getFilter());
                // remove "parent" references
                fitlerText = fitlerText.replace("parent.", "");
                // replace "value" references with the local name of the
                // property itself
                fitlerText = fitlerText.replace("value", propertyName);
                return String.format("if_then_else(%s, %s, Expression.NIL)", fitlerText, cql);
            }
        }
    }
    return cql;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 8 with Condition

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

the class CQLFilterDialogFactory method openDialog.

@Override
public Filter openDialog(Shell shell, EntityDefinition entityDef, String title, String message) {
    TypeEntityDefinition parentType;
    if (entityDef.getPropertyPath().isEmpty())
        parentType = AlignmentUtil.getTypeEntity(entityDef);
    else {
        Definition<?> def = entityDef.getDefinition();
        TypeDefinition propertyType = ((PropertyDefinition) def).getPropertyType();
        // create a dummy type for the filter
        TypeDefinition dummyType = new DefaultTypeDefinition(new QName("ValueFilterDummy"));
        // create dummy type entity
        Condition condition = AlignmentUtil.getContextCondition(entityDef);
        Filter filter = condition == null ? null : condition.getFilter();
        parentType = new TypeEntityDefinition(dummyType, entityDef.getSchemaSpace(), filter);
        // with the property type being contained as value
        // property
        new DefaultPropertyDefinition(new QName("value"), dummyType, propertyType);
        // and the parent type as parent property
        new DefaultPropertyDefinition(new QName("parent"), dummyType, ((PropertyDefinition) def).getParentType());
    }
    CQLFilterDialog dialog = new CQLFilterDialog(shell, parentType, title, message);
    if (dialog.open() == CQLFilterDialog.OK) {
        return dialog.getFilter();
    }
    return null;
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) Condition(eu.esdihumboldt.hale.common.align.model.Condition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) QName(javax.xml.namespace.QName) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)

Example 9 with Condition

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

the class EntityDefinitionServiceImpl method editConditionContext.

/**
 * @see eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService#editConditionContext(eu.esdihumboldt.hale.common.align.model.EntityDefinition,
 *      eu.esdihumboldt.hale.common.instance.model.Filter)
 */
@Override
public EntityDefinition editConditionContext(final EntityDefinition sibling, Filter filter) {
    List<ChildContext> path = sibling.getPropertyPath();
    if (sibling.getSchemaSpace() == SchemaSpaceID.TARGET && path.isEmpty()) {
        // XXX throw exception instead?
        return null;
    }
    // Check whether there actually is a change. If not, we are done.
    Condition oldCondition = AlignmentUtil.getContextCondition(sibling);
    if (Objects.equal(filter, oldCondition == null ? null : oldCondition.getFilter()))
        return sibling;
    // Create the new entity. Do not add context yet, since the user could
    // still abort the process (see below).
    EntityDefinition newDef = AlignmentUtil.getDefaultEntity(sibling);
    if (filter != null)
        newDef = createWithCondition(sibling, new Condition(filter));
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    Alignment alignment = as.getAlignment();
    // Collect cells to replace.
    // All cells of the EntityDefinition's type can be affected.
    Collection<? extends Cell> potentiallyAffected = alignment.getCells(sibling.getType(), sibling.getSchemaSpace());
    Predicate<Cell> associatedCellPredicate = new Predicate<Cell>() {

        @Override
        public boolean apply(Cell input) {
            return input != null && AlignmentUtil.associatedWith(sibling, input, false, true);
        }
    };
    Collection<? extends Cell> affected = new HashSet<Cell>(Collections2.filter(potentiallyAffected, associatedCellPredicate));
    // Check whether base alignment cells are affected.
    boolean baseCellsAffected = false;
    Predicate<Cell> baseCellPredicate = new Predicate<Cell>() {

        @Override
        public boolean apply(Cell input) {
            return input != null && input.isBaseCell();
        }
    };
    if (Iterables.find(affected, baseCellPredicate, null) != null) {
        // Check whether the user wants to continue.
        final Display display = PlatformUI.getWorkbench().getDisplay();
        final AtomicBoolean abort = new AtomicBoolean();
        display.syncExec(new Runnable() {

            @Override
            public void run() {
                MessageBox mb = new MessageBox(display.getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
                mb.setMessage("Some base alignment cells reference the entity definition you wish to change.\n" + "The change will only affect cells which aren't from any base alignment.\n\n" + "Do you still wish to continue?");
                mb.setText("Continue?");
                abort.set(mb.open() != SWT.YES);
            }
        });
        if (abort.get())
            return null;
        // Filter base alignment cells out.
        baseCellsAffected = true;
        affected = Collections2.filter(affected, Predicates.not(baseCellPredicate));
    }
    // Add condition context if necessary
    if (filter != null)
        addConditionContext(sibling, filter);
    // Replace affected (filtered) cells.
    Map<Cell, MutableCell> replaceMap = new HashMap<Cell, MutableCell>();
    for (Cell cell : affected) {
        DefaultCell newCell = new DefaultCell(cell);
        if (newDef.getSchemaSpace() == SchemaSpaceID.SOURCE)
            newCell.setSource(replace(newCell.getSource(), sibling, newDef));
        else
            newCell.setTarget(replace(newCell.getTarget(), sibling, newDef));
        replaceMap.put(cell, newCell);
    }
    as.replaceCells(replaceMap);
    // nor do any base alignment cells still use it.
    if (oldCondition != null && !baseCellsAffected)
        removeContext(sibling);
    return newDef;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashMap(java.util.HashMap) Predicate(com.google.common.base.Predicate) MessageBox(org.eclipse.swt.widgets.MessageBox) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

Example 10 with Condition

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

the class EntityDefinitionServiceImpl method removeContext.

/**
 * @see EntityDefinitionService#removeContext(EntityDefinition)
 */
@Override
public void removeContext(EntityDefinition entity) {
    EntityDefinition def = AlignmentUtil.getDefaultEntity(entity);
    // XXX any checks? Alignment must still be valid! see also
    // InstanceContextTester
    List<ChildContext> path = entity.getPropertyPath();
    if (path.isEmpty()) {
        // type entity definition
        Filter filter = entity.getFilter();
        if (filter != null) {
            synchronized (conditionContexts) {
                conditionContexts.remove(def, new Condition(filter));
            }
        // XXX what about the children of this context?
        }
        notifyContextRemoved(entity);
        return;
    }
    boolean removed = false;
    ChildContext lastContext = path.get(path.size() - 1);
    if (lastContext.getContextName() != null) {
        synchronized (namedContexts) {
            namedContexts.remove(def, lastContext.getContextName());
        }
        removed = true;
    }
    if (lastContext.getIndex() != null) {
        synchronized (indexContexts) {
            indexContexts.remove(def, lastContext.getIndex());
        }
        removed = true;
    }
    if (lastContext.getCondition() != null) {
        synchronized (conditionContexts) {
            conditionContexts.remove(def, lastContext.getCondition());
        }
        removed = true;
    }
    if (removed) {
        notifyContextRemoved(entity);
    }
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) 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) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Aggregations

Condition (eu.esdihumboldt.hale.common.align.model.Condition)12 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)8 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)8 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)6 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)6 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)4 ArrayList (java.util.ArrayList)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)2 EntityDefinitionService (eu.esdihumboldt.hale.ui.service.entity.EntityDefinitionService)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Predicate (com.google.common.base.Predicate)1 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)1 Property (eu.esdihumboldt.hale.common.align.model.Property)1 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)1 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)1 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)1 SourceNode (eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode)1