use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project geotoolkit by Geomatys.
the class OGC110Test method testFilterLogicalAnd.
// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR LOGIC FILTERS ///////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testFilterLogicalAnd() throws JAXBException, NoSuchAuthorityCodeException, FactoryException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_FIL_LOG_AND);
assertNotNull(obj);
JAXBElement<? extends FilterType> jaxfilter = (JAXBElement<? extends FilterType>) obj;
assertNotNull(jaxfilter);
Filter filter = TRANSFORMER_GT.visitFilter(jaxfilter.getValue());
assertNotNull(filter);
LogicalOperator prop = (LogicalOperator) filter;
BinaryComparisonOperator leftop = (BinaryComparisonOperator) prop.getOperands().get(0);
BinaryComparisonOperator rightop = (BinaryComparisonOperator) prop.getOperands().get(1);
ValueReference left = (ValueReference) leftop.getOperand1();
Literal right = (Literal) leftop.getOperand2();
assertEquals(left.getXPath(), valueStr);
assertEquals(((Number) right.apply(null)).floatValue(), 455f, DELTA);
left = (ValueReference) rightop.getOperand1();
right = (Literal) rightop.getOperand2();
assertEquals(left.getXPath(), valueStr);
assertEquals(((Number) right.apply(null)).floatValue(), 457f, DELTA);
// write test
FilterType ft = TRANSFORMER_OGC.apply(filter);
assertNotNull(ft.getLogicOps());
LogicOpsType cot = ft.getLogicOps().getValue();
assertEquals(ft.getLogicOps().getName().getLocalPart(), OGCJAXBStatics.FILTER_LOGIC_AND);
BinaryLogicOpType pibt = (BinaryLogicOpType) cot;
BinaryComparisonOpType leftoptype = (BinaryComparisonOpType) pibt.getComparisonOps().get(0).getValue();
BinaryComparisonOpType rightoptype = (BinaryComparisonOpType) pibt.getComparisonOps().get(1).getValue();
PropertyNameType lf = (PropertyNameType) leftoptype.getExpression().get(0).getValue();
LiteralType rg = (LiteralType) leftoptype.getExpression().get(1).getValue();
assertEquals(valueStr, lf.getContent());
numberEquals(455, rg.getContent().get(0));
lf = (PropertyNameType) rightoptype.getExpression().get(0).getValue();
rg = (LiteralType) rightoptype.getExpression().get(1).getValue();
assertEquals(valueStr, lf.getContent());
numberEquals(457, rg.getContent().get(0));
MARSHALLER.marshal(ft.getLogicOps(), TEST_FILE_FIL_LOG_AND);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project geotoolkit by Geomatys.
the class OGC110toGTTransformer method visitLogicOp.
/**
* Transform a SLD logic Filter v1.1 in GT filter.
*/
public Filter visitLogicOp(final JAXBElement<? extends org.geotoolkit.ogc.xml.v110.LogicOpsType> jax) throws NoSuchAuthorityCodeException, FactoryException {
final org.geotoolkit.ogc.xml.v110.LogicOpsType ops = jax.getValue();
final String OpName = jax.getName().getLocalPart();
if (ops instanceof org.geotoolkit.ogc.xml.v110.UnaryLogicOpType) {
final org.geotoolkit.ogc.xml.v110.UnaryLogicOpType unary = (org.geotoolkit.ogc.xml.v110.UnaryLogicOpType) ops;
if (OGCJAXBStatics.FILTER_LOGIC_NOT.equalsIgnoreCase(OpName)) {
Filter filter = null;
if (unary.getComparisonOps() != null) {
filter = visitComparisonOp(unary.getComparisonOps());
} else if (unary.getLogicOps() != null) {
filter = visitLogicOp(unary.getLogicOps());
} else if (unary.getSpatialOps() != null) {
filter = visitSpatialOp(unary.getSpatialOps());
}
if (filter == null) {
throw new IllegalArgumentException("Invalide filter element" + unary);
}
return filterFactory.not(filter);
}
} else if (ops instanceof org.geotoolkit.ogc.xml.v110.BinaryLogicOpType) {
final org.geotoolkit.ogc.xml.v110.BinaryLogicOpType binary = (org.geotoolkit.ogc.xml.v110.BinaryLogicOpType) ops;
if (OGCJAXBStatics.FILTER_LOGIC_AND.equalsIgnoreCase(OpName)) {
final List<Filter> filters = new ArrayList<Filter>();
for (final JAXBElement<? extends ComparisonOpsType> ele : binary.getComparisonOps()) {
if (ele.getValue() instanceof ComparisonOpsType) {
filters.add(visitComparisonOp(ele));
}
}
for (final JAXBElement<? extends LogicOpsType> ele : binary.getLogicOps()) {
if (ele.getValue() instanceof LogicOpsType) {
filters.add(visitLogicOp(ele));
}
}
for (final JAXBElement<? extends SpatialOpsType> ele : binary.getSpatialOps()) {
if (ele.getValue() instanceof SpatialOpsType) {
filters.add(visitSpatialOp(ele));
}
}
if (filters.isEmpty()) {
return Filter.include();
} else if (filters.size() == 1) {
return filters.get(0);
} else {
return filterFactory.and((List) filters);
}
} else if (OGCJAXBStatics.FILTER_LOGIC_OR.equalsIgnoreCase(OpName)) {
final List<Filter> filters = new ArrayList<Filter>();
for (final JAXBElement<? extends ComparisonOpsType> ele : binary.getComparisonOps()) {
if (ele.getValue() instanceof ComparisonOpsType) {
filters.add(visitComparisonOp(ele));
}
}
for (final JAXBElement<? extends LogicOpsType> ele : binary.getLogicOps()) {
if (ele.getValue() instanceof LogicOpsType) {
filters.add(visitLogicOp(ele));
}
}
for (final JAXBElement<? extends SpatialOpsType> ele : binary.getSpatialOps()) {
if (ele.getValue() instanceof SpatialOpsType) {
filters.add(visitSpatialOp(ele));
}
}
if (filters.isEmpty()) {
return Filter.include();
} else if (filters.size() == 1) {
return filters.get(0);
} else {
return filterFactory.or((List) filters);
}
}
}
throw new IllegalArgumentException("Unknowed filter element" + jax);
}
use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project ddf by codice.
the class WfsFilterDelegateTest method testLogicalAndOrSpatial.
private void testLogicalAndOrSpatial(String methName, String compOpName) throws Exception {
String mockProperty = "myPropertyName";
String mockType = "myType";
WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
FilterType spatialFilter1 = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", 1000);
FilterType spatialFilter2 = delegate.dwithin(Metacard.ANY_GEO, "POINT (50 10)", 1500);
List<FilterType> filtersToCombine = new ArrayList<>();
filtersToCombine.add(spatialFilter1);
filtersToCombine.add(spatialFilter2);
// Perform Test
Method method = WfsFilterDelegate.class.getMethod(methName, List.class);
FilterType filter = (FilterType) method.invoke(delegate, filtersToCombine);
// Verify
assertThat(filter.getLogicOps().getName().toString(), is(compOpName));
BinaryLogicOpType logicOpType = (BinaryLogicOpType) filter.getLogicOps().getValue();
DistanceBufferType spatialOpsType1 = (DistanceBufferType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue();
assertThat(spatialOpsType1.getDistance().getValue(), is(1000d));
DistanceBufferType spatialOpsType2 = (DistanceBufferType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue();
assertThat(spatialOpsType2.getDistance().getValue(), is(1500d));
}
use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project ddf by codice.
the class WfsFilterDelegateTest method testLogicalAndOrComparison.
private void testLogicalAndOrComparison(String methName, String compOpName) throws Exception {
String mockProperty = "myPropertyName";
String mockType = "myType";
WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
FilterType compFilter1 = delegate.propertyIsLike(Metacard.ANY_TEXT, LITERAL, true);
FilterType compFilter2 = delegate.propertyIsLike(Metacard.ANY_TEXT, LITERAL, true);
List<FilterType> filtersToCombine = new ArrayList<>();
filtersToCombine.add(compFilter1);
filtersToCombine.add(compFilter2);
// Perform Test
Method method = WfsFilterDelegate.class.getMethod(methName, List.class);
FilterType filter = (FilterType) method.invoke(delegate, filtersToCombine);
// Verify
assertThat(filter.getLogicOps().getName().toString(), is(compOpName));
BinaryLogicOpType logicOpType = (BinaryLogicOpType) filter.getLogicOps().getValue();
Assert.assertThat(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().size(), is(2));
for (JAXBElement<?> jaxbElement : logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps()) {
PropertyIsLikeType compOpsType = (PropertyIsLikeType) jaxbElement.getValue();
String valRef = fetchPropertyIsLikeExpression(compOpsType, VALUE_REFERENCE);
assertThat(valRef, is(mockProperty));
String literal = fetchPropertyIsLikeExpression(compOpsType, LITERAL);
assertThat(literal, is(LITERAL));
}
}
use of org.geotoolkit.ogc.xml.v110.BinaryLogicOpType in project ddf by codice.
the class TestWfsFilterDelegate method testLogicalAndOrSpatial.
private void testLogicalAndOrSpatial(String methName, String compOpName) throws Exception {
String mockProperty = "myPropertyName";
String mockType = "myType";
WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
FilterType spatialFilter1 = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", Double.valueOf(1000));
FilterType spatialFilter2 = delegate.dwithin(Metacard.ANY_GEO, "POINT (50 10)", Double.valueOf(1500));
List<FilterType> filtersToCombine = new ArrayList<>();
filtersToCombine.add(spatialFilter1);
filtersToCombine.add(spatialFilter2);
//Perform Test
Method method = WfsFilterDelegate.class.getMethod(methName, List.class);
FilterType filter = (FilterType) method.invoke(delegate, filtersToCombine);
//Verify
assertThat(filter.getLogicOps().getName().toString(), is(compOpName));
BinaryLogicOpType logicOpType = (BinaryLogicOpType) filter.getLogicOps().getValue();
DistanceBufferType spatialOpsType1 = (DistanceBufferType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue();
assertThat(Double.toString(spatialOpsType1.getDistance().getValue()), is(Double.valueOf(1000).toString()));
DistanceBufferType spatialOpsType2 = (DistanceBufferType) logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue();
assertThat(Double.toString(spatialOpsType2.getDistance().getValue()), is(Double.valueOf(1500).toString()));
}
Aggregations