Search in sources :

Example 46 with Cell

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

the class AppSchemaMappingTest method testNilReasonOnNotNillableElement.

@Test
public void testNilReasonOnNotNillableElement() {
    final String nilReason = "missing";
    final String nilReasonAssignCQL = "'" + nilReason + "'";
    final String nilReasonRenameCQL = SOURCE_UUID_V1;
    // --- test with a constant mapping --- //
    DefaultCell assignNilReason = new DefaultCell();
    assignNilReason.setTransformationIdentifier(AssignFunction.ID);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(nilReason));
    assignNilReason.setTarget(getDescriptionNilReasonTargetProperty());
    assignNilReason.setTransformationParameters(parameters);
    Cell typeCell = getDefaultTypeCell(unitType, landCoverUnitType);
    AttributeMappingType attrMapping = null;
    AppSchemaMappingContext context = new AppSchemaMappingContext(mappingWrapper);
    AssignHandler assignHandler = new AssignHandler();
    attrMapping = assignHandler.handlePropertyTransformation(typeCell, assignNilReason, context);
    assertNotNull(attrMapping);
    assertEquals("gml:description", attrMapping.getTargetAttribute());
    assertNull(attrMapping.getSourceExpression());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
    assertEquals(nilReasonAssignCQL, attrMapping.getClientProperty().get(0).getValue());
    // encodeIfEmpty=true because we are using a constant mapping
    assertTrue(attrMapping.isEncodeIfEmpty());
    // --- test with a non-constant mapping --- //
    DefaultCell rename = new DefaultCell();
    rename.setTransformationIdentifier(RenameFunction.ID);
    rename.setSource(getUuidSourceProperty(unitType));
    rename.setTarget(getDescriptionNilReasonTargetProperty());
    // reset mapping
    initMapping();
    context = new AppSchemaMappingContext(mappingWrapper);
    // process rename
    RenameHandler renameHandler = new RenameHandler();
    attrMapping = renameHandler.handlePropertyTransformation(typeCell, rename, context);
    assertNotNull(attrMapping);
    assertEquals("gml:description", attrMapping.getTargetAttribute());
    assertNull(attrMapping.getSourceExpression());
    assertEquals(1, attrMapping.getClientProperty().size());
    assertEquals(GML_NIL_REASON, attrMapping.getClientProperty().get(0).getName());
    assertEquals(nilReasonRenameCQL, attrMapping.getClientProperty().get(0).getValue());
    // encodeIfEmpty has not been set, because we are using a mapping which
    // is a function of the source value
    assertNull(attrMapping.isEncodeIfEmpty());
}
Also used : AssignHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) RenameHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.RenameHandler) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Test(org.junit.Test)

Example 47 with Cell

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

the class AppSchemaMappingTest method testAssignHandler.

@Test
public void testAssignHandler() {
    final String ASSIGN_VALUE = "LCU_1234";
    final String OCQL = "'" + ASSIGN_VALUE + "'";
    final String OCQL_BOUND = "if_then_else(isNull(" + SOURCE_UUID_V1 + "), Expression.NIL, '" + ASSIGN_VALUE + "')";
    Cell typeCell = getDefaultTypeCell(unitDenormType, landCoverUnitType);
    DefaultCell cell = new DefaultCell();
    cell.setTransformationIdentifier(AssignFunction.ID);
    ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
    parameters.put(AssignFunction.PARAMETER_VALUE, new ParameterValue(ASSIGN_VALUE));
    cell.setTarget(getLocalIdTargetProperty());
    cell.setTransformationParameters(parameters);
    AssignHandler assignHandler = new AssignHandler();
    AttributeMappingType attrMapping = assignHandler.handlePropertyTransformation(typeCell, cell, new AppSchemaMappingContext(mappingWrapper));
    assertEquals(OCQL, attrMapping.getSourceExpression().getOCQL());
    assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
    // bound version of "Assign"
    DefaultCell cellCopy = new DefaultCell(cell);
    Collection<Property> anchor = getUuidSourceProperty(unitDenormType).values();
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.putAll(AssignFunction.ENTITY_ANCHOR, anchor);
    cellCopy.setSource(source);
    cellCopy.setTransformationIdentifier(AssignFunction.ID_BOUND);
    attrMapping = assignHandler.handlePropertyTransformation(typeCell, cellCopy, new AppSchemaMappingContext(mappingWrapper));
    assertEquals(OCQL_BOUND, attrMapping.getSourceExpression().getOCQL());
    assertEquals(TARGET_LOCAL_ID, attrMapping.getTargetAttribute());
}
Also used : AssignHandler(eu.esdihumboldt.hale.io.appschema.writer.internal.AssignHandler) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) AttributeMappingType(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) AppSchemaMappingContext(eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Property(eu.esdihumboldt.hale.common.align.model.Property) ClientProperty(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) Test(org.junit.Test)

Example 48 with Cell

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

the class AppSchemaMappingGenerator method createNamespaces.

private void createNamespaces() {
    Collection<? extends Cell> typeCells = alignment.getTypeCells();
    for (Cell typeCell : typeCells) {
        ListMultimap<String, ? extends Entity> targetEntities = typeCell.getTarget();
        if (targetEntities != null) {
            for (Entity entity : targetEntities.values()) {
                createNamespaceForEntity(entity);
            }
        }
        Collection<? extends Cell> propertyCells = alignment.getPropertyCells(typeCell);
        for (Cell propCell : propertyCells) {
            Collection<? extends Entity> targetProperties = propCell.getTarget().values();
            if (targetProperties != null) {
                for (Entity property : targetProperties) {
                    createNamespaceForEntity(property);
                }
            }
        }
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 49 with Cell

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

the class ConceptualSchemaTransformer method transform.

/**
 * @see TransformationService#transform(Alignment, InstanceCollection,
 *      InstanceSink, ServiceProvider, ProgressIndicator)
 */
@Override
public TransformationReport transform(Alignment alignment, InstanceCollection source, InstanceSink target, ServiceProvider serviceProvider, ProgressIndicator progressIndicator) {
    TransformationReporter reporter = new DefaultTransformationReporter("Instance transformation", true);
    TransformationContext context = new TransformationContext(serviceProvider, alignment);
    TransformationFunctionService functions = serviceProvider.getService(TransformationFunctionService.class);
    final SubtaskProgressIndicator sub = new SubtaskProgressIndicator(progressIndicator) {

        @Override
        protected String getCombinedTaskName(String taskName, String subtaskName) {
            return taskName + " (" + subtaskName + ")";
        }
    };
    progressIndicator = sub;
    target = new CountingInstanceSink(target) {

        private long lastUpdate = 0;

        @Override
        protected void countChanged(int count) {
            long now = System.currentTimeMillis();
            if (now - lastUpdate > 100) {
                // only update every 100
                // milliseconds
                lastUpdate = now;
                sub.subTask(count + " transformed instances");
            }
        }
    };
    progressIndicator.begin("Transformation", ProgressIndicator.UNKNOWN);
    try {
        EngineManager engines = new EngineManager();
        PropertyTransformer transformer = new TreePropertyTransformer(alignment, reporter, target, engines, context);
        Collection<? extends Cell> typeCells = alignment.getActiveTypeCells();
        // sort type cell by priority
        typeCells = sortTypeCells(typeCells);
        for (Cell typeCell : typeCells) {
            if (progressIndicator.isCanceled()) {
                break;
            }
            List<TypeTransformationFactory> transformations = functions.getTypeTransformations(typeCell.getTransformationIdentifier());
            if (transformations == null || transformations.isEmpty()) {
                reporter.error(new TransformationMessageImpl(typeCell, MessageFormat.format("No transformation for function {0} found. Skipped type transformation.", typeCell.getTransformationIdentifier()), null));
            } else {
                // TODO select based on e.g. preferred transformation
                // engine?
                TypeTransformationFactory transformation = transformations.iterator().next();
                doTypeTransformation(transformation, typeCell, source, target, alignment, engines, transformer, context, reporter, progressIndicator);
            }
        }
        progressIndicator.setCurrentTask("Wait for property transformer to complete");
        // wait for the property transformer to complete
        // cancel property transformations if process was canceled - this
        // may leave transformed instances in inconsistent state
        transformer.join(progressIndicator.isCanceled());
        engines.dispose();
        reporter.setSuccess(true);
        return reporter;
    } finally {
        progressIndicator.end();
    }
}
Also used : EngineManager(eu.esdihumboldt.cst.internal.EngineManager) DefaultTransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter) TransformationFunctionService(eu.esdihumboldt.hale.common.align.service.TransformationFunctionService) CountingInstanceSink(eu.esdihumboldt.cst.internal.util.CountingInstanceSink) SubtaskProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.SubtaskProgressIndicator) TransformationContext(eu.esdihumboldt.cst.internal.TransformationContext) TypeTransformationFactory(eu.esdihumboldt.hale.common.align.extension.transformation.TypeTransformationFactory) TransformationMessageImpl(eu.esdihumboldt.hale.common.align.transformation.report.impl.TransformationMessageImpl) TransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.TransformationReporter) DefaultTransformationReporter(eu.esdihumboldt.hale.common.align.transformation.report.impl.DefaultTransformationReporter) PropertyTransformer(eu.esdihumboldt.hale.common.align.transformation.service.PropertyTransformer) TreePropertyTransformer(eu.esdihumboldt.cst.internal.TreePropertyTransformer) Cell(eu.esdihumboldt.hale.common.align.model.Cell) TreePropertyTransformer(eu.esdihumboldt.cst.internal.TreePropertyTransformer)

Example 50 with Cell

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

the class DuplicateVisitor method visit.

@Override
protected boolean visit(PropertyEntityDefinition ped) {
    if (ADE_NS.equals(ped.getDefinition().getName().getNamespaceURI())) {
        for (Cell exampleCell : exampleCells.get(ped.getDefinition().getName().getLocalPart())) {
            // handle each example cell
            // copy cell
            DefaultCell cell = new DefaultCell(exampleCell);
            // reset ID
            cell.setId(null);
            // assign new target
            ListMultimap<String, Entity> target = ArrayListMultimap.create();
            target.put(cell.getTarget().keys().iterator().next(), new DefaultProperty(ped));
            cell.setTarget(target);
            BGISAppUtil.appendNote(cell, cellNote);
            cells.add(cell);
        }
        return true;
    }
    return false;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

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