use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode 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.rif.filter.nonterminal.FilterNode in project hale by halestudio.
the class CqlToMappingConditionTranslator method createNode.
private FilterNode createNode(FilterNode parent, Filter child) {
FilterNode childNode = null;
if (isLogical(child)) {
LogicFilterImpl logicFilter = (LogicFilterImpl) child;
childNode = factory.createLogicNode(logicFilter);
List<?> children = logicFilter.getChildren();
for (Object c : children) {
createNode(childNode, (Filter) c);
}
} else if (isComparison(child)) {
AbstractComparisonNode comparisonNode = null;
if (LikeFilterImpl.class.isAssignableFrom(child.getClass())) {
LikeFilterImpl like = (LikeFilterImpl) child;
comparisonNode = factory.createComparisonNode(like);
comparisonNode.setLeft(getLeftContents((AttributeExpressionImpl) like.getExpression()));
LeafNode node = new LeafNode();
node.setLiteralValue(LiteralValue.getNew(like.getLiteral()));
comparisonNode.setRight(node);
} else {
CompareFilterImpl compare = (CompareFilterImpl) child;
comparisonNode = factory.createComparisonNode(compare);
comparisonNode.setLeft(getLeftContents((AttributeExpressionImpl) compare.getExpression1()));
comparisonNode.setRight(getRightContents(compare.getExpression2()));
}
childNode = comparisonNode;
} else if (isGeometric(child)) {
childNode = factory.createGeometricNode((GeometryFilterImpl) child);
}
if (parent != null) {
parent.addChild(childNode);
}
return childNode;
}
use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode 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"));
}
use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateSimpleLogical.
/**
* Test that takes a simple logical expression comprising a parent logical
* filter and for each child filter, an equality test.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testTranslateSimpleLogical() throws CQLException, TranslationException {
// $NON-NLS-1$
String cqlPredicate = "ATTR1 < 10 AND ATTR2 < 2";
ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
assertNotNull(result);
assertNotNull(result.getRoot());
assertThat(result.getRoot(), is(instanceOf(AndNode.class)));
assertNotNull(result.getRoot().getChildren());
assertThat(result.getRoot().getChildren().size(), is(equalTo(2)));
FilterNode firstNode = result.getRoot().getChildren().get(0);
assertThat(firstNode, is(instanceOf(LessThanNode.class)));
LessThanNode less1 = (LessThanNode) firstNode;
assertNotNull(less1.getLeft());
assertNotNull(less1.getLeft().getPropertyName());
// $NON-NLS-1$
assertThat(less1.getLeft().getPropertyName(), is(equalTo("ATTR1")));
assertNotNull(less1.getRight());
assertNotNull(less1.getRight().getLiteralValue());
// $NON-NLS-1$
assertThat(less1.getRight().getLiteralValue().toString(), is(equalTo("10")));
FilterNode secondNode = result.getRoot().getChildren().get(1);
assertThat(secondNode, is(instanceOf(LessThanNode.class)));
LessThanNode less2 = (LessThanNode) secondNode;
assertNotNull(less2.getLeft());
assertNotNull(less2.getLeft().getPropertyName());
// $NON-NLS-1$
assertThat(less2.getLeft().getPropertyName(), is(equalTo("ATTR2")));
assertNotNull(less2.getRight());
assertNotNull(less2.getRight().getLiteralValue());
// $NON-NLS-1$
assertThat(less2.getRight().getLiteralValue().toString(), is(equalTo("2")));
}
use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode in project hale by halestudio.
the class CqlToMappingConditionTranslator method translate.
/**
* {@inheritDoc}
*/
@Override
public ModelMappingCondition translate(Filter source) throws TranslationException {
ModelMappingCondition filter = new ModelMappingCondition();
FilterNode root = null;
if (isLogical(source)) {
LogicFilterImpl logicFilter = (LogicFilterImpl) source;
root = factory.createLogicNode(logicFilter);
List<?> children = logicFilter.getChildren();
for (Object child : children) {
createNode(root, (Filter) child);
}
} else // if it's a comparison filter we assume we are at the start of the tree
if (isComparison(source)) {
CompareFilterImpl compare = (CompareFilterImpl) source;
AbstractComparisonNode cn = factory.createComparisonNode(compare);
cn.setLeft(getLeftContents((AttributeExpressionImpl) compare.getExpression1()));
cn.setRight(getRightContents(compare.getExpression2()));
root = cn;
} else // likewise if it's a geometric filter
if (isGeometric(source)) {
GeometryFilterImpl geometric = (GeometryFilterImpl) source;
AbstractGeometricNode gn = factory.createGeometricNode(geometric);
gn.setLeft(getLeftContents((AttributeExpressionImpl) geometric.getExpression1()));
gn.setRight(getRightContents(geometric.getExpression2()));
setGeometricOperationSpecifics(gn, geometric);
root = gn;
}
filter.setRoot(root);
return filter;
}
Aggregations