Search in sources :

Example 41 with Entity

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

the class DataCaptureSpecUtil method getDataCaptureSpec.

/**
 * Extract the data capture specification from a type cell.
 *
 * @param typeCell the type cell
 * @return the data capture specification or <code>null</code>
 */
public static String getDataCaptureSpec(Cell typeCell) {
    ListMultimap<String, ? extends Entity> source = typeCell.getSource();
    if (source != null && !source.isEmpty()) {
        for (Entity entity : source.values()) {
            Definition<?> def = entity.getDefinition().getDefinition();
            if (def instanceof TypeDefinition) {
                String ns = def.getName().getNamespaceURI();
                if (ns != null && ns.startsWith(CityGMLConstants.CITYGML_NAMESPACE_CORE)) {
                    // extract version from namespace
                    Pattern pattern = Pattern.compile("[^/]*/([1-9][^/]*)");
                    Matcher matcher = pattern.matcher(ns);
                    if (matcher.find()) {
                        return "CityGML " + ns.substring(matcher.start(1), matcher.end(1));
                    }
                }
            }
        }
    }
    return null;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 42 with Entity

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

the class SourceDescriptionUtil method getSourceDescription.

/**
 * Derive a source description from a type cell.
 *
 * @param typeCell the type cell
 * @return the source description or <code>null</code>
 */
public static String getSourceDescription(Cell typeCell) {
    ListMultimap<String, ? extends Entity> source = typeCell.getSource();
    if (source != null && !source.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        builder.append('[');
        boolean first = true;
        for (Entity entity : source.values()) {
            if (first)
                first = false;
            else
                builder.append(", ");
            builder.append(entity.getDefinition().getDefinition().getDisplayName());
        }
        builder.append(']');
        return builder.toString();
    }
    return null;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity)

Example 43 with Entity

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

the class SingleSourceToTargetHandler method handleTypeTransformation.

/**
 * @see eu.esdihumboldt.hale.io.appschema.writer.internal.TypeTransformationHandler#handleTypeTransformation(eu.esdihumboldt.hale.common.align.model.Cell,
 *      eu.esdihumboldt.hale.io.appschema.writer.internal.mapping.AppSchemaMappingContext)
 */
@Override
public FeatureTypeMapping handleTypeTransformation(Cell typeCell, AppSchemaMappingContext context) {
    ListMultimap<String, ? extends Entity> sourceEntities = typeCell.getSource();
    if (sourceEntities == null || sourceEntities.size() == 0) {
        throw new IllegalStateException("No source type has been specified.");
    }
    ListMultimap<String, ? extends Entity> targetEntities = typeCell.getTarget();
    if (targetEntities == null || targetEntities.size() == 0) {
        throw new IllegalStateException("No target type has been specified.");
    }
    // Maps 1 source to 1 target, so it is safe to pick the first entity in
    // the list
    Entity sourceType = sourceEntities.values().iterator().next();
    Entity targetType = targetEntities.values().iterator().next();
    TypeDefinition targetTypeDef = targetType.getDefinition().getType();
    FeatureTypeMapping ftMapping = context.getOrCreateFeatureTypeMapping(targetTypeDef);
    ftMapping.setSourceType(sourceType.getDefinition().getType().getName().getLocalPart());
    return ftMapping;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) FeatureTypeMapping(eu.esdihumboldt.hale.io.appschema.impl.internal.generated.app_schema.TypeMappingsPropertyType.FeatureTypeMapping) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 44 with Entity

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

the class AbstractAlignmentMappingExport method addCellData.

// get the information of the cell and add them to the map
private void addCellData(Cell cell) {
    Map<CellType, CellInformation> cellInfos = new HashMap<CellType, CellInformation>();
    // create all entries
    List<CellType> cellTypes = getCellTypes();
    for (int i = 0; i < cellTypes.size(); i++) {
        cellInfos.put(cellTypes.get(i), new CellInformation());
    }
    cellInfos.get(CellType.ID).addText(cell.getId(), 0);
    if (cell.getSource() != null) {
        // save the hierarchy of the properties
        // all entries (in the same CellInfo) with the same hierarchy level
        // have to be shown on the same height
        int position = 0;
        for (Entity entity : cell.getSource().values()) {
            // column source type
            cellInfos.get(CellType.SOURCE_TYPE).addText(entity.getDefinition().getType().getName().getLocalPart(), position);
            if (includeNamespaces)
                // column source type namespace
                cellInfos.get(CellType.SOURCE_TYPE_NAMESPACE).addText(entity.getDefinition().getType().getName().getNamespaceURI(), position);
            // column source type conditions
            Filter entityFilter;
            if ((entityFilter = entity.getDefinition().getFilter()) != null) {
                cellInfos.get(CellType.SOURCE_TYPE_CONDITIONS).addText(FilterDefinitionManager.getInstance().asString(entityFilter), position);
                entity.getDefinition().getType().getName().getLocalPart();
            }
            for (ChildContext childContext : entity.getDefinition().getPropertyPath()) {
                PropertyDefinition child = childContext.getChild().asProperty();
                if (child != null) {
                    // column source properties
                    cellInfos.get(CellType.SOURCE_PROPERTIES).addText(child.getName().getLocalPart(), position);
                    if (includeNamespaces)
                        // column source properties namespace
                        cellInfos.get(CellType.SOURCE_PROPERTIES_NAMESPACE).addText(child.getName().getNamespaceURI(), position);
                    Filter contextFilter;
                    if (childContext.getCondition() != null) {
                        contextFilter = childContext.getCondition().getFilter();
                        // column source property conditions
                        cellInfos.get(CellType.SOURCE_PROPERTY_CONDITIONS).addText(FilterDefinitionManager.getInstance().asString(contextFilter), position);
                    }
                    // add dummy to adapt position of source type and source
                    // type conditions
                    cellInfos.get(CellType.SOURCE_TYPE).addText("", position);
                    cellInfos.get(CellType.SOURCE_TYPE_CONDITIONS).addText("", position);
                    position++;
                }
            }
            // next entries must have higher position
            position++;
        }
    }
    if (cell.getTarget() != null) {
        int position = 0;
        for (Entity entity : cell.getTarget().values()) {
            // column target type
            cellInfos.get(CellType.TARGET_TYPE).addText(entity.getDefinition().getType().getDisplayName(), position);
            if (includeNamespaces)
                // column target type namespace
                cellInfos.get(CellType.TARGET_TYPE_NAMESPACE).addText(entity.getDefinition().getType().getName().getNamespaceURI(), position);
            for (ChildContext childContext : entity.getDefinition().getPropertyPath()) {
                PropertyDefinition child = childContext.getChild().asProperty();
                if (child != null) {
                    // column target properties
                    cellInfos.get(CellType.TARGET_PROPERTIES).addText(child.getName().getLocalPart(), position);
                    if (includeNamespaces)
                        // column target properties namespace
                        cellInfos.get(CellType.TARGET_PROPERTIES_NAMESPACE).addText(child.getName().getNamespaceURI(), position);
                    // add dummy to adapt position of target type
                    cellInfos.get(CellType.TARGET_TYPE).addText("", position);
                    position++;
                }
            }
            position++;
        }
    }
    FunctionDefinition<?> function = FunctionUtil.getFunction(cell.getTransformationIdentifier(), getServiceProvider());
    if (function != null) {
        // column relation name
        cellInfos.get(CellType.RELATION_NAME).addText(function.getDisplayName(), 0);
        // column cell explanation
        CellExplanation cellExpl = function.getExplanation();
        if (cellExpl != null) {
            cellInfos.get(CellType.CELL_EXPLANATION).addText(function.getExplanation().getExplanation(cell, null), 0);
        }
    }
    // column cell notes
    List<String> docs = cell.getDocumentation().get(null);
    if (!docs.isEmpty()) {
        String notes = docs.get(0);
        if (notes != null && !notes.isEmpty()) {
            cellInfos.get(CellType.CELL_NOTES).addText(notes, 0);
        }
    }
    // cell priority
    cellInfos.get(CellType.PRIORITY).addText(cell.getPriority().value(), 0);
    // base cell
    if (cell.isBaseCell()) {
        cellInfos.get(CellType.BASE_CELL).addText("yes", 0);
    } else {
        cellInfos.get(CellType.BASE_CELL).addText("no", 0);
    }
    // column transformation/disabled
    if (transformationAndDisabledMode) {
        if (AlignmentUtil.isTypeCell(cell)) {
            currentTypeCell = cell;
            cellInfos.get(CellType.TRANSFORMATION_AND_DISABLED).addText(cell.getTransformationMode().displayName(), 0);
        } else {
            Set<String> disabledCells = cell.getDisabledFor();
            if (disabledCells.contains(currentTypeCell.getId())) {
                for (String disCell : disabledCells) {
                    cellInfos.get(CellType.TRANSFORMATION_AND_DISABLED).addText(disCell, 0);
                }
            }
        }
    }
    // add the row to the map
    allRelations.add(cellInfos);
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) HashMap(java.util.HashMap) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) CellExplanation(eu.esdihumboldt.hale.common.align.model.CellExplanation) Filter(eu.esdihumboldt.hale.common.instance.model.Filter) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext)

Example 45 with Entity

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

the class XsltGenerator method write.

/**
 * Generate the XSLT transformation and write it to the given target.
 *
 * @param target the target output supplier
 * @return the report
 * @throws Exception if a unrecoverable error occurs during the process
 */
public IOReport write(LocatableOutputSupplier<? extends OutputStream> target) throws Exception {
    Template root = ve.getTemplate(Templates.ROOT, "UTF-8");
    VelocityContext context = XslTransformationUtil.createStrictVelocityContext();
    // project info
    context.put("info", ProjectXslInfo.getInfo(projectInfo));
    // collects IDs of type cells
    Set<String> typeIds = new HashSet<String>();
    // type cells
    for (Cell typeCell : alignment.getTypeCells()) {
        if (typeCell.getTransformationMode() != TransformationMode.disabled) {
            // ignore disabled cells
            Entity targetEntity = CellUtil.getFirstEntity(typeCell.getTarget());
            if (targetEntity != null) {
                // assign identifiers for type transformations
                String targetName = targetEntity.getDefinition().getDefinition().getName().getLocalPart();
                String id = cellIdentifiers.getId(typeCell, targetName);
                typeIds.add(id);
            } else {
                reporter.warn(new IOMessageImpl("Ignoring type relation without target type", null));
            }
        }
    }
    // collects IDs of type cells mapped to target element names
    Map<String, QName> targetElements = new HashMap<String, QName>();
    // container
    File container = new File(workDir, "container.xsl");
    progress.setCurrentTask("Generating container");
    generateContainer(typeIds, container, targetElements);
    Set<String> passiveCellIds = new HashSet<String>(typeIds);
    progress.setCurrentTask("Generate type transformations");
    // all active cells templates
    for (Entry<String, QName> entry : targetElements.entrySet()) {
        // generate XSL fragments for type transformations
        String id = entry.getKey();
        QName elementName = entry.getValue();
        Cell typeCell = cellIdentifiers.getObject(id);
        // this is not a passive cell
        passiveCellIds.remove(id);
        XmlElement targetElement = targetSchema.getElements().get(elementName);
        String filename = "_" + id + ".xsl";
        File file = new File(workDir, filename);
        includes.add(filename);
        generateTypeTransformation(id, targetElement, typeCell, file);
    }
    // all passive cell templates
    for (String passiveId : passiveCellIds) {
        Cell typeCell = cellIdentifiers.getObject(passiveId);
        String filename = "_" + passiveId + ".xsl";
        File file = new File(workDir, filename);
        includes.add(filename);
        // XXX dummy target element
        XmlElement targetElement = new XmlElement(new QName(NS_XSL_DEFINITIONS, "dummy"), null, null);
        generateTypeTransformation(passiveId, targetElement, typeCell, file);
        // for passive cells no variables should be created
        typeIds.remove(passiveId);
    }
    // namespaces that occur additionally to the fixed namespaces
    Map<String, String> additionalNamespaces = new HashMap<String, String>(prefixes.asMap());
    for (String fixedPrefix : FIXED_PREFIXES.keySet()) {
        additionalNamespaces.remove(fixedPrefix);
    }
    context.put("additionalNamespaces", additionalNamespaces);
    // types cells
    /*
		 * The type identifiers are used as variable name to store the result of
		 * the equally named template.
		 */
    context.put("targets", typeIds);
    // includes
    // TODO check if files to include are actually there?
    context.put("includes", includes);
    OutputStream out = target.getOutput();
    XMLPrettyPrinter printer = new XMLPrettyPrinter(out);
    Future<?> ready = printer.start();
    Writer writer = new OutputStreamWriter(printer, "UTF-8");
    try {
        root.merge(context, writer);
        writer.flush();
    } finally {
        writer.close();
        ready.get();
        out.close();
    }
    reporter.setSuccess(reporter.getErrors().isEmpty());
    return reporter;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) QName(javax.xml.namespace.QName) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Template(org.apache.velocity.Template) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) OutputStreamWriter(java.io.OutputStreamWriter) Cell(eu.esdihumboldt.hale.common.align.model.Cell) File(java.io.File) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

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