Search in sources :

Example 11 with Cell

use of eu.esdihumboldt.hale.common.align.model.Cell 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 12 with Cell

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

the class GroovyTransformationPage method addActions.

@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
    super.addActions(toolbar, viewer);
    PageHelp.createToolItem(toolbar, this);
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            // create a dummy type with the variables as children
            DefaultTypeDefinition dummy = new DefaultTypeDefinition(TypeStructureTray.VARIABLES_TYPE_NAME);
            Cell cell = getWizard().getUnfinishedCell();
            boolean useInstanceValues = CellUtil.getOptionalParameter(cell, GroovyTransformation.PARAM_INSTANCE_VARIABLES, Value.of(false)).as(Boolean.class);
            for (EntityDefinition variable : getVariables()) {
                if (variable.getDefinition() instanceof PropertyDefinition) {
                    PropertyDefinition prop = (PropertyDefinition) variable.getDefinition();
                    TypeDefinition propertyType;
                    if (useInstanceValues) {
                        // use instance type
                        propertyType = prop.getPropertyType();
                    } else {
                        // use dummy type with only the
                        // binding/HasValueFlag copied
                        DefaultTypeDefinition crippledType = new DefaultTypeDefinition(prop.getPropertyType().getName());
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(Binding.class));
                        crippledType.setConstraint(prop.getPropertyType().getConstraint(HasValueFlag.class));
                        propertyType = crippledType;
                    }
                    DefaultPropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName(getVariableName(variable)), dummy, propertyType);
                    // number of times
                    if (cell.getTransformationIdentifier().equals(GroovyGreedyTransformation.ID))
                        dummyProp.setConstraint(Cardinality.CC_ANY_NUMBER);
                }
            }
            return Collections.singleton(dummy);
        }
    });
    TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {

        @Override
        public Collection<? extends TypeDefinition> getTypes() {
            Property targetProperty = (Property) CellUtil.getFirstEntity(getWizard().getUnfinishedCell().getTarget());
            if (targetProperty != null) {
                return Collections.singleton(targetProperty.getDefinition().getDefinition().getPropertyType());
            }
            return Collections.emptyList();
        }
    });
    PageFunctions.createToolItem(toolbar, this);
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) QName(javax.xml.namespace.QName) TypeProvider(eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.TypeProvider) Collection(java.util.Collection) Cell(eu.esdihumboldt.hale.common.align.model.Cell) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 13 with Cell

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

the class SequentialIDParameterPage method validateValue.

/**
 * Validates if the given value is valid for the target property.
 *
 * @param value the value to validate
 * @return if the value is valid
 */
protected boolean validateValue(String value) {
    Cell cell = getWizard().getUnfinishedCell();
    List<? extends Entity> targets = cell.getTarget().get(null);
    if (!targets.isEmpty()) {
        Entity entity = targets.get(0);
        Definition<?> def = entity.getDefinition().getDefinition();
        if (def instanceof PropertyDefinition) {
            TypeDefinition propertyType = ((PropertyDefinition) def).getPropertyType();
            Validator validator = propertyType.getConstraint(ValidationConstraint.class).getValidator();
            // TODO conversion to binding needed?
            String error = validator.validate(value);
            // update the example decoration
            if (error == null) {
                exampleDecoration.hide();
            } else {
                exampleDecoration.setDescriptionText(error);
                exampleDecoration.show();
            }
            return error == null;
        }
    }
    // no validation possible
    return true;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) ValidationConstraint(eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint) Cell(eu.esdihumboldt.hale.common.align.model.Cell) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Validator(eu.esdihumboldt.util.validator.Validator) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 14 with Cell

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

the class OMLReaderTest method testNetworkExpansion1.

/**
 * Test for network expansion function in alignment4
 */
@Test
public void testNetworkExpansion1() {
    Collection<? extends Cell> cells = alignment4.getCells();
    Iterator<? extends Cell> it = cells.iterator();
    Cell cell = null;
    while (it.hasNext()) {
        Cell temp = it.next();
        if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.cst.functions.geometric.networkexpansion")) {
            cell = temp;
            break;
        }
    }
    ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
    List<ParameterValue> values = params.get("bufferWidth");
    assertEquals(1, values.size());
    // size is always 1
    String temp = values.get(0).as(String.class);
    assertEquals("0.005", temp);
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Example 15 with Cell

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

the class OMLReaderTest method testDateExtraction.

/**
 * Test for date extraction function in alignment
 */
@Test
public void testDateExtraction() {
    Collection<? extends Cell> cells = alignment.getCells();
    Iterator<? extends Cell> it = cells.iterator();
    Cell cell = null;
    while (it.hasNext()) {
        Cell temp = it.next();
        if (temp.getTransformationIdentifier().equals("eu.esdihumboldt.cst.functions.string.dateextraction")) {
            cell = temp;
            break;
        }
    }
    ListMultimap<String, ParameterValue> params = cell.getTransformationParameters();
    List<ParameterValue> values = params.get("dateFormat");
    assertEquals(1, values.size());
    String date = values.get(0).as(String.class);
    assertEquals("yyyy-MM-dd HH:mm:ss", date);
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Aggregations

Cell (eu.esdihumboldt.hale.common.align.model.Cell)123 ArrayList (java.util.ArrayList)33 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)28 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)28 Test (org.junit.Test)27 Entity (eu.esdihumboldt.hale.common.align.model.Entity)24 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)24 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)18 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)16 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)16 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)15 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)13 HashSet (java.util.HashSet)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Type (eu.esdihumboldt.hale.common.align.model.Type)11 List (java.util.List)11 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)9 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)9 Property (eu.esdihumboldt.hale.common.align.model.Property)8