Search in sources :

Example 1 with TranslationException

use of com.onespatial.jrc.tns.oml_to_rif.api.TranslationException 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 TranslationException

use of com.onespatial.jrc.tns.oml_to_rif.api.TranslationException in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method createAttribute.

private ModelAttributeMappingCell createAttribute(ICell original, Property sourceEntity, Property targetEntity, Map<String, SchemaElement> sourceFeatures, Map<String, SchemaElement> targetFeatures) {
    // FIXME what about composed properties?
    if (sourceEntity instanceof ComposedProperty || targetEntity instanceof ComposedProperty) {
        // $NON-NLS-1$
        report.setFailed(original, "Composed properties not supported");
        return null;
    }
    List<FeatureClass> filter = sourceEntity.getDomainRestriction();
    if (filter != null && !filter.isEmpty()) {
        // $NON-NLS-1$
        report.setWarning(original, "Filters on attributive functions currently not supported in the RIF export");
    }
    String function = sourceEntity.getTransformation().getService().getLocation();
    if (!RenameAttributeFunction.class.getName().equals(function)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        report.setWarning(original, "Function " + function + " not recognized");
    }
    IDetailedAbout sourceAbout = DetailedAbout.getDetailedAbout(sourceEntity.getAbout(), true);
    IDetailedAbout targetAbout = DetailedAbout.getDetailedAbout(targetEntity.getAbout(), true);
    try {
        return new ModelAttributeMappingCell(createAttributePath(sourceAbout, sourceFeatures), createAttributePath(targetAbout, targetFeatures));
    } catch (TranslationException e) {
        report.setFailed(original, e.getMessage());
        return null;
    }
}
Also used : ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) ComposedProperty(eu.esdihumboldt.commons.goml.omwg.ComposedProperty) IDetailedAbout(eu.esdihumboldt.commons.goml.rdf.IDetailedAbout) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) FeatureClass(eu.esdihumboldt.commons.goml.omwg.FeatureClass)

Example 3 with TranslationException

use of com.onespatial.jrc.tns.oml_to_rif.api.TranslationException in project hale by halestudio.

the class UrlToAlignmentDigester method translate.

/**
 * Translates an {@link URL} into a HALE {@link Alignment}.
 *
 * @param source
 *            {@link URL} the source URL
 * @return {@link Alignment}
 * @throws TranslationException
 *             if anything goes wrong during the translation
 */
@Override
public HaleAlignment translate(URL source) throws TranslationException {
    if (source == null) {
        // $NON-NLS-1$
        throw new TranslationException("url is null");
    }
    Alignment al = new OmlRdfReader().read(source);
    ApacheSchemaProvider sp = new ApacheSchemaProvider();
    Schema s, t;
    try {
        URI suri = new URI(al.getSchema1().getLocation());
        // if (!suri.isAbsolute()) {
        // suri = source.toURI();
        // suri = new URI(suri.getScheme(), suri.getUserInfo(),
        // suri.getHost(), suri.getPort(),
        // al.getSchema1().getLocation(), null, null);
        // }
        s = sp.loadSchema(suri, null);
        t = sp.loadSchema(new URI(al.getSchema2().getLocation()), null);
    } catch (Exception e) {
        // $NON-NLS-1$
        throw new TranslationException("Error loading schemas", e);
    }
    return new HaleAlignment(al, s.getElements().values(), t.getElements().values());
}
Also used : HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) Alignment(eu.esdihumboldt.commons.goml.align.Alignment) HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) Schema(eu.esdihumboldt.hale.schemaprovider.Schema) ApacheSchemaProvider(eu.esdihumboldt.hale.schemaprovider.provider.ApacheSchemaProvider) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) OmlRdfReader(eu.esdihumboldt.commons.goml.oml.io.OmlRdfReader) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)

Example 4 with TranslationException

use of com.onespatial.jrc.tns.oml_to_rif.api.TranslationException in project hale by halestudio.

the class ModelClassMappingCell method buildMappingConditions.

private List<ModelMappingCondition> buildMappingConditions(List<Restriction> mappingRestrictions) throws TranslationException {
    List<ModelMappingCondition> result;
    try {
        result = new ArrayList<ModelMappingCondition>();
        for (Restriction restriction : mappingRestrictions) {
            ModelMappingCondition condition = DIGESTER.translate(CQL.toFilter(restriction.getCqlStr()));
            result.add(condition);
        }
    } catch (CQLException e) {
        throw new TranslationException(e);
    }
    return result;
}
Also used : Restriction(eu.esdihumboldt.commons.goml.omwg.Restriction) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 5 with TranslationException

use of com.onespatial.jrc.tns.oml_to_rif.api.TranslationException in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method createStaticAssignment.

private ModelStaticAssignmentCell createStaticAssignment(ICell original, Property targetEntity, Map<String, SchemaElement> targetFeatures) {
    String function = targetEntity.getTransformation().getService().getLocation();
    if (ConstantValueFunction.class.getName().equals(function)) {
        // constant value
        String content = null;
        for (IParameter param : targetEntity.getTransformation().getParameters()) {
            if (param.getName().equals(ConstantValueFunction.DEFAULT_VALUE_PARAMETER_NAME)) {
                content = param.getValue();
                break;
            }
        }
        IDetailedAbout targetAbout = DetailedAbout.getDetailedAbout(targetEntity.getAbout(), true);
        try {
            return new ModelStaticAssignmentCell(createAttributePath(targetAbout, targetFeatures), content);
        } catch (TranslationException e) {
            report.setFailed(original, e.getMessage());
            return null;
        }
    } else if (NilReasonFunction.class.getName().equals(function)) {
        // nil reason
        String reason = null;
        for (IParameter param : targetEntity.getTransformation().getParameters()) {
            if (param.getName().equals(NilReasonFunction.PARAMETER_NIL_REASON_TYPE)) {
                reason = param.getValue();
                break;
            }
        }
        // $NON-NLS-1$
        report.setWarning(original, "The nil reason will be set regardless of whether a value for its parent is set or not");
        IDetailedAbout targetAbout = DetailedAbout.getDetailedAbout(targetEntity.getAbout(), true);
        List<String> properties = new ArrayList<String>(targetAbout.getProperties());
        // XXX this is an attribute does it make any difference? //$NON-NLS-1$
        properties.add("nilReason");
        targetAbout = new DetailedAbout(targetAbout.getNamespace(), targetAbout.getFeatureClass(), properties);
        try {
            return new ModelStaticAssignmentCell(createAttributePath(targetAbout, targetFeatures), reason);
        } catch (TranslationException e) {
            report.setFailed(original, e.getMessage());
            return null;
        }
    } else {
        // not supported
        // $NON-NLS-1$
        report.setFailed(original, "Only default value augmentations supported");
        return null;
    }
}
Also used : IParameter(eu.esdihumboldt.specification.cst.align.ext.IParameter) ConstantValueFunction(eu.esdihumboldt.cst.corefunctions.ConstantValueFunction) ModelStaticAssignmentCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell) IDetailedAbout(eu.esdihumboldt.commons.goml.rdf.IDetailedAbout) DetailedAbout(eu.esdihumboldt.commons.goml.rdf.DetailedAbout) IDetailedAbout(eu.esdihumboldt.commons.goml.rdf.IDetailedAbout) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TranslationException (com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)8 HaleAlignment (com.onespatial.jrc.tns.oml_to_rif.HaleAlignment)3 ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)2 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)2 Alignment (eu.esdihumboldt.commons.goml.align.Alignment)2 ComposedProperty (eu.esdihumboldt.commons.goml.omwg.ComposedProperty)2 FeatureClass (eu.esdihumboldt.commons.goml.omwg.FeatureClass)2 IDetailedAbout (eu.esdihumboldt.commons.goml.rdf.IDetailedAbout)2 SchemaElement (eu.esdihumboldt.hale.schemaprovider.model.SchemaElement)2 ArrayList (java.util.ArrayList)2 Document (org.w3c.dom.Document)2 ModelAlignment (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment)1 ModelClassMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell)1 GmlAttribute (com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttribute)1 GmlAttributePath (com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttributePath)1 OmlRdfReader (eu.esdihumboldt.commons.goml.oml.io.OmlRdfReader)1 Property (eu.esdihumboldt.commons.goml.omwg.Property)1 Restriction (eu.esdihumboldt.commons.goml.omwg.Restriction)1 DetailedAbout (eu.esdihumboldt.commons.goml.rdf.DetailedAbout)1 ConstantValueFunction (eu.esdihumboldt.cst.corefunctions.ConstantValueFunction)1