use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment in project hale by halestudio.
the class TestAlignmentToModelAlignmentDigester method testExample3CPWithFilter.
/**
* Tests translation based on the example 3 CP data set including a simple
* predicate filter on the mapping of source classes to the target logical
* schema.
*
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testExample3CPWithFilter() throws TranslationException {
URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
"com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_cp_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(LessThanNode.class)));
LessThanNode lessNode = (LessThanNode) root;
assertNotNull(lessNode.getLeft());
// $NON-NLS-1$
assertThat(lessNode.getLeft().getPropertyName(), is(equalTo("MI_PRINX")));
// $NON-NLS-1$
assertThat(lessNode.getRight().getLiteralValue().toString(), is(equalTo("3.5")));
assertNotNull(lessNode.getRight());
// $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"));
}
use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment in project hale by halestudio.
the class TestAlignmentToModelAlignmentDigester method testExample3CP.
/**
* Tests translation based on the example 3 CP source dataset.
*
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testExample3CP() throws TranslationException {
URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
"com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_cp.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());
// $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"));
}
use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment 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);
}
use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment 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 < 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"));
}
Aggregations