Search in sources :

Example 6 with ModelAttributeMappingCell

use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell in project hale by halestudio.

the class TestAlignmentToModelAlignmentDigester method testExample3CPWithComplexLogicalFilter.

/**
 * Tests translation based on the example 3 CP data set including a slightly
 * more complex predicate filter on the mapping of source classes to the
 * target logical schema. CQL Filter on which this test particularly focuses
 * is as follows.
 * <p>
 * <code>
 * PCVL_PRCL = 'a specific string' and (MI_PRINX &lt; 3.5 or ABSTRACT like
 * '%a certain keyword%').
 * </code>
 * <p>
 *
 * @throws TranslationException
 *             if any errors occurred during the translation
 */
@Test
public void testExample3CPWithComplexLogicalFilter() throws TranslationException {
    URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
    "com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_cp_complex_logical_filter.goml");
    ModelAlignment result = translator.translate(url);
    assertNotNull(result);
    assertNotNull(result.getClassMappings());
    assertNotNull(result.getAttributeMappings());
    assertNotNull(result.getStaticAssignments());
    assertThat(result.getClassMappings().size(), is(1));
    ModelClassMappingCell modelClassMappingCell = result.getClassMappings().get(0);
    assertNotNull(modelClassMappingCell);
    assertNotNull(modelClassMappingCell.getSourceClass());
    assertNotNull(modelClassMappingCell.getTargetClass());
    assertNotNull(modelClassMappingCell.getMappingConditions());
    assertThat(modelClassMappingCell.getMappingConditions().size(), is(1));
    assertNotNull(modelClassMappingCell.getMappingConditions().get(0).getRoot());
    FilterNode root = modelClassMappingCell.getMappingConditions().get(0).getRoot();
    assertThat(root, is(instanceOf(AndNode.class)));
    // $NON-NLS-1$
    assertThat(modelClassMappingCell.getSourceClass().getElementName().getLocalPart(), is("ParcelArea"));
    // $NON-NLS-1$
    assertThat(modelClassMappingCell.getTargetClass().getElementName().getLocalPart(), is("CadastralParcel"));
    // CHECKSTYLE:OFF
    assertThat(result.getAttributeMappings().size(), is(7));
    // CHECKSTYLE:ON
    ModelAttributeMappingCell attributeMapping0 = result.getAttributeMappings().get(0);
    assertThat(attributeMapping0.getSourceAttribute().get(0).getDefinition().getName(), // $NON-NLS-1$
    is("PCVL_PRCL_"));
    assertThat(attributeMapping0.getTargetAttribute().get(0).getDefinition().getName(), // $NON-NLS-1$
    is("inspireId"));
    assertThat(result.getStaticAssignments().size(), is(1));
    ModelStaticAssignmentCell assignment0 = result.getStaticAssignments().get(0);
    // $NON-NLS-1$
    assertThat(assignment0.getTarget().get(0).getDefinition().getName(), is("inspireId"));
    // $NON-NLS-1$
    assertThat(assignment0.getContent(), is("DP.CAD.CP"));
}
Also used : ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) ModelClassMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell) ModelStaticAssignmentCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell) FilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode) ModelAlignment(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment) URL(java.net.URL) Test(org.junit.Test)

Example 7 with ModelAttributeMappingCell

use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell in project hale by halestudio.

the class ModelAlignmentToModelRifTranslator method filter.

/**
 * Filter {@link ModelAttributeMappingCell}s to leave only those that can
 * target the specified source and target classes.
 *
 * @param attributeMappings
 *            cells to filter.
 * @param sourceClass
 *            source class that mapping must apply to.
 * @param targetClass
 *            target class that mapping must apply to.
 * @return filtered list of mappings cells.
 */
private static List<ModelAttributeMappingCell> filter(List<ModelAttributeMappingCell> attributeMappings, SchemaElement sourceClass, SchemaElement targetClass) {
    List<ModelAttributeMappingCell> applicableMappings = new ArrayList<ModelAttributeMappingCell>();
    for (ModelAttributeMappingCell candidate : attributeMappings) {
        TypeDefinition sourceElement = candidate.getSourceAttribute().get(0).getDefinition().getDeclaringType();
        TypeDefinition targetElement = candidate.getTargetAttribute().get(0).getDefinition().getDeclaringType();
        if (canBeSubstitutedBy(sourceElement, sourceClass) && canBeSubstitutedBy(targetElement, targetClass)) {
            applicableMappings.add(candidate);
        }
    // also test attributes.
    }
    return applicableMappings;
}
Also used : ModelAttributeMappingCell(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell) ArrayList(java.util.ArrayList) TypeDefinition(eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition)

Aggregations

ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)7 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)5 ModelAlignment (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment)4 ModelClassMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell)4 URL (java.net.URL)3 Test (org.junit.Test)3 TranslationException (com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)2 FilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode)2 ComposedProperty (eu.esdihumboldt.commons.goml.omwg.ComposedProperty)2 FeatureClass (eu.esdihumboldt.commons.goml.omwg.FeatureClass)2 ArrayList (java.util.ArrayList)2 HaleAlignment (com.onespatial.jrc.tns.oml_to_rif.HaleAlignment)1 ModelMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)1 ModelSentence (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelSentence)1 AbstractFilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode)1 LessThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode)1 Alignment (eu.esdihumboldt.commons.goml.align.Alignment)1 Property (eu.esdihumboldt.commons.goml.omwg.Property)1 IDetailedAbout (eu.esdihumboldt.commons.goml.rdf.IDetailedAbout)1 SchemaElement (eu.esdihumboldt.hale.schemaprovider.model.SchemaElement)1