use of org.geotoolkit.ogc.xml.v100.BinaryLogicOpType in project ddf by codice.
the class TestWfsFilterDelegate method testLogicalAndOfSpatialTemporal.
/**
* Verifies that a temporal criteria can be AND'ed to other criteria.
*
* @throws Exception
*/
@Test
public void testLogicalAndOfSpatialTemporal() throws Exception {
String mockProperty = "myPropertyName";
String mockType = "myType";
WfsFilterDelegate delegate = mockFeatureMetacardCreateDelegate(mockProperty, mockType);
FilterType spatialFilter = delegate.dwithin(Metacard.ANY_GEO, "POINT (30 10)", Double.valueOf(1000));
FilterType temporalFilter = delegate.during(mockProperty, new DateTime().minusDays(365).toDate(), new DateTime().minusDays(10).toDate());
List<FilterType> filtersToBeAnded = new ArrayList<>(Arrays.asList(spatialFilter, temporalFilter));
//Perform Test
FilterType filter = delegate.and(filtersToBeAnded);
//Verify AND op used
if (filter.getLogicOps() == null) {
fail("No AND/OR element found in the generated FilterType.");
}
assertEquals(LOGICAL_AND_NAME, filter.getLogicOps().getName().toString());
BinaryLogicOpType logicOpType = (BinaryLogicOpType) filter.getLogicOps().getValue();
//Verify two items were AND'ed
assertEquals(2, logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().size());
//Verify first is spatial, second is temporal
assertTrue(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(0).getValue() instanceof DistanceBufferType);
assertTrue(logicOpType.getComparisonOpsOrSpatialOpsOrTemporalOps().get(1).getValue() instanceof BinaryTemporalOpType);
}
use of org.geotoolkit.ogc.xml.v100.BinaryLogicOpType in project ddf by codice.
the class TestWfsFilterDelegate 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.v100.BinaryLogicOpType in project geo-platform by geosdi.
the class NotOperatorHandler method createLogicOps.
/**
* @param elements
* @return {@link UnaryLogicOpType}
*/
protected UnaryLogicOpType createLogicOps(@Nonnull(when = NEVER) List<JAXBElement<?>> elements, @Nonnull(when = NEVER) FilterType filter) {
checkArgument(elements != null, "The Parameter elements must not be null.");
checkArgument(filter != null, "The Parameter filter must not be null.");
if (filter.isSetSpatialOps()) {
elements.add(filter.getSpatialOps());
filter.setSpatialOps(null);
}
UnaryLogicOpType unaryLogicOpType = new UnaryLogicOpType();
BinaryLogicOpType and = new BinaryLogicOpType();
and.setComparisonOpsOrSpatialOpsOrLogicOps(elements);
unaryLogicOpType.setLogicOps(filterFactory.createAnd(and));
return unaryLogicOpType;
}
use of org.geotoolkit.ogc.xml.v100.BinaryLogicOpType in project geo-platform by geosdi.
the class NotOperatorHandler method createComparisonOps.
/**
* @param element
* @return {@link UnaryLogicOpType}
*/
protected UnaryLogicOpType createComparisonOps(@Nonnull(when = NEVER) JAXBElement element, @Nonnull(when = NEVER) FilterType filter) {
checkArgument(element != null, "The Parameter element must not be null.");
checkArgument(filter != null, "The Parameter filter must not be null.");
if (filter.isSetSpatialOps()) {
List<JAXBElement<?>> elements = new ArrayList<>(2);
elements.add(filter.getSpatialOps());
filter.setSpatialOps(null);
elements.add(element);
UnaryLogicOpType unaryLogicOpType = new UnaryLogicOpType();
BinaryLogicOpType and = new BinaryLogicOpType();
and.setComparisonOpsOrSpatialOpsOrLogicOps(elements);
unaryLogicOpType.setLogicOps(filterFactory.createAnd(and));
return unaryLogicOpType;
} else {
UnaryLogicOpType unaryLogicOpType = new UnaryLogicOpType();
unaryLogicOpType.setComparisonOps(element);
return unaryLogicOpType;
}
}
use of org.geotoolkit.ogc.xml.v100.BinaryLogicOpType in project geotoolkit by Geomatys.
the class OGC100Test method testFilterLogicalOr.
@Test
public void testFilterLogicalOr() throws JAXBException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_FIL_LOG_OR);
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_OR);
BinaryLogicOpType pibt = (BinaryLogicOpType) cot;
BinaryComparisonOpType leftoptype = (BinaryComparisonOpType) pibt.getComparisonOpsOrSpatialOpsOrLogicOps().get(0).getValue();
BinaryComparisonOpType rightoptype = (BinaryComparisonOpType) pibt.getComparisonOpsOrSpatialOpsOrLogicOps().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_OR);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
Aggregations