Search in sources :

Example 16 with Entity

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

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

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

the class DefaultsVisitor method addAugmentationCell.

/**
 * Add a simple cell using an augmentation w/o parameters.
 *
 * @param ped the property entity definition
 * @param functionId the function identifier
 * @param priority the cell priority
 */
private void addAugmentationCell(PropertyEntityDefinition ped, String functionId, Priority priority) {
    // create cell template
    MutableCell cell = new DefaultCell();
    cell.setPriority(priority);
    ListMultimap<String, Entity> target = ArrayListMultimap.create();
    cell.setTarget(target);
    // set transformation identifier (Function ID)
    cell.setTransformationIdentifier(functionId);
    // set cell target (Property)
    target.put(null, new DefaultProperty(ped));
    BGISAppUtil.appendNote(cell, "Generated default mapping.");
    cells.add(cell);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) MutableCell(eu.esdihumboldt.hale.common.align.model.MutableCell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Example 19 with Entity

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

Example 20 with Entity

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

Aggregations

Entity (eu.esdihumboldt.hale.common.align.model.Entity)64 Cell (eu.esdihumboldt.hale.common.align.model.Cell)25 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)21 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)14 ArrayList (java.util.ArrayList)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)9 ParameterValue (eu.esdihumboldt.hale.common.align.model.ParameterValue)9 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)9 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)9 List (java.util.List)9 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)8 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)7 ChildContext (eu.esdihumboldt.hale.common.align.model.ChildContext)6 HashSet (java.util.HashSet)6 Locale (java.util.Locale)6 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)5 FunctionDefinition (eu.esdihumboldt.hale.common.align.extension.function.FunctionDefinition)4 CellUtil (eu.esdihumboldt.hale.common.align.model.CellUtil)4 CellLog (eu.esdihumboldt.hale.common.align.model.annotations.messages.CellLog)4 AbstractCellExplanation (eu.esdihumboldt.hale.common.align.model.impl.AbstractCellExplanation)4