Search in sources :

Example 1 with DefaultProperty

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

the class AppSchemaMappingTest method createTargetProperty.

private ListMultimap<String, Property> createTargetProperty(TypeDefinition targetType, List<ChildDefinition<?>> childDefs, List<Integer> contextNames, List<Condition> conditions) {
    if (contextNames == null) {
        contextNames = Collections.emptyList();
    }
    if (conditions == null) {
        conditions = Collections.emptyList();
    }
    List<ChildContext> childContext = new ArrayList<ChildContext>();
    for (int i = 0; i < childDefs.size(); i++) {
        ChildDefinition<?> childDef = childDefs.get(i);
        Integer contextName = (contextNames.size() > i) ? contextNames.get(i) : null;
        Condition condition = (conditions.size() > 1) ? conditions.get(i) : null;
        childContext.add(new ChildContext(contextName, null, condition, childDef));
    }
    ListMultimap<String, Property> target = ArrayListMultimap.create();
    target.put(null, new DefaultProperty(new PropertyEntityDefinition(targetType, childContext, SchemaSpaceID.TARGET, null)));
    return target;
}
Also used : Condition(eu.esdihumboldt.hale.common.align.model.Condition) JoinCondition(eu.esdihumboldt.hale.common.align.model.functions.join.JoinParameter.JoinCondition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) 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) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 2 with DefaultProperty

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

the class AppSchemaMappingTest method createSourceProperty.

private ListMultimap<String, Property> createSourceProperty(TypeDefinition sourceType, ChildDefinition<?> childDef) {
    List<ChildContext> childContext = new ArrayList<ChildContext>();
    childContext.add(new ChildContext(childDef));
    ListMultimap<String, Property> source = ArrayListMultimap.create();
    source.put(null, new DefaultProperty(new PropertyEntityDefinition(sourceType, childContext, SchemaSpaceID.SOURCE, null)));
    return source;
}
Also used : PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ArrayList(java.util.ArrayList) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) 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) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 3 with DefaultProperty

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

the class CityGMLXsltExport method writeContainerIntro.

@Override
protected void writeContainerIntro(XMLStreamWriter writer, XsltGenerationContext context) throws XMLStreamException, IOException {
    if (targetCityModel != null && sourceCityModel != null) {
        // copy GML boundedBy
        // do it in a special template
        String template = context.reserveTemplateName("copyBoundedBy");
        writer.writeStartElement(NS_URI_XSL, "call-template");
        writer.writeAttribute("name", template);
        writer.writeEndElement();
        // find source property
        PropertyDefinition sourceBB = null;
        for (ChildDefinition<?> child : sourceCityModel.getType().getChildren()) {
            if (child.asProperty() != null && child.getName().getLocalPart().equals("boundedBy") && child.getName().getNamespaceURI().startsWith(GML_NAMESPACE_CORE)) {
                sourceBB = child.asProperty();
                break;
            }
        }
        // find target property
        PropertyDefinition targetBB = null;
        for (ChildDefinition<?> child : targetCityModel.getType().getChildren()) {
            if (child.asProperty() != null && child.getName().getLocalPart().equals("boundedBy") && child.getName().getNamespaceURI().startsWith(GML_NAMESPACE_CORE)) {
                targetBB = child.asProperty();
                break;
            }
        }
        if (sourceBB != null && targetBB != null) {
            // create templated
            OutputStreamWriter out = new OutputStreamWriter(context.addInclude().openBufferedStream(), getCharset());
            try {
                out.write("<xsl:template name=\"" + template + "\">");
                StringBuilder selectSource = new StringBuilder();
                selectSource.append('/');
                selectSource.append(GroovyXslHelpers.asPrefixedName(sourceCityModel.getName(), context));
                selectSource.append('/');
                selectSource.append(GroovyXslHelpers.asPrefixedName(sourceBB.getName(), context));
                selectSource.append("[1]");
                out.write("<xsl:for-each select=\"" + selectSource.toString() + "\">");
                String elementName = GroovyXslHelpers.asPrefixedName(targetBB.getName(), context);
                out.write("<" + elementName + ">");
                // create bogus rename cell
                DefaultCell cell = new DefaultCell();
                // source
                ListMultimap<String, Entity> source = ArrayListMultimap.create();
                List<ChildContext> sourcePath = new ArrayList<ChildContext>();
                sourcePath.add(new ChildContext(sourceBB));
                PropertyEntityDefinition sourceDef = new PropertyEntityDefinition(sourceCityModel.getType(), sourcePath, SchemaSpaceID.SOURCE, null);
                source.put(null, new DefaultProperty(sourceDef));
                cell.setSource(source);
                // target
                ListMultimap<String, Entity> target = ArrayListMultimap.create();
                List<ChildContext> targetPath = new ArrayList<ChildContext>();
                targetPath.add(new ChildContext(targetBB));
                PropertyEntityDefinition targetDef = new PropertyEntityDefinition(targetCityModel.getType(), targetPath, SchemaSpaceID.TARGET, null);
                target.put(null, new DefaultProperty(targetDef));
                cell.setTarget(target);
                // parameters
                ListMultimap<String, ParameterValue> parameters = ArrayListMultimap.create();
                parameters.put(RenameFunction.PARAMETER_STRUCTURAL_RENAME, new ParameterValue("true"));
                parameters.put(RenameFunction.PARAMETER_IGNORE_NAMESPACES, new ParameterValue("true"));
                cell.setTransformationParameters(parameters);
                // variables
                ListMultimap<String, XslVariable> variables = ArrayListMultimap.create();
                variables.put(null, new XslVariableImpl(sourceDef, "."));
                try {
                    out.write(context.getPropertyTransformation(RenameFunction.ID).selectFunction(cell).getSequence(cell, variables, context, null));
                } catch (TransformationException e) {
                    throw new IllegalStateException("Failed to create template for boundedBy copy.", e);
                }
                out.write("</" + elementName + ">");
                out.write("</xsl:for-each>");
                out.write("</xsl:template>");
            } finally {
                out.close();
            }
        }
    }
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) TransformationException(eu.esdihumboldt.hale.common.align.transformation.function.TransformationException) ParameterValue(eu.esdihumboldt.hale.common.align.model.ParameterValue) ArrayList(java.util.ArrayList) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) XslVariableImpl(eu.esdihumboldt.hale.io.xslt.functions.impl.XslVariableImpl) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) XslVariable(eu.esdihumboldt.hale.io.xslt.functions.XslVariable) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) OutputStreamWriter(java.io.OutputStreamWriter)

Example 4 with DefaultProperty

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty 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)

Example 5 with DefaultProperty

use of eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty 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

DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)15 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)12 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)9 ArrayList (java.util.ArrayList)8 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)7 Entity (eu.esdihumboldt.hale.common.align.model.Entity)7 Property (eu.esdihumboldt.hale.common.align.model.Property)7 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)6 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)6 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)5 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)4 Cell (eu.esdihumboldt.hale.common.align.model.Cell)3 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)3 Type (eu.esdihumboldt.hale.common.align.model.Type)3 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)3 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)2 ModifiableCell (eu.esdihumboldt.hale.common.align.model.ModifiableCell)2 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)2 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)2 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)2