Search in sources :

Example 1 with SchemaElement

use of eu.esdihumboldt.hale.schemaprovider.model.SchemaElement in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method translate.

/**
 * Translates a {@link HaleAlignment} into an intermediate
 * {@link ModelAlignment} format.
 *
 * @param hal the HALE alignment
 * @return {@link ModelAlignment}
 * @throws TranslationException
 *             if any problems occurred during translation
 */
@Override
public ModelAlignment translate(HaleAlignment hal) throws TranslationException {
    List<ModelClassMappingCell> classMappings = new ArrayList<ModelClassMappingCell>();
    List<ModelAttributeMappingCell> attributeMappings = new ArrayList<ModelAttributeMappingCell>();
    ArrayList<ModelStaticAssignmentCell> staticAssigments = new ArrayList<ModelStaticAssignmentCell>();
    Alignment source = hal.getAlignment();
    Map<String, SchemaElement> sourceFeatures = hal.getSourceElements();
    Map<String, SchemaElement> targetFeatures = hal.getTargetElements();
    for (ICell cell : source.getMap()) {
        IEntity sourceEntity = cell.getEntity1();
        IEntity targetEntity = cell.getEntity2();
        boolean sourceIsFeatureClass = sourceEntity instanceof FeatureClass;
        boolean targetIsFeatureClass = targetEntity instanceof FeatureClass;
        if (sourceIsFeatureClass && targetIsFeatureClass) {
            // type mapping
            classMappings.add(createCell((FeatureClass) sourceEntity, (FeatureClass) targetEntity, sourceFeatures, targetFeatures));
        } else if (!sourceIsFeatureClass && !targetIsFeatureClass) {
            // property mapping
            ModelAttributeMappingCell modelCell = createAttribute(cell, (Property) sourceEntity, (Property) targetEntity, sourceFeatures, targetFeatures);
            if (modelCell != null) {
                attributeMappings.add(modelCell);
            }
        } else if (sourceIsFeatureClass && !targetIsFeatureClass) {
            // augmentations
            ModelStaticAssignmentCell modelCell = createStaticAssignment(cell, (Property) targetEntity, targetFeatures);
            if (modelCell != null) {
                staticAssigments.add(modelCell);
            }
        } else {
            // $NON-NLS-1$
            throw new TranslationException("Unhandled combination");
        }
    }
    return new ModelAlignment(classMappings, attributeMappings, staticAssigments);
}
Also used : ModelClassMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell) IEntity(eu.esdihumboldt.specification.cst.align.IEntity) ModelStaticAssignmentCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell) ArrayList(java.util.ArrayList) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) FeatureClass(eu.esdihumboldt.commons.goml.omwg.FeatureClass) ICell(eu.esdihumboldt.specification.cst.align.ICell) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) Alignment(eu.esdihumboldt.commons.goml.align.Alignment) HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) SchemaElement(eu.esdihumboldt.hale.schemaprovider.model.SchemaElement) Property(eu.esdihumboldt.commons.goml.omwg.Property) ComposedProperty(eu.esdihumboldt.commons.goml.omwg.ComposedProperty)

Example 2 with SchemaElement

use of eu.esdihumboldt.hale.schemaprovider.model.SchemaElement in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method findFeatureElementDecl.

private SchemaElement findFeatureElementDecl(FeatureClass entity, Map<String, SchemaElement> nameToFeatureMap) {
    String featureName = entity.getAbout().getAbout();
    SchemaElement result = nameToFeatureMap.get(featureName);
    return result;
}
Also used : SchemaElement(eu.esdihumboldt.hale.schemaprovider.model.SchemaElement)

Example 3 with SchemaElement

use of eu.esdihumboldt.hale.schemaprovider.model.SchemaElement in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method createAttributePath.

/**
 * Create an attribute path from an {@link IDetailedAbout}
 *
 * @param about the about
 * @param elements the available elements
 * @return the attribute path
 * @throws TranslationException if the attribute path cannot be resolved
 */
private static GmlAttributePath createAttributePath(IDetailedAbout about, Map<String, SchemaElement> elements) throws TranslationException {
    GmlAttributePath binding = new GmlAttributePath();
    // get the parent class for the entity
    // $NON-NLS-1$
    SchemaElement entityParent = elements.get(about.getNamespace() + "/" + about.getFeatureClass());
    if (entityParent == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new TranslationException("Element " + about.getFeatureClass() + " not found");
    }
    TypeDefinition type = entityParent.getType();
    List<String> nestedParts = about.getProperties();
    for (String attributeName : nestedParts) {
        AttributeDefinition attDef = type.getAttribute(attributeName);
        if (attDef == null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new TranslationException("Attribute " + attributeName + " not found");
        }
        GmlAttribute attribute = new GmlAttribute(attDef);
        binding.add(attribute);
        type = attDef.getAttributeType();
    }
    return binding;
}
Also used : GmlAttributePath(com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttributePath) AttributeDefinition(eu.esdihumboldt.hale.schemaprovider.model.AttributeDefinition) SchemaElement(eu.esdihumboldt.hale.schemaprovider.model.SchemaElement) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) GmlAttribute(com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttribute) TypeDefinition(eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition)

Aggregations

SchemaElement (eu.esdihumboldt.hale.schemaprovider.model.SchemaElement)3 TranslationException (com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)2 HaleAlignment (com.onespatial.jrc.tns.oml_to_rif.HaleAlignment)1 ModelAlignment (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment)1 ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)1 ModelClassMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell)1 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)1 GmlAttribute (com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttribute)1 GmlAttributePath (com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttributePath)1 Alignment (eu.esdihumboldt.commons.goml.align.Alignment)1 ComposedProperty (eu.esdihumboldt.commons.goml.omwg.ComposedProperty)1 FeatureClass (eu.esdihumboldt.commons.goml.omwg.FeatureClass)1 Property (eu.esdihumboldt.commons.goml.omwg.Property)1 AttributeDefinition (eu.esdihumboldt.hale.schemaprovider.model.AttributeDefinition)1 TypeDefinition (eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition)1 ICell (eu.esdihumboldt.specification.cst.align.ICell)1 IEntity (eu.esdihumboldt.specification.cst.align.IEntity)1 ArrayList (java.util.ArrayList)1