Search in sources :

Example 11 with Property

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

the class DateExtractionHandler method getSourceExpressionAsCQL.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 */
@Override
protected String getSourceExpressionAsCQL() {
    Property source = AppSchemaMappingUtils.getSourceProperty(propertyCell);
    String dateFormat = propertyCell.getTransformationParameters().get(PARAMETER_DATE_FORMAT).get(0).getStringRepresentation();
    String dateStrProperty = source.getDefinition().getDefinition().getName().getLocalPart();
    String cqlExpression = String.format("dateParse(%s, '%s')", dateStrProperty, dateFormat);
    return getConditionalExpression(source.getDefinition(), cqlExpression);
}
Also used : Property(eu.esdihumboldt.hale.common.align.model.Property)

Example 12 with Property

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

the class ExtentHandler method getSourceExpressionAsCQL.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 */
@Override
protected String getSourceExpressionAsCQL() {
    Property source = getSourceProperty(propertyCell);
    ParameterValue extentTypeParam = getTransformationParameter(propertyCell, ExtentFunction.PARAM_TYPE);
    String extentType = (extentTypeParam != null) ? extentTypeParam.as(String.class, ExtentFunction.PARAM_BOUNDING_BOX) : ExtentFunction.PARAM_BOUNDING_BOX;
    String extentFunction = "";
    if (extentType.equals(ExtentFunction.PARAM_BOUNDING_BOX)) {
        extentFunction = "envelope";
    } else if (extentType.equals(ExtentFunction.PARAM_CONVEX_HULL)) {
        extentFunction = "convexHull";
    } else {
        throw new IllegalArgumentException("Extent type not supported: " + extentType);
    }
    String geomProperty = source.getDefinition().getDefinition().getName().getLocalPart();
    String cqlExpression = String.format("%s(%s)", extentFunction, geomProperty);
    return getConditionalExpression(source.getDefinition(), cqlExpression);
}
Also used : ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) Property(eu.esdihumboldt.hale.common.align.model.Property) AppSchemaMappingUtils.getSourceProperty(eu.esdihumboldt.hale.io.appschema.writer.AppSchemaMappingUtils.getSourceProperty)

Example 13 with Property

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

the class CityGMLPropagateVisitor method propagateCell.

/**
 * Propagate a given cell to the given target property and possible source
 * types.
 *
 * @param exampleCell the example cell
 * @param ped the target property
 */
private void propagateCell(Cell exampleCell, PropertyEntityDefinition ped) {
    /*
		 * Find the type where the property actually is defined, as if possible
		 * a super type mapping should be used.
		 */
    TypeDefinition targetType = findTypeDefining(ped);
    if (!targetType.equals(ped.getType())) {
        ped = new PropertyEntityDefinition(targetType, ped.getPropertyPath(), ped.getSchemaSpace(), ped.getFilter());
    }
    // check if the cell was already handled for the type
    if (handledTargets.get(exampleCell).contains(targetType)) {
        // don't produce any duplicates
        return;
    }
    handledTargets.put(exampleCell, targetType);
    TypeEntityIndex<List<ChildContext>> index = new TypeEntityIndex<List<ChildContext>>();
    Collection<TypeDefinition> sourceTypes = findSourceTypes(exampleCell, targetType, index);
    if (sourceTypes != null) {
        for (TypeDefinition sourceType : sourceTypes) {
            // 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);
            // assign new source(s)
            ListMultimap<String, Entity> source = ArrayListMultimap.create();
            for (Entry<String, ? extends Entity> entry : cell.getSource().entries()) {
                // create new source entity
                List<ChildContext> path = index.get(sourceType, entry.getValue());
                if (path == null) {
                    throw new IllegalStateException("No replacement property path computed");
                }
                Property newSource = new DefaultProperty(new PropertyEntityDefinition(sourceType, path, SchemaSpaceID.SOURCE, null));
                source.put(entry.getKey(), newSource);
            }
            cell.setSource(source);
            BGISAppUtil.appendNote(cell, cellNote);
            cells.add(cell);
        }
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TypeEntityIndex(eu.esdihumboldt.hale.app.bgis.ade.propagate.internal.TypeEntityIndex) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 14 with Property

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

the class RenameHandler method getSourceExpressionAsCQL.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.AbstractPropertyTransformationHandler#getSourceExpressionAsCQL()
 */
@Override
protected String getSourceExpressionAsCQL() {
    Property source = AppSchemaMappingUtils.getSourceProperty(propertyCell);
    String cqlExpression = source.getDefinition().getDefinition().getName().getLocalPart();
    return getConditionalExpression(source.getDefinition(), cqlExpression);
}
Also used : Property(eu.esdihumboldt.hale.common.align.model.Property)

Example 15 with Property

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

the class DefaultAlignmentIOTest method testBaseAlignmentSaveLoad.

/**
 * Tests base alignment add, save and load.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testBaseAlignmentSaveLoad() throws Exception {
    DefaultAlignment baseAlignment = new DefaultAlignment();
    MutableAlignment alignment = new DefaultAlignment();
    Schema schema = TestUtil.loadSchema(getClass().getResource("/testdata/simple/t1.xsd").toURI());
    Iterator<? extends TypeDefinition> iter = schema.getMappingRelevantTypes().iterator();
    TypeDefinition t = iter.next();
    if (!t.getName().getLocalPart().equals("T1")) {
        t = iter.next();
    }
    DefaultCell cell1 = new DefaultCell();
    cell1.setTransformationIdentifier("trans1");
    ListMultimap<String, Type> source = ArrayListMultimap.create();
    source.put(null, new DefaultType(new TypeEntityDefinition(t, SchemaSpaceID.SOURCE, null)));
    cell1.setSource(source);
    ListMultimap<String, Type> target = ArrayListMultimap.create();
    target.put(null, new DefaultType(new TypeEntityDefinition(t, SchemaSpaceID.TARGET, null)));
    cell1.setTarget(target);
    DefaultCell cell2 = new DefaultCell();
    cell2.setTransformationIdentifier("trans2");
    List<ChildContext> childContext = new ArrayList<ChildContext>();
    PropertyDefinition child = DefinitionUtil.getChild(t, new QName("a1")).asProperty();
    childContext.add(new ChildContext(child));
    ListMultimap<String, Property> source2 = ArrayListMultimap.create();
    source2.put(null, new DefaultProperty(new PropertyEntityDefinition(t, childContext, SchemaSpaceID.SOURCE, null)));
    cell2.setSource(source2);
    ListMultimap<String, Property> target2 = ArrayListMultimap.create();
    target2.put(null, new DefaultProperty(new PropertyEntityDefinition(t, childContext, SchemaSpaceID.TARGET, null)));
    cell2.setTarget(target2);
    // add cell1 to base alignment
    baseAlignment.addCell(cell1);
    // save base alignment
    File baseAlignmentFile = tmp.newFile("alignment_base.xml");
    System.out.println(baseAlignmentFile.getAbsolutePath());
    saveAlignment(baseAlignment, new BufferedOutputStream(new FileOutputStream(baseAlignmentFile)));
    // add as base alignment to extended alignment
    addBaseAlignment(alignment, baseAlignmentFile.toURI(), schema, schema);
    assertEquals(1, alignment.getBaseAlignments().size());
    String usedPrefix = alignment.getBaseAlignments().keySet().iterator().next();
    assertEquals(1, alignment.getCells().size());
    assertEquals(usedPrefix + ":" + cell1.getId(), alignment.getCells().iterator().next().getId());
    // add cell2 to extended alignment
    alignment.addCell(cell2);
    assertEquals(2, alignment.getCells().size());
    assertEquals(1, alignment.getPropertyCells(cell1).size());
    // save extended alignment
    File alignmentFile = tmp.newFile("alignment_extended.xml");
    System.out.println(alignmentFile.getAbsolutePath());
    saveAlignment(alignment, new BufferedOutputStream(new FileOutputStream(alignmentFile)));
    // load extended
    MutableAlignment alignment2 = loadAlignment(new FileInputStream(alignmentFile), schema, schema);
    assertEquals(2, alignment2.getCells().size());
    assertEquals(1, alignment2.getTypeCells().size());
    Cell typeCell = alignment2.getTypeCells().iterator().next();
    assertTrue(typeCell instanceof BaseAlignmentCell);
    assertEquals(usedPrefix + ":" + cell1.getId(), typeCell.getId());
    assertEquals(1, alignment2.getPropertyCells(typeCell).size());
    assertFalse(alignment2.getPropertyCells(typeCell).iterator().next() instanceof BaseAlignmentCell);
}
Also used : Schema(eu.esdihumboldt.hale.common.schema.model.Schema) DefaultSchema(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema) ArrayList(java.util.ArrayList) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) BufferedOutputStream(java.io.BufferedOutputStream) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell) ModifiableCell(eu.esdihumboldt.hale.common.align.model.ModifiableCell) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) QName(javax.xml.namespace.QName) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) FileInputStream(java.io.FileInputStream) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test)

Aggregations

Property (eu.esdihumboldt.hale.common.align.model.Property)25 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)13 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)11 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)9 ArrayList (java.util.ArrayList)9 Cell (eu.esdihumboldt.hale.common.align.model.Cell)8 ClientProperty (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType.ClientProperty)8 Test (org.junit.Test)8 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)7 AttributeMappingType (eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.AttributeMappingType)7 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)6 AppSchemaMappingContext (eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)6 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)5 Type (eu.esdihumboldt.hale.common.align.model.Type)5 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)5 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)3 FormattedStringHandler (eu.esdihumboldt.hale.io.appschema.writer.internal.FormattedStringHandler)3 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2