Search in sources :

Example 1 with JoinParameter

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter in project hale by halestudio.

the class JoinParameterPage method getConfiguration.

/**
 * @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#getConfiguration()
 */
@Override
public ListMultimap<String, ParameterValue> getConfiguration() {
    ListMultimap<String, ParameterValue> result = ArrayListMultimap.create(1, 1);
    Set<JoinCondition> conditions = new HashSet<>();
    for (ConditionPage page : pages) {
        conditions.addAll(page.conditions);
    }
    JoinParameter param = new JoinParameter(types, conditions);
    result.put(PARAMETER_JOIN, new ParameterValue(new ComplexValue(param)));
    return result;
}
Also used : ComplexValue(eu.esdihumboldt.hale.common.core.io.impl.ComplexValue) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) HashSet(java.util.HashSet)

Example 2 with JoinParameter

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter in project hale by halestudio.

the class JoinParameterPage method createJoinParameter.

/**
 * Creates a join parameter for the types up to <code>upToIndex</code>.
 *
 * @param upToIndex the type index up to which the parameter should be
 *            created for
 * @return the current join parameter up to the specified index
 */
private JoinParameter createJoinParameter(int upToIndex) {
    Set<JoinCondition> conditions = new HashSet<>();
    for (int i = 0; i < upToIndex; i++) conditions.addAll(pages.get(i).conditions);
    JoinParameter param = new JoinParameter(types.subList(0, upToIndex + 1), conditions);
    return param;
}
Also used : JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) HashSet(java.util.HashSet)

Example 3 with JoinParameter

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter in project hale by halestudio.

the class JoinParameterPage method onShowPage.

/**
 * @see eu.esdihumboldt.hale.ui.HaleWizardPage#onShowPage(boolean)
 */
@Override
protected void onShowPage(boolean firstShow) {
    super.onShowPage(firstShow);
    Cell cell = getWizard().getUnfinishedCell();
    List<? extends Entity> sourceEntities = cell.getSource().get(JOIN_TYPES);
    List<TypeEntityDefinition> types = new ArrayList<TypeEntityDefinition>();
    Iterator<? extends Entity> iter = sourceEntities.iterator();
    while (iter.hasNext()) {
        types.add(AlignmentUtil.getTypeEntity(iter.next().getDefinition()));
    }
    if (sameTypes(this.types, types)) {
        return;
    }
    if (containsDuplicateType(types)) {
        setPageComplete(false);
        setErrorMessage("The selected source types contain duplicates.");
        this.types.clear();
        table.setInput(null);
        return;
    } else {
        setErrorMessage(null);
    }
    JoinParameter initialValue = null;
    if (firstShow && !getInitialValues().get(PARAMETER_JOIN).isEmpty()) {
        initialValue = getInitialValues().get(PARAMETER_JOIN).get(0).as(JoinParameter.class);
        if (initialValue != null) {
            // use ordering of the initial value (needs to be modifiable)
            List<TypeEntityDefinition> tmp = new ArrayList<>(initialValue.getTypes());
            // append any type that were added, or remove types that were
            // removed
            tmp.retainAll(types);
            List<TypeEntityDefinition> more = new ArrayList<>(types);
            more.removeAll(tmp);
            tmp.addAll(more);
            types = tmp;
            // apply potentially changed type list
            initialValue = new JoinParameter(types, initialValue.getConditions());
            if (initialValue.validate(true) != null) {
                // try to fix config
                // not recoverable
                initialValue = null;
            }
        }
    }
    this.types = types;
    for (ConditionPage page : pages) {
        page.dispose();
    }
    pages.clear();
    if (table != null) {
        table.setInput(types);
    }
    for (int i = 1; i < types.size(); i++) {
        ConditionPage conditionPage = new ConditionPage(i);
        conditionPage.setWizard(getWizard());
        pages.add(conditionPage);
    }
    if (initialValue != null) {
        // add initial conditions
        for (JoinCondition condition : initialValue.getConditions()) {
            TypeEntityDefinition joinType = AlignmentUtil.getTypeEntity(condition.joinProperty);
            int typeIndex = types.indexOf(joinType);
            int pageIndex = typeIndex - 1;
            pages.get(pageIndex).conditions.add(condition);
            pages.get(pageIndex).updateCompletionStatus();
        }
    }
    // order is always valid, will trigger updateButtons
    setPageComplete(true);
}
Also used : TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ArrayList(java.util.ArrayList) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)

Example 4 with JoinParameter

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter in project hale by halestudio.

the class GroovyJoinPage method validate.

@Override
protected boolean validate(String document) {
    ParameterValue param = CellUtil.getFirstParameter(getWizard().getUnfinishedCell(), JoinFunction.PARAMETER_JOIN);
    JoinParameter joinParameter = param.as(JoinParameter.class);
    // check Join parameter
    if (joinParameter == null) {
        // setValidationError("Missing join configuration");
        return false;
    } else {
        String error = joinParameter.validate();
        if (!setValidationError(error)) {
            return false;
        }
    }
    // target type
    Type targetType = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
    if (targetType == null) {
        // not yet selected (NewRelationWizard)
        return false;
    }
    /*
		 * FIXME use JoinParameter to fake joined instances!
		 * 
		 * XXX for now just base instance
		 */
    TypeEntityDefinition sourceType = joinParameter.getTypes().get(0);
    InstanceBuilder builder = new InstanceBuilder(false);
    Instance instance = getTestValues().get(sourceType);
    if (instance == null) {
        // use an empty instance as input for the script
        instance = new DefaultInstance(sourceType.getDefinition(), DataSet.SOURCE);
    }
    FamilyInstance source = new FamilyInstanceImpl(instance);
    // prepare binding
    Cell cell = getWizard().getUnfinishedCell();
    CellLog log = new CellLog(new DefaultTransformationReporter("dummy", false), cell);
    ExecutionContext context = new DummyExecutionContext(HaleUI.getServiceProvider());
    Binding binding = GroovyRetype.createBinding(source, cell, builder, log, context, targetType.getDefinition().getDefinition());
    GroovyService service = HaleUI.getServiceProvider().getService(GroovyService.class);
    Script script = null;
    try {
        script = service.parseScript(document, binding);
        GroovyUtil.evaluateAll(script, builder, targetType.getDefinition().getDefinition(), service, log);
    } catch (final Exception e) {
        return handleValidationResult(script, e);
    }
    return handleValidationResult(script, null);
}
Also used : Binding(groovy.lang.Binding) Script(groovy.lang.Script) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) DefaultTransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) GroovyService(eu.esdihumboldt.util.groovy.sandbox.GroovyService) FamilyInstanceImpl(eu.esdihumboldt.hale.common.align.transformation.function.impl.FamilyInstanceImpl) Type(eu.esdihumboldt.hale.common.align.model.Type) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ExecutionContext(eu.esdihumboldt.hale.common.align.transformation.function.ExecutionContext) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) FamilyInstance(eu.esdihumboldt.hale.common.instance.model.FamilyInstance) Cell(eu.esdihumboldt.hale.common.align.model.Cell) CellLog(eu.esdihumboldt.hale.common.align.transformation.report.impl.CellLog) InstanceBuilder(eu.esdihumboldt.hale.common.instance.groovy.InstanceBuilder)

Example 5 with JoinParameter

use of eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter in project hale by halestudio.

the class GroovyJoinPage method addActions.

@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
    PageHelp.createToolItem(toolbar, this);
    // FIXME TypeStructureTray does not support FamilyInstances
    // XXX for now only use Join base type
    JoinTypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            ParameterValue param = CellUtil.getFirstParameter(getWizard().getUnfinishedCell(), JoinFunction.PARAMETER_JOIN);
            JoinParameter joinParameter = param.as(JoinParameter.class);
            if (joinParameter != null && joinParameter.getTypes() != null && !joinParameter.getTypes().isEmpty()) {
                return Collections.singleton(joinParameter.getTypes().get(0).getDefinition());
            }
            return Collections.emptyList();
        }
    });
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            Type targetType = (Type) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (targetType != null) {
                return Collections.singleton(targetType.getDefinition().getDefinition());
            }
            return Collections.emptyList();
        }
    });
    PageFunctions.createToolItem(toolbar, this);
}
Also used : Type(eu.esdihumboldt.hale.common.align.model.Type) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) TypeProvider(eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.TypeProvider) Collection(java.util.Collection) JoinParameter(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

JoinParameter (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter)16 JoinCondition (eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition)11 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)10 ArrayList (java.util.ArrayList)7 Cell (eu.esdihumboldt.hale.common.align.model.Cell)5 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)5 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)4 HashSet (java.util.HashSet)4 Type (eu.esdihumboldt.hale.common.align.model.Type)3 FamilyInstance (eu.esdihumboldt.hale.common.instance.model.FamilyInstance)3 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 List (java.util.List)3 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 ListMultimap (com.google.common.collect.ListMultimap)2 JoinDefinition (eu.esdihumboldt.cst.functions.core.join.JoinUtil.JoinDefinition)2 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)2 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)2 TransformationException (eu.esdihumboldt.hale.common.align.transformation.function.TransformationException)2 ComplexValue (eu.esdihumboldt.hale.common.core.io.impl.ComplexValue)2 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)2